List of usage examples for android.database.sqlite SQLiteDatabase beginTransaction
public void beginTransaction()
From source file:de.stadtrallye.rallyesoft.model.map.MapManager.java
private void updateDatabase(List<Node> nodes, List<Edge> edges) { SQLiteDatabase db = getDb(); db.beginTransaction(); try {// w w w.j a v a 2 s .co m db.delete(Edges.TABLE, null, null); db.delete(Nodes.TABLE, null, null); SQLiteStatement nodeIn = db.compileStatement("INSERT INTO " + Nodes.TABLE + " (" + DatabaseHelper.strStr(Nodes.COLS) + ") VALUES (?, ?, ?, ?, ?)"); SQLiteStatement edgeIn = db.compileStatement( "INSERT INTO " + Edges.TABLE + " (" + DatabaseHelper.strStr(Edges.COLS) + ") VALUES (?, ?, ?)"); for (Node n : nodes) { nodeIn.bindLong(1, n.nodeID); nodeIn.bindString(2, n.name); nodeIn.bindDouble(3, n.location.latitude); nodeIn.bindDouble(4, n.location.longitude); nodeIn.bindString(5, n.description); nodeIn.executeInsert(); } for (Edge m : edges) { edgeIn.bindLong(1, m.nodeA.nodeID); edgeIn.bindLong(2, m.nodeB.nodeID); edgeIn.bindString(3, m.type.toString()); edgeIn.executeInsert(); } db.setTransactionSuccessful(); } catch (Exception e) { Log.e(THIS, "Map Update on Database failed", e); } finally { db.endTransaction(); } }
From source file:com.appsimobile.appsii.module.apps.AppsProvider.java
@Override public int bulkInsert(Uri uri, @NonNull ContentValues[] values) { SqlArguments args = new SqlArguments(uri); SQLiteDatabase db = mOpenHelper.getWritableDatabase(); db.beginTransaction(); try {/*ww w . jav a 2 s .c o m*/ int numValues = values.length; for (int i = 0; i < numValues; i++) { if (db.insert(args.table, null, values[i]) < 0) return 0; } db.setTransactionSuccessful(); } finally { db.endTransaction(); } sendNotify(uri); return values.length; }
From source file:com.futureplatforms.kirin.extensions.databases.DatabasesBackend.java
protected void beginNativeTransaction(SQLiteDatabase db) { db.beginTransaction(); }
From source file:mobisocial.musubi.ui.AcceptFriendActivity.java
@Override protected void onResume() { super.onResume(); if (getIntent() == null || getIntent().getData() == null) { Toast.makeText(this, "No data.", Toast.LENGTH_SHORT).show(); finish();/*from w ww .j a v a 2 s. c o m*/ return; } mUri = getIntent().getData(); mName = mUri.getQueryParameter("n"); if (mName == null) { mName = "Unnamed Friend"; } mTypes = mUri.getQueryParameters("t"); mPrincipals = mUri.getQueryParameters("p"); if (mTypes.size() != mPrincipals.size()) { Toast.makeText(this, "Mismatched identity information", Toast.LENGTH_SHORT).show(); finish(); return; } if (mTypes.size() == 0) { Toast.makeText(this, "Missing identity information", Toast.LENGTH_SHORT).show(); finish(); return; } Iterator<String> i_types = mTypes.iterator(); Iterator<String> i_princiapls = mPrincipals.iterator(); TLongArrayList ids = new TLongArrayList(4); SQLiteDatabase db = mDatabaseSource.getWritableDatabase(); int num_facebook_ids = 0; String description = ""; try { db.beginTransaction(); while (i_types.hasNext()) { int type; try { type = Integer.parseInt(i_types.next()); } catch (NumberFormatException e) { continue; } String principal = i_princiapls.next(); Authority authority = IBHashedIdentity.Authority.values()[type]; if (authority == Authority.Local) { continue; } IBIdentity id = new IBIdentity(authority, principal, 0); long identId = mIdentitiesManager.getIdForIBHashedIdentity(id); MIdentity ident; if (identId == 0) { ident = new MIdentity(); ident.type_ = authority; ident.principal_ = principal; ident.principalHash_ = Util.sha256(ident.principal_.getBytes()); ident.principalShortHash_ = Util.shortHash(ident.principalHash_); ident.claimed_ = true; ident.musubiName_ = mName; identId = mIdentitiesManager.insertIdentity(ident); } else { ident = mIdentitiesManager.getIdentityForId(identId); ident.principal_ = principal; // implicitly checked by lookup ident.claimed_ = true; ident.musubiName_ = mName; mIdentitiesManager.updateIdentity(ident); } ids.add(identId); if (ident.type_ == Authority.Facebook) { num_facebook_ids++; } else { description += "\n" + ident.principal_; } } if (num_facebook_ids > 0) { description += "\n" + num_facebook_ids + " Facebook IDs"; } db.setTransactionSuccessful(); } catch (Exception e) { } finally { db.endTransaction(); } showDialog(AcceptFriendDialog.newInstance(mName, description, ids.toArray())); }
From source file:com.dm.wallpaper.board.databases.Database.java
public void addCategories(List<WallpaperJson> categories) { String query = "INSERT INTO " + TABLE_CATEGORIES + " (" + KEY_NAME + "," + KEY_THUMB_URL + ") VALUES (?,?);"; SQLiteDatabase db = this.getWritableDatabase(); SQLiteStatement statement = db.compileStatement(query); db.beginTransaction(); for (int i = 0; i < categories.size(); i++) { statement.clearBindings();/* w ww .java2 s. c o m*/ statement.bindString(1, categories.get(i).name); statement.bindString(2, categories.get(i).thumbUrl == null ? "" : categories.get(i).thumbUrl); statement.execute(); } db.setTransactionSuccessful(); db.endTransaction(); db.close(); }
From source file:com.dm.wallpaper.board.databases.Database.java
public void addWallpapers(@NonNull List<Wallpaper> wallpapers) { String query = "INSERT INTO " + TABLE_WALLPAPERS + " (" + KEY_NAME + "," + KEY_AUTHOR + "," + KEY_URL + "," + KEY_THUMB_URL + "," + KEY_CATEGORY + "," + KEY_ADDED_ON + ") VALUES (?,?,?,?,?,?);"; SQLiteDatabase db = this.getWritableDatabase(); SQLiteStatement statement = db.compileStatement(query); db.beginTransaction(); for (int i = 0; i < wallpapers.size(); i++) { statement.clearBindings();// w ww. j ava2s. co m statement.bindString(1, wallpapers.get(i).getName()); statement.bindString(2, wallpapers.get(i).getAuthor()); statement.bindString(3, wallpapers.get(i).getUrl()); statement.bindString(4, wallpapers.get(i).getThumbUrl()); statement.bindString(5, wallpapers.get(i).getCategory()); statement.bindString(6, TimeHelper.getLongDateTime()); statement.execute(); } db.setTransactionSuccessful(); db.endTransaction(); db.close(); }
From source file:com.dm.wallpaper.board.databases.Database.java
public void addWallpapers(@NonNull WallpaperJson wallpaper) { String query = "INSERT INTO " + TABLE_WALLPAPERS + " (" + KEY_NAME + "," + KEY_AUTHOR + "," + KEY_URL + "," + KEY_THUMB_URL + "," + KEY_CATEGORY + "," + KEY_ADDED_ON + ") VALUES (?,?,?,?,?,?);"; SQLiteDatabase db = this.getWritableDatabase(); SQLiteStatement statement = db.compileStatement(query); db.beginTransaction(); for (int i = 0; i < wallpaper.getWallpapers.size(); i++) { statement.clearBindings();/*from w w w . jav a 2 s. c o m*/ statement.bindString(1, wallpaper.getWallpapers.get(i).name); statement.bindString(2, wallpaper.getWallpapers.get(i).author); statement.bindString(3, wallpaper.getWallpapers.get(i).url); statement.bindString(4, wallpaper.getWallpapers.get(i).thumbUrl == null ? wallpaper.getWallpapers.get(i).url : wallpaper.getWallpapers.get(i).thumbUrl); statement.bindString(5, wallpaper.getWallpapers.get(i).category); statement.bindString(6, TimeHelper.getLongDateTime()); statement.execute(); } db.setTransactionSuccessful(); db.endTransaction(); db.close(); }
From source file:com.flowzr.activity.MainActivity.java
private void initialLoad() { long t3, t2, t1, t0 = System.currentTimeMillis(); DatabaseAdapter db = new DatabaseAdapter(this); db.open();// w ww . j a v a2 s .c o m try { SQLiteDatabase x = db.db(); x.beginTransaction(); t1 = System.currentTimeMillis(); try { updateFieldInTable(x, DatabaseHelper.CATEGORY_TABLE, 0, "title", getString(R.string.no_category)); updateFieldInTable(x, DatabaseHelper.CATEGORY_TABLE, -1, "title", getString(R.string.split)); updateFieldInTable(x, DatabaseHelper.PROJECT_TABLE, 0, "title", getString(R.string.no_project)); updateFieldInTable(x, DatabaseHelper.LOCATIONS_TABLE, 0, "name", getString(R.string.current_location)); x.setTransactionSuccessful(); } finally { x.endTransaction(); } t2 = System.currentTimeMillis(); if (MyPreferences.shouldUpdateHomeCurrency(this)) { db.setDefaultHomeCurrency(); } CurrencyCache.initialize(db.em()); t3 = System.currentTimeMillis(); if (MyPreferences.shouldRebuildRunningBalance(this)) { db.rebuildRunningBalances(); } if (MyPreferences.shouldUpdateAccountsLastTransactionDate(this)) { db.updateAccountsLastTransactionDate(); } } finally { db.close(); } long t4 = System.currentTimeMillis(); Log.d("Financisto", "Load time = " + (t4 - t0) + "ms = " + (t2 - t1) + "ms+" + (t3 - t2) + "ms+" + (t4 - t3) + "ms"); }
From source file:mobisocial.musubi.ui.fragments.AccountLinkDialog.java
/** * Adds an account to the local database. Must not be called on the main thread. *///from w ww. j a v a 2 s .c o m public static MMyAccount addAccountToDatabase(Activity activity, AccountDetails accountDetails) { SQLiteOpenHelper databaseSource = App.getDatabaseSource(activity); IdentitiesManager im = new IdentitiesManager(databaseSource); MyAccountManager am = new MyAccountManager(databaseSource); DeviceManager dm = new DeviceManager(databaseSource); FeedManager fm = new FeedManager(databaseSource); String accountType = accountDetails.accountType; String accountName = accountDetails.accountName; String principal = accountDetails.principal; boolean owned = accountDetails.owned; IBIdentity ibid; if (accountType.equals(ACCOUNT_TYPE_GOOGLE)) { ibid = new IBIdentity(Authority.Email, principal, 0); } else if (accountType.equals(ACCOUNT_TYPE_FACEBOOK)) { ibid = new IBIdentity(Authority.Facebook, principal, 0); } else if (accountType.equals(ACCOUNT_TYPE_PHONE)) { ibid = new IBIdentity(Authority.PhoneNumber, principal, 0); } else { throw new RuntimeException("Unsupported account type " + accountType); } SQLiteDatabase db = databaseSource.getWritableDatabase(); db.beginTransaction(); try { // Ensure identity in the database MIdentity id = im.getIdentityForIBHashedIdentity(ibid); //don't repeatedly add profile broadcast groups or do any //of this processing if the account is already owned. if (id != null && id.owned_) { return null; } MIdentity original = im.getOwnedIdentities().get(0); //if this identity wasnt already in the contact book, we need to update it if (id == null) { id = new MIdentity(); populateMyNewIdentity(activity, principal, im, ibid, id, original, owned); im.insertIdentity(id); } else { populateMyNewIdentity(activity, principal, im, ibid, id, original, owned); im.updateIdentity(id); } im.updateMyProfileName(activity, id.musubiName_, false); im.updateMyProfileThumbnail(activity, id.musubiThumbnail_, false); // Ensure account entry exists MMyAccount account = am.lookupAccount(accountName, accountType); if (account == null) { //create the account account = new MMyAccount(); account.accountName_ = accountName; account.accountType_ = accountType; account.identityId_ = id.id_; am.insertAccount(account); } else { account.identityId_ = id.id_; am.updateAccount(account); } // For accounts linked to identities that are not yet owned, // skip further initialization if (owned) { MDevice dev = dm.getDeviceForName(id.id_, dm.getLocalDeviceName()); // Ensure device exists if (dev == null) { dev = new MDevice(); dev.deviceName_ = dm.getLocalDeviceName(); dev.identityId_ = id.id_; dm.insertDevice(dev); } //this feed will contain all members who should receive //a profile for the account because of a friend introduction MFeed provisional = new MFeed(); provisional.name_ = MFeed.PROVISONAL_WHITELIST_FEED_NAME; provisional.type_ = MFeed.FeedType.ASYMMETRIC; fm.insertFeed(provisional); //XXX //TODO: in other places in the code, we should be pruning the //provisional whitelist feed as people become whitelisted.. //these get inserted for owned identities to allow profile //broadcasts to go out MMyAccount provAccount = new MMyAccount(); provAccount.accountName_ = MMyAccount.PROVISIONAL_WHITELIST_ACCOUNT; provAccount.accountType_ = MMyAccount.INTERNAL_ACCOUNT_TYPE; provAccount.identityId_ = id.id_; provAccount.feedId_ = provisional.id_; am.insertAccount(provAccount); //this feed will contain all members who should receive //a profile for the account because they are whitelisted //and contacted you on one of your accounts. MFeed accountBroadcastFeed = new MFeed(); accountBroadcastFeed.name_ = MFeed.LOCAL_WHITELIST_FEED_NAME; accountBroadcastFeed.type_ = MFeed.FeedType.ASYMMETRIC; fm.insertFeed(accountBroadcastFeed); MMyAccount localAccount = new MMyAccount(); localAccount.accountName_ = MMyAccount.LOCAL_WHITELIST_ACCOUNT; localAccount.accountType_ = MMyAccount.INTERNAL_ACCOUNT_TYPE; localAccount.identityId_ = id.id_; localAccount.feedId_ = accountBroadcastFeed.id_; am.insertAccount(localAccount); db.setTransactionSuccessful(); ContentResolver resolver = activity.getContentResolver(); // Notify interested services (identity available makes AMQP wake up for example) resolver.notifyChange(MusubiService.OWNED_IDENTITY_AVAILABLE, null); resolver.notifyChange(MusubiService.MY_PROFILE_UPDATED, null); // Makes key update wake up resolver.notifyChange(MusubiService.AUTH_TOKEN_REFRESH, null); WizardStepHandler.accomplishTask(activity, WizardStepHandler.TASK_LINK_ACCOUNT); App.getUsageMetrics(activity).report(MusubiMetrics.ACCOUNT_CONNECTED, account.accountType_); } else { db.setTransactionSuccessful(); } return account; } finally { db.endTransaction(); } }
From source file:mobisocial.bento.anyshare.util.DBHelper.java
@Override public void onCreate(SQLiteDatabase db) { db.beginTransaction(); createTable(db, ItemObject.TABLE, null, ItemObject._ID, "INTEGER PRIMARY KEY", ItemObject.FEEDNAME, "TEXT", ItemObject.TITLE, "TEXT", ItemObject.DESC, "TEXT", ItemObject.TIMESTAMP, "INTEGER", ItemObject.RAW, "BLOB", ItemObject.OBJHASH, "INTEGER", ItemObject.PARENT_ID, "INTEGER"); createIndex(db, "INDEX", "objects_by_hash", ItemObject.TABLE, ItemObject.OBJHASH); createIndex(db, "INDEX", "objects_timestamp", ItemObject.TABLE, ItemObject.TIMESTAMP); db.execSQL("CREATE INDEX objects_by_parent_id ON " + ItemObject.TABLE + "(" + ItemObject.PARENT_ID + ", " + ItemObject.TIMESTAMP + ")"); db.setVersion(VERSION);/*from w w w .ja va2 s.c om*/ db.setTransactionSuccessful(); db.endTransaction(); this.onOpen(db); //} }