use of android.database.sqlite.SQLiteDatabase in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method shouldPassArgsToInsertWithOnConflict.
@Test
public void shouldPassArgsToInsertWithOnConflict() {
SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
SQLiteDatabase sqLiteDatabase = mock(SQLiteDatabase.class);
when(sqLiteOpenHelper.getWritableDatabase()).thenReturn(sqLiteDatabase);
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
InsertQuery insertQuery = InsertQuery.builder().table("test_table").nullColumnHack("custom_null_hack").build();
ContentValues contentValues = mock(ContentValues.class);
int conflictAlgorithm = SQLiteDatabase.CONFLICT_ROLLBACK;
storIOSQLite.lowLevel().insertWithOnConflict(insertQuery, contentValues, conflictAlgorithm);
verify(sqLiteDatabase).insertWithOnConflict(eq("test_table"), eq("custom_null_hack"), same(contentValues), eq(SQLiteDatabase.CONFLICT_ROLLBACK));
}
use of android.database.sqlite.SQLiteDatabase in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method nestedTransactionShouldWorkNormally.
// See https://github.com/pushtorefresh/storio/issues/478
@Test
public void nestedTransactionShouldWorkNormally() {
SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
SQLiteDatabase sqLiteDatabase = mock(SQLiteDatabase.class);
when(sqLiteOpenHelper.getWritableDatabase()).thenReturn(sqLiteDatabase);
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
// External transaction
storIOSQLite.lowLevel().beginTransaction();
try {
try {
// Nested transaction
storIOSQLite.lowLevel().beginTransaction();
storIOSQLite.lowLevel().notifyAboutChanges(Changes.newInstance("table1"));
storIOSQLite.lowLevel().notifyAboutChanges(Changes.newInstance("table2"));
// Finishing nested transaction
storIOSQLite.lowLevel().setTransactionSuccessful();
} finally {
storIOSQLite.lowLevel().endTransaction();
}
// Marking external transaction as successful
storIOSQLite.lowLevel().setTransactionSuccessful();
} finally {
// Finishing external transaction
storIOSQLite.lowLevel().endTransaction();
}
}
use of android.database.sqlite.SQLiteDatabase in project weiciyuan by qii.
the class DraftDBManager method getInstance.
public static DraftDBManager getInstance() {
if (singleton == null) {
DatabaseHelper databaseHelper = DatabaseHelper.getInstance();
SQLiteDatabase wsd = databaseHelper.getWritableDatabase();
SQLiteDatabase rsd = databaseHelper.getReadableDatabase();
singleton = new DraftDBManager();
singleton.wsd = wsd;
singleton.rsd = rsd;
}
return singleton;
}
use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.
the class RecentsProvider method insert.
@Override
public Uri insert(Uri uri, ContentValues values) {
final SQLiteDatabase db = mHelper.getWritableDatabase();
final ContentValues key = new ContentValues();
switch(sMatcher.match(uri)) {
case URI_RECENT:
values.put(RecentColumns.TIMESTAMP, System.currentTimeMillis());
db.insert(TABLE_RECENT, null, values);
final long cutoff = System.currentTimeMillis() - MAX_HISTORY_IN_MILLIS;
db.delete(TABLE_RECENT, RecentColumns.TIMESTAMP + "<" + cutoff, null);
return uri;
case URI_STATE:
final String authority = uri.getPathSegments().get(1);
final String rootId = uri.getPathSegments().get(2);
final String documentId = uri.getPathSegments().get(3);
key.put(StateColumns.AUTHORITY, authority);
key.put(StateColumns.ROOT_ID, rootId);
key.put(StateColumns.DOCUMENT_ID, documentId);
// Ensure that row exists, then update with changed values
db.insertWithOnConflict(TABLE_STATE, null, key, SQLiteDatabase.CONFLICT_IGNORE);
db.update(TABLE_STATE, values, StateColumns.AUTHORITY + "=? AND " + StateColumns.ROOT_ID + "=? AND " + StateColumns.DOCUMENT_ID + "=?", new String[] { authority, rootId, documentId });
return uri;
case URI_RESUME:
values.put(ResumeColumns.TIMESTAMP, System.currentTimeMillis());
final String packageName = uri.getPathSegments().get(1);
key.put(ResumeColumns.PACKAGE_NAME, packageName);
// Ensure that row exists, then update with changed values
db.insertWithOnConflict(TABLE_RESUME, null, key, SQLiteDatabase.CONFLICT_IGNORE);
db.update(TABLE_RESUME, values, ResumeColumns.PACKAGE_NAME + "=?", new String[] { packageName });
return uri;
default:
throw new UnsupportedOperationException("Unsupported Uri " + uri);
}
}
use of android.database.sqlite.SQLiteDatabase in project platform_frameworks_base by android.
the class Mapper method putDeviceDocument.
/**
* Puts device information to database.
*
* @return If device is added to the database.
* @throws FileNotFoundException
*/
synchronized boolean putDeviceDocument(MtpDeviceRecord device) throws FileNotFoundException {
final SQLiteDatabase database = mDatabase.getSQLiteDatabase();
database.beginTransaction();
try {
final ContentValues[] valuesList = new ContentValues[1];
final ContentValues[] extraValuesList = new ContentValues[1];
valuesList[0] = new ContentValues();
extraValuesList[0] = new ContentValues();
MtpDatabase.getDeviceDocumentValues(valuesList[0], extraValuesList[0], device);
final boolean changed = putDocuments(null, valuesList, extraValuesList, COLUMN_PARENT_DOCUMENT_ID + " IS NULL", EMPTY_ARGS, strings(COLUMN_DEVICE_ID, COLUMN_MAPPING_KEY));
database.setTransactionSuccessful();
return changed;
} finally {
database.endTransaction();
}
}
Aggregations