List of usage examples for android.database.sqlite SQLiteDatabase setTransactionSuccessful
public void setTransactionSuccessful()
From source file:com.hemou.android.core.sync.persistence.DatabaseCache.java
private <E> List<E> requestAndStore(final SQLiteOpenHelper helper, final PersistableResource<E> persistableResource) throws IOException { List<E> items = null;/*from w w w . java 2 s.c o m*/ try { items = persistableResource.request(); } catch (ExpiredAuthorizationException e) { return new ArrayList<E>(); } final SQLiteDatabase db = getWritable(helper); if (db == null) return items; db.beginTransaction(); try { persistableResource.store(db, items); db.setTransactionSuccessful(); } finally { db.endTransaction(); } return items; }
From source file:com.futureplatforms.kirin.extensions.databases.DatabasesBackend.java
protected void setNativeTransactionSuccessful(SQLiteDatabase db) { db.setTransactionSuccessful(); }
From source file:ru.ming13.gambit.database.DatabaseOperator.java
private void insertDatabaseContents(SQLiteDatabase database, File databaseFile) { database.execSQL(SqlBuilder.buildAttachingClause(databaseFile.getAbsolutePath(), DATABASE_ALIAS)); try {//from www .j a v a 2 s .c o m database.beginTransaction(); database.execSQL(SqlBuilder.buildInsertionClause(DatabaseSchema.Tables.DECKS, DATABASE_ALIAS)); database.execSQL(SqlBuilder.buildInsertionClause(DatabaseSchema.Tables.CARDS, DATABASE_ALIAS)); database.setTransactionSuccessful(); } finally { database.endTransaction(); } database.execSQL(SqlBuilder.buildDetachingClause(DATABASE_ALIAS)); }
From source file:com.jefftharris.passwdsafe.sync.GDriveLaunchActivity.java
/** Get the database info for the drive file */ private Pair<DbProvider, DbFile> getFile(String fileId) { Pair<DbProvider, DbFile> rc = null; SyncDb syncDb = SyncDb.acquire();//from w w w. java 2 s .com try { SQLiteDatabase db = syncDb.beginTransaction(); List<DbProvider> providers = SyncDb.getProviders(db); for (DbProvider provider : providers) { if (provider.itsType == ProviderType.GDRIVE) { DbFile file = SyncDb.getFileByRemoteId(provider.itsId, fileId, db); if (file != null) { rc = new Pair<>(provider, file); } break; } } db.setTransactionSuccessful(); } catch (Exception e) { Log.e(TAG, "Error opening Google Drive file: " + fileId, e); } finally { syncDb.endTransactionAndRelease(); } return rc; }
From source file:com.jefftharris.passwdsafe.sync.gdrive.GDriveProvider.java
/** * Check whether any migrations are needed */// w ww. j a v a 2 s . c o m private void checkMigration() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(itsContext); int migration = prefs.getInt(PREF_MIGRATION, 0); if (migration < MIGRATION_V3API) { // Set the account name from the db provider SyncDb syncDb = SyncDb.acquire(); try { SQLiteDatabase db = syncDb.beginTransaction(); for (DbProvider provider : SyncDb.getProviders(db)) { if (provider.itsType != ProviderType.GDRIVE) { continue; } setAcctName(provider.itsAcct); } db.setTransactionSuccessful(); } catch (SQLException e) { Log.e(TAG, "Error migrating account", e); } finally { syncDb.endTransactionAndRelease(); } prefs.edit().putInt(PREF_MIGRATION, MIGRATION_V3API).apply(); } }
From source file:net.willwebberley.gowertides.utils.WeatherDatabase.java
public Boolean insertAllData(String data) { JSONObject jsonArray = null;/*from w ww .j av a 2s . c om*/ JSONArray weatherArray = null; JSONArray surfArray = null; try { jsonArray = new JSONObject(data); weatherArray = jsonArray.getJSONArray("weather"); surfArray = jsonArray.getJSONArray("surf"); } catch (Exception e) { System.err.println("couldn't parse JSON"); return false; } SQLiteDatabase db = this.getWritableDatabase(); int err_count = 0; /* Insert weather data */ db.beginTransaction(); Boolean weatherSuccess = insertWeatherData(weatherArray.toString(), db); if (!weatherSuccess) { err_count++; System.err.println("Error storing weather"); db.endTransaction(); } else { db.setTransactionSuccessful(); db.endTransaction(); } /* Insert surf data - using transactions to help performance */ db.beginTransaction(); Boolean surfSuccess = insertSurfData(surfArray.toString(), db); if (!surfSuccess) { err_count++; System.err.println("Error storing surf"); db.endTransaction(); } else { db.setTransactionSuccessful(); db.endTransaction(); } if (err_count > 0) { db.endTransaction(); return false; } return true; }
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();/*from w w w.ja v a 2 s. c o m*/ try { 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:org.opendatakit.common.android.database.DataModelDatabaseHelper.java
public static void deleteTableAndData(SQLiteDatabase db, String formId) { try {// w w w .j av a 2 s .com IdInstanceNameStruct ids = getIds(db, formId); String whereClause = TableDefinitionsColumns.TABLE_ID + " = ?"; String[] whereArgs = { ids.tableId }; db.beginTransaction(); // Drop the table used for the formId db.execSQL("DROP TABLE IF EXISTS " + ids.tableId + ";"); // Delete the table definition for the tableId int count = db.delete(TABLE_DEFS_TABLE_NAME, whereClause, whereArgs); // Delete the column definitions for this tableId db.delete(COLUMN_DEFINITIONS_TABLE_NAME, whereClause, whereArgs); // Delete the uploads for the tableId String uploadWhereClause = InstanceColumns.DATA_TABLE_TABLE_ID + " = ?"; db.delete(UPLOADS_TABLE_NAME, uploadWhereClause, whereArgs); // Delete the values from the 4 key value stores db.delete(KEY_VALUE_STORE_DEFAULT_TABLE_NAME, whereClause, whereArgs); db.delete(KEY_VALUE_STORE_ACTIVE_TABLE_NAME, whereClause, whereArgs); db.delete(KEY_VALUE_STORE_SERVER_TABLE_NAME, whereClause, whereArgs); db.delete(KEY_VALULE_STORE_SYNC_TABLE_NAME, whereClause, whereArgs); db.setTransactionSuccessful(); } catch (Exception ex) { Log.e(t, "Exception during deletion of data for formId:" + formId + " exception: " + ex.toString()); } finally { db.endTransaction(); } }
From source file:nerd.tuxmobil.fahrplan.congress.FahrplanMisc.java
public static void addAlarm(Context context, Lecture lecture, int alarmTimesIndex) { int[] alarm_times = { 0, 5, 10, 15, 30, 45, 60 }; long when;//from w w w. j ava 2s. c o m Time time; long startTime; long startTimeInSeconds = lecture.dateUTC; if (startTimeInSeconds > 0) { when = startTimeInSeconds; startTime = startTimeInSeconds; time = new Time(); } else { time = lecture.getTime(); startTime = time.normalize(true); when = time.normalize(true); } long alarmTimeDiffInSeconds = alarm_times[alarmTimesIndex] * 60 * 1000; when -= alarmTimeDiffInSeconds; // DEBUG // when = System.currentTimeMillis() + (30 * 1000); time.set(when); MyApp.LogDebug("addAlarm", "Alarm time: " + time.format("%Y-%m-%dT%H:%M:%S%z") + ", in seconds: " + when); Intent intent = new Intent(context, AlarmReceiver.class); intent.putExtra(BundleKeys.ALARM_LECTURE_ID, lecture.lecture_id); intent.putExtra(BundleKeys.ALARM_DAY, lecture.day); intent.putExtra(BundleKeys.ALARM_TITLE, lecture.title); intent.putExtra(BundleKeys.ALARM_START_TIME, startTime); intent.setAction(AlarmReceiver.ALARM_LECTURE); intent.setData(Uri.parse("alarm://" + lecture.lecture_id)); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); PendingIntent pendingintent = PendingIntent.getBroadcast(context, Integer.parseInt(lecture.lecture_id), intent, 0); // Cancel any existing alarms for this lecture alarmManager.cancel(pendingintent); // Set new alarm alarmManager.set(AlarmManager.RTC_WAKEUP, when, pendingintent); int alarmTimeInMin = alarm_times[alarmTimesIndex]; // write to DB AlarmsDBOpenHelper alarmDB = new AlarmsDBOpenHelper(context); SQLiteDatabase db = alarmDB.getWritableDatabase(); // delete any previous alarms of this lecture try { db.beginTransaction(); db.delete(AlarmsTable.NAME, AlarmsTable.Columns.EVENT_ID + "=?", new String[] { lecture.lecture_id }); ContentValues values = new ContentValues(); values.put(AlarmsTable.Columns.EVENT_ID, Integer.parseInt(lecture.lecture_id)); values.put(AlarmsTable.Columns.EVENT_TITLE, lecture.title); values.put(AlarmsTable.Columns.ALARM_TIME_IN_MIN, alarmTimeInMin); values.put(AlarmsTable.Columns.TIME, when); DateFormat df = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT); values.put(AlarmsTable.Columns.TIME_TEXT, df.format(new Date(when))); values.put(AlarmsTable.Columns.DISPLAY_TIME, startTime); values.put(AlarmsTable.Columns.DAY, lecture.day); db.insert(AlarmsTable.NAME, null, values); db.setTransactionSuccessful(); } catch (SQLException e) { } finally { db.endTransaction(); db.close(); } lecture.has_alarm = true; }
From source file:com.jefftharris.passwdsafe.NotificationMgr.java
/** Load the expiration entries */ private void loadEntries() { SQLiteDatabase db = itsDbHelper.getWritableDatabase(); try {/*from www .ja va 2s. c o m*/ db.beginTransaction(); loadEntries(db); db.setTransactionSuccessful(); } catch (SQLException e) { Log.e(TAG, "Database error", e); } finally { db.endTransaction(); } }