diff --git a/collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt b/collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt index 62400fe974c..273c89f44c1 100644 --- a/collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt +++ b/collect_app/src/main/java/org/odk/collect/android/database/entities/DatabaseEntitiesRepository.kt @@ -132,7 +132,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep } databaseConnection.withConnection { - writeableDatabase.update( + writableDatabase.update( ListsTable.TABLE_NAME, contentValues, "${ListsTable.COLUMN_NAME} = ?", @@ -184,10 +184,10 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep override fun clear() { databaseConnection.withConnection { getLists().forEach { - writeableDatabase.delete(it) + writableDatabase.delete(it) } - writeableDatabase.delete(ListsTable.TABLE_NAME) + writableDatabase.delete(ListsTable.TABLE_NAME) } } @@ -201,7 +201,7 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep override fun delete(id: String) { databaseConnection.withConnection { getLists().forEach { - writeableDatabase.delete( + writableDatabase.delete( it, "${EntitiesTable.COLUMN_ID} = ?", arrayOf(id) @@ -317,13 +317,13 @@ class DatabaseEntitiesRepository(context: Context, dbPath: String) : EntitiesRep private fun updateRowIdTables() { databaseConnection.withConnection { getLists().forEach { - writeableDatabase.execSQL( + writableDatabase.execSQL( """ DROP TABLE IF EXISTS ${getRowIdTableName(it)}; """.trimIndent() ) - writeableDatabase.execSQL( + writableDatabase.execSQL( """ CREATE TABLE ${getRowIdTableName(it)} AS SELECT _id FROM $it; """.trimIndent() diff --git a/collect_app/src/main/java/org/odk/collect/android/database/forms/DatabaseFormsRepository.java b/collect_app/src/main/java/org/odk/collect/android/database/forms/DatabaseFormsRepository.java index 3797a7f5a0e..db305178f92 100644 --- a/collect_app/src/main/java/org/odk/collect/android/database/forms/DatabaseFormsRepository.java +++ b/collect_app/src/main/java/org/odk/collect/android/database/forms/DatabaseFormsRepository.java @@ -238,13 +238,13 @@ private Cursor queryAndReturnCursor(Map projectionMap, String[] } private Long insertForm(ContentValues values) { - SQLiteDatabase writeableDatabase = databaseConnection.getWriteableDatabase(); - return writeableDatabase.insertOrThrow(FORMS_TABLE_NAME, null, values); + SQLiteDatabase writableDatabase = databaseConnection.getWritableDatabase(); + return writableDatabase.insertOrThrow(FORMS_TABLE_NAME, null, values); } private void updateForm(Long id, ContentValues values) { - SQLiteDatabase writeableDatabase = databaseConnection.getWriteableDatabase(); - writeableDatabase.update(FORMS_TABLE_NAME, values, _ID + "=?", new String[]{String.valueOf(id)}); + SQLiteDatabase writableDatabase = databaseConnection.getWritableDatabase(); + writableDatabase.update(FORMS_TABLE_NAME, values, _ID + "=?", new String[]{String.valueOf(id)}); } private void deleteForms(String selection, String[] selectionArgs) { @@ -255,8 +255,8 @@ private void deleteForms(String selection, String[] selectionArgs) { deleteFilesForForm(form); } - SQLiteDatabase writeableDatabase = databaseConnection.getWriteableDatabase(); - writeableDatabase.delete(FORMS_TABLE_NAME, selection, selectionArgs); + SQLiteDatabase writableDatabase = databaseConnection.getWritableDatabase(); + writableDatabase.delete(FORMS_TABLE_NAME, selection, selectionArgs); } @NotNull diff --git a/collect_app/src/main/java/org/odk/collect/android/database/instances/DatabaseInstancesRepository.java b/collect_app/src/main/java/org/odk/collect/android/database/instances/DatabaseInstancesRepository.java index 18f06367c03..8c9d33c3a44 100644 --- a/collect_app/src/main/java/org/odk/collect/android/database/instances/DatabaseInstancesRepository.java +++ b/collect_app/src/main/java/org/odk/collect/android/database/instances/DatabaseInstancesRepository.java @@ -144,7 +144,7 @@ public List getAllNotDeletedByFormIdAndVersion(String jrFormId, String public void delete(Long id) { Instance instance = get(id); - databaseConnection.getWriteableDatabase().delete( + databaseConnection.getWritableDatabase().delete( INSTANCES_TABLE_NAME, _ID + "=?", new String[]{String.valueOf(id)} @@ -157,7 +157,7 @@ public void delete(Long id) { public void deleteAll() { List instances = getAll(); - databaseConnection.getWriteableDatabase().delete( + databaseConnection.getWritableDatabase().delete( INSTANCES_TABLE_NAME, null, null @@ -253,7 +253,7 @@ private Cursor query(String[] projection, String selection, String[] selectionAr } private long insert(ContentValues values) { - return databaseConnection.getWriteableDatabase().insertOrThrow( + return databaseConnection.getWritableDatabase().insertOrThrow( INSTANCES_TABLE_NAME, null, values @@ -261,7 +261,7 @@ private long insert(ContentValues values) { } private void update(Long instanceId, ContentValues values) { - databaseConnection.getWriteableDatabase().update( + databaseConnection.getWritableDatabase().update( INSTANCES_TABLE_NAME, values, _ID + "=?", diff --git a/collect_app/src/main/java/org/odk/collect/android/database/savepoints/DatabaseSavepointsRepository.kt b/collect_app/src/main/java/org/odk/collect/android/database/savepoints/DatabaseSavepointsRepository.kt index b9029fee1ad..6b126b04acd 100644 --- a/collect_app/src/main/java/org/odk/collect/android/database/savepoints/DatabaseSavepointsRepository.kt +++ b/collect_app/src/main/java/org/odk/collect/android/database/savepoints/DatabaseSavepointsRepository.kt @@ -66,7 +66,7 @@ class DatabaseSavepointsRepository( val values = getValuesFromSavepoint(savepoint, cachePath, instancesPath) databaseConnection - .writeableDatabase + .writableDatabase .insertOrThrow(SAVEPOINTS_TABLE_NAME, null, values) } @@ -86,7 +86,7 @@ class DatabaseSavepointsRepository( } databaseConnection - .writeableDatabase + .writableDatabase .delete(SAVEPOINTS_TABLE_NAME, selection, selectionArgs) File(savepoint.savepointFilePath).delete() @@ -98,7 +98,7 @@ class DatabaseSavepointsRepository( } databaseConnection - .writeableDatabase + .writableDatabase .delete(SAVEPOINTS_TABLE_NAME) } diff --git a/db/src/main/java/org/odk/collect/db/sqlite/DatabaseConnection.kt b/db/src/main/java/org/odk/collect/db/sqlite/DatabaseConnection.kt index b709ed212e1..b5690057d99 100644 --- a/db/src/main/java/org/odk/collect/db/sqlite/DatabaseConnection.kt +++ b/db/src/main/java/org/odk/collect/db/sqlite/DatabaseConnection.kt @@ -26,7 +26,7 @@ open class DatabaseConnection @JvmOverloads constructor( private val databasePath = path + File.separator + name - val writeableDatabase: SQLiteDatabase + val writableDatabase: SQLiteDatabase get() { StrictMode.noteSlowCall("Accessing writable DB") return dbHelper.writableDatabase @@ -73,7 +73,7 @@ open class DatabaseConnection @JvmOverloads constructor( * * This can be dangerous if the database is being access by multiple threads as the connection * might be closed while a transaction is running or while another thread is using a - * [SQLiteDatabase] instance obtained via [writeableDatabase] or [readableDatabase]. Using + * [SQLiteDatabase] instance obtained via [writableDatabase] or [readableDatabase]. Using * [SynchronizedDatabaseConnection] is recommended in those scenarios. */ fun reset() { @@ -85,10 +85,9 @@ open class DatabaseConnection @JvmOverloads constructor( * used if a calls to [reset] will be made. * * Does not guarantee synchronized access if this or another [DatabaseConnection] for the - * same `.db` file uses [writeableDatabase] or [readableDatabase]. + * same `.db` file uses [writableDatabase] or [readableDatabase]. * [SynchronizedDatabaseConnection] can be used to ensure synchronized writes/reads to the * underlying DB. - * */ fun withSynchronizedConnection(block: DatabaseConnection.() -> T): T { return synchronized(dbHelper) { diff --git a/db/src/main/java/org/odk/collect/db/sqlite/SynchronizedDatabaseConnection.kt b/db/src/main/java/org/odk/collect/db/sqlite/SynchronizedDatabaseConnection.kt index 1400d3f30eb..21e63608aa4 100644 --- a/db/src/main/java/org/odk/collect/db/sqlite/SynchronizedDatabaseConnection.kt +++ b/db/src/main/java/org/odk/collect/db/sqlite/SynchronizedDatabaseConnection.kt @@ -27,7 +27,7 @@ class SynchronizedDatabaseConnection( body: SQLiteDatabase.() -> T ) { return withConnection { - writeableDatabase.transaction { + writableDatabase.transaction { body() } }