diff --git a/README.md b/README.md index 6ca8d3879..92417144d 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl ```groovy - def dbflow_version = "4.0.2" + def dbflow_version = "4.0.3" // or dbflow_version = "develop-SNAPSHOT" for grabbing latest dependency in your project on the develop branch // or 10-digit short-hash of a specific commit. (Useful for bugs fixed in develop, but not in a release yet) diff --git a/dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/ModelExtensions.kt b/dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/ModelExtensions.kt index 48943cea0..7bb21d96c 100644 --- a/dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/ModelExtensions.kt +++ b/dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/ModelExtensions.kt @@ -1,5 +1,6 @@ package com.raizlabs.android.dbflow.kotlinextensions +import com.raizlabs.android.dbflow.structure.AsyncModel import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper inline fun T.save(databaseWrapper: DatabaseWrapper = writableDatabaseForTable()) = modelAdapter().save(this, databaseWrapper) @@ -10,4 +11,6 @@ inline fun T.update(databaseWrapper: DatabaseWrapper = writabl inline fun T.delete(databaseWrapper: DatabaseWrapper = writableDatabaseForTable()) = modelAdapter().delete(this, databaseWrapper) -inline fun T.exists(databaseWrapper: DatabaseWrapper = writableDatabaseForTable()) = modelAdapter().exists(this, databaseWrapper) \ No newline at end of file +inline fun T.exists(databaseWrapper: DatabaseWrapper = writableDatabaseForTable()) = modelAdapter().exists(this, databaseWrapper) + +inline fun T.async(databaseWrapper: DatabaseWrapper = writableDatabaseForTable()) = AsyncModel(this) \ No newline at end of file diff --git a/dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/QueryExtensions.kt b/dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/QueryExtensions.kt index fd5a43cb4..094abdc57 100644 --- a/dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/QueryExtensions.kt +++ b/dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/QueryExtensions.kt @@ -52,7 +52,7 @@ infix fun Case.`else`(value: T?) = _else(value) infix fun Case.end(columnName: String) = end(columnName) -fun case(caseColumn: IProperty<*>? = null) = SQLite._case(caseColumn) +fun case(caseColumn: IProperty<*>) = SQLite._case(caseColumn) fun caseWhen(operator: SQLOperator) = SQLite.caseWhen(operator) @@ -100,16 +100,16 @@ inline val ModelQueriable.async get() = async() infix inline fun AsyncQuery.list(crossinline callback: (QueryTransaction<*>, MutableList) -> Unit) - = queryListResultCallback { queryTransaction, mutableList -> callback(queryTransaction, mutableList) } - .execute() + = queryListResultCallback { queryTransaction, mutableList -> callback(queryTransaction, mutableList) } + .execute() infix inline fun AsyncQuery.result(crossinline callback: (QueryTransaction<*>, T?) -> Unit) - = querySingleResultCallback { queryTransaction, model -> callback(queryTransaction, model) } - .execute() + = querySingleResultCallback { queryTransaction, model -> callback(queryTransaction, model) } + .execute() infix inline fun AsyncQuery.cursorResult(crossinline callback: (QueryTransaction<*>, CursorResult) -> Unit) - = queryResultCallback { queryTransaction, cursorResult -> callback(queryTransaction, cursorResult) } - .execute() + = queryResultCallback { queryTransaction, cursorResult -> callback(queryTransaction, cursorResult) } + .execute() inline val Model.async get() = async() @@ -163,7 +163,7 @@ infix fun Update.set(sqlOperator: SQLOperator) = set(sqlOperator) inline fun delete() = SQLite.delete(T::class.java) inline fun delete(deleteClause: From.() -> BaseModelQueriable) - = deleteClause(SQLite.delete(T::class.java)) + = deleteClause(SQLite.delete(T::class.java)) // insert methods diff --git a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/ProcessorManager.kt b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/ProcessorManager.kt index 5ce85aae1..972f72612 100644 --- a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/ProcessorManager.kt +++ b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/ProcessorManager.kt @@ -234,9 +234,8 @@ class ProcessorManager internal constructor(val processingEnvironment: Processin try { if (databaseHolderDefinition.databaseDefinition == null) { - manager.logError("Found null db with: ${databaseHolderDefinition.tableNameMap.values.size} tables," + - " ${databaseHolderDefinition.modelViewDefinitionMap.values.size} modelviews. " + - "Attempt to rebuild project should fix this intermittant issue.") + manager.logError("Found cannot find referenced db with: ${databaseHolderDefinition.tableNameMap.values.size} tables," + + " ${databaseHolderDefinition.modelViewDefinitionMap.values.size} modelviews. ") manager.logError("Found tables: " + databaseHolderDefinition.tableNameMap.values) continue } diff --git a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/IndexGroupsDefinition.kt b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/IndexGroupsDefinition.kt index 903523516..1398fd97c 100644 --- a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/IndexGroupsDefinition.kt +++ b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/IndexGroupsDefinition.kt @@ -19,20 +19,21 @@ class IndexGroupsDefinition(private val tableDefinition: TableDefinition, indexG val columnDefinitionList: MutableList = ArrayList() - val fieldSpec = field(ParameterizedTypeName.get(ClassNames.INDEX_PROPERTY, tableDefinition.elementClassName), - "index_$indexName") { - addModifiers(public, static, final) - `=` { - add("new \$T<>(${indexName.S}, $isUnique, \$T.class", - ClassNames.INDEX_PROPERTY, tableDefinition.elementTypeName) + val fieldSpec + get() = field(ParameterizedTypeName.get(ClassNames.INDEX_PROPERTY, tableDefinition.elementClassName), + "index_$indexName") { + addModifiers(public, static, final) + `=` { + add("new \$T<>(${indexName.S}, $isUnique, \$T.class", + ClassNames.INDEX_PROPERTY, tableDefinition.elementTypeName) - if (columnDefinitionList.isNotEmpty()) { - add(",") + if (columnDefinitionList.isNotEmpty()) { + add(",") + } + val index = AtomicInteger(0) + columnDefinitionList.forEach { it.appendIndexInitializer(this, index) } + add(")") } - val index = AtomicInteger(0) - columnDefinitionList.forEach { it.appendIndexInitializer(this, index) } - add(")") - } - }.build()!! + }.build()!! } diff --git a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/TableDefinition.kt b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/TableDefinition.kt index 00291f74c..8f62ddb4a 100644 --- a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/TableDefinition.kt +++ b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/TableDefinition.kt @@ -329,6 +329,8 @@ class TableDefinition(manager: ProcessorManager, element: TypeElement) : BaseTab get() = ParameterizedTypeName.get(ClassNames.MODEL_ADAPTER, elementClassName) override fun onWriteDefinition(typeBuilder: TypeSpec.Builder) { + // check references to properly set them up. + foreignKeyDefinitions.forEach { it.checkNeedsReferences() } typeBuilder.apply { writeGetModelClass(this, elementClassName) diff --git a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ColumnAccessCombiner.kt b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ColumnAccessCombiner.kt index 3711c12c1..1764bcb1e 100644 --- a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ColumnAccessCombiner.kt +++ b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ColumnAccessCombiner.kt @@ -136,7 +136,7 @@ class ContentValuesCombiner(combiner: Combiner) } override fun addNull(code: CodeBlock.Builder, columnRepresentation: String, index: Int) { - code.addStatement("values.putNull(\$S)", columnRepresentation) + code.addStatement("values.putNull(\$S)", QueryBuilder.quote(columnRepresentation)) } } diff --git a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ForeignKeyColumnDefinition.kt b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ForeignKeyColumnDefinition.kt index 46297f071..4e8530157 100644 --- a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ForeignKeyColumnDefinition.kt +++ b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ForeignKeyColumnDefinition.kt @@ -324,7 +324,7 @@ class ForeignKeyColumnDefinition(manager: ProcessorManager, tableDefinition: Tab * If [ForeignKey] has no [ForeignKeyReference]s, we use the primary key the referenced * table. We do this post-evaluation so all of the [TableDefinition] can be generated. */ - private fun checkNeedsReferences() { + fun checkNeedsReferences() { val tableDefinition = (baseTableDefinition as TableDefinition) val referencedTableDefinition = manager.getTableDefinition( tableDefinition.databaseTypeName, referencedTableClassName) diff --git a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/utils/ProcessorUtils.kt b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/utils/ProcessorUtils.kt index 7354b0fec..9d35a41c9 100644 --- a/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/utils/ProcessorUtils.kt +++ b/dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/utils/ProcessorUtils.kt @@ -2,9 +2,6 @@ package com.raizlabs.android.dbflow.processor.utils import com.raizlabs.android.dbflow.processor.ProcessorManager import com.raizlabs.android.dbflow.processor.ProcessorManager.Companion.manager -import com.raizlabs.android.dbflow.processor.utils.ElementUtility -import com.raizlabs.android.dbflow.processor.utils.erasure -import com.raizlabs.android.dbflow.processor.utils.toTypeElement import com.squareup.javapoet.ClassName import javax.annotation.processing.ProcessingEnvironment import javax.lang.model.element.Element @@ -92,7 +89,7 @@ fun getTypeElement(typeMirror: TypeMirror): TypeElement? { var typeElement: TypeElement? = typeMirror.toTypeElement(manager) if (typeElement == null) { val el = manager.typeUtils.asElement(typeMirror) - typeElement = if (el != null) (el as TypeElement) else null + typeElement = if (el != null && el is TypeElement) el else null } return typeElement } diff --git a/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherDatabase.java b/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherDatabase.java index 5b4f71c56..eb78f63ef 100644 --- a/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherDatabase.java +++ b/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherDatabase.java @@ -26,7 +26,7 @@ public static SQLCipherDatabase from(SQLiteDatabase database) { } @Override - public void execSQL(String query) { + public void execSQL(@NonNull String query) { database.execSQL(query); } @@ -50,8 +50,9 @@ public int getVersion() { return database.getVersion(); } + @NonNull @Override - public DatabaseStatement compileStatement(String rawQuery) { + public DatabaseStatement compileStatement(@NonNull String rawQuery) { return SQLCipherStatement.from(database.compileStatement(rawQuery)); } @@ -59,21 +60,23 @@ public SQLiteDatabase getDatabase() { return database; } + @NonNull @Override - public FlowCursor rawQuery(String query, String[] selectionArgs) { + public FlowCursor rawQuery(@NonNull String query, @Nullable String[] selectionArgs) { return FlowCursor.from(database.rawQuery(query, selectionArgs)); } @Override - public long updateWithOnConflict(String tableName, ContentValues contentValues, String where, String[] whereArgs, int conflictAlgorithm) { + public long updateWithOnConflict(@NonNull String tableName, @NonNull ContentValues contentValues, @Nullable String where, @Nullable String[] whereArgs, int conflictAlgorithm) { return database.updateWithOnConflict(tableName, contentValues, where, whereArgs, conflictAlgorithm); } @Override - public long insertWithOnConflict(String tableName, String nullColumnHack, ContentValues values, int sqLiteDatabaseAlgorithmInt) { + public long insertWithOnConflict(@NonNull String tableName, @Nullable String nullColumnHack, @NonNull ContentValues values, int sqLiteDatabaseAlgorithmInt) { return database.insertWithOnConflict(tableName, nullColumnHack, values, sqLiteDatabaseAlgorithmInt); } + @NonNull @Override public FlowCursor query(@NonNull String tableName, @Nullable String[] columns, diff --git a/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherOpenHelper.java b/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherOpenHelper.java index 372b37356..ea34301a5 100644 --- a/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherOpenHelper.java +++ b/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherOpenHelper.java @@ -1,6 +1,8 @@ package com.raizlabs.android.dbflow.sqlcipher; import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.DatabaseConfig; import com.raizlabs.android.dbflow.config.DatabaseDefinition; @@ -42,6 +44,7 @@ public void performRestoreFromBackup() { databaseHelperDelegate.performRestoreFromBackup(); } + @Nullable @Override public DatabaseHelperDelegate getDelegate() { return databaseHelperDelegate; @@ -57,6 +60,7 @@ public void backupDB() { databaseHelperDelegate.backupDB(); } + @NonNull @Override public DatabaseWrapper getDatabase() { if (cipherDatabase == null || !cipherDatabase.getDatabase().isOpen()) { @@ -71,7 +75,7 @@ public DatabaseWrapper getDatabase() { * * @param listener */ - public void setDatabaseListener(DatabaseHelperListener listener) { + public void setDatabaseListener(@Nullable DatabaseHelperListener listener) { databaseHelperDelegate.setDatabaseHelperListener(listener); } @@ -114,6 +118,7 @@ public BackupHelper(Context context, String name, int version, DatabaseDefinitio this.baseDatabaseHelper = new BaseDatabaseHelper(databaseDefinition); } + @NonNull @Override public DatabaseWrapper getDatabase() { if (sqlCipherDatabase == null) { @@ -126,6 +131,7 @@ public DatabaseWrapper getDatabase() { public void performRestoreFromBackup() { } + @Nullable @Override public DatabaseHelperDelegate getDelegate() { return null; @@ -145,7 +151,7 @@ public void closeDB() { } @Override - public void setDatabaseListener(DatabaseHelperListener helperListener) { + public void setDatabaseListener(@Nullable DatabaseHelperListener helperListener) { } @Override diff --git a/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherStatement.java b/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherStatement.java index b2d72267a..6c51130d7 100644 --- a/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherStatement.java +++ b/dbflow-sqlcipher/src/main/java/com/raizlabs/android/dbflow/sqlcipher/SQLCipherStatement.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.sqlcipher; +import android.support.annotation.Nullable; + import com.raizlabs.android.dbflow.structure.database.BaseDatabaseStatement; import com.raizlabs.android.dbflow.structure.database.DatabaseStatement; @@ -45,6 +47,7 @@ public long simpleQueryForLong() { return statement.simpleQueryForLong(); } + @Nullable @Override public String simpleQueryForString() { return statement.simpleQueryForString(); diff --git a/dbflow-tests/build.gradle b/dbflow-tests/build.gradle index 9202e26ae..9a281dd3e 100644 --- a/dbflow-tests/build.gradle +++ b/dbflow-tests/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-kapt' apply plugin: 'com.getkeepsafe.dexcount' android { diff --git a/dbflow-tests/src/androidTest/java/com/raizlabs/android/dbflow/DBFlowInstrumentedTestRule.kt b/dbflow-tests/src/androidTest/java/com/raizlabs/android/dbflow/DBFlowInstrumentedTestRule.kt index bc2793445..086dc03eb 100644 --- a/dbflow-tests/src/androidTest/java/com/raizlabs/android/dbflow/DBFlowInstrumentedTestRule.kt +++ b/dbflow-tests/src/androidTest/java/com/raizlabs/android/dbflow/DBFlowInstrumentedTestRule.kt @@ -15,9 +15,9 @@ class DBFlowInstrumentedTestRule : TestRule { @Throws(Throwable::class) override fun evaluate() { FlowManager.init(FlowConfig.Builder(DemoApp.context) - .addDatabaseConfig(DatabaseConfig.Builder(AppDatabase::class.java) - .transactionManagerCreator(::ImmediateTransactionManager) - .build()).build()) + .addDatabaseConfig(DatabaseConfig.Builder(AppDatabase::class.java) + .transactionManagerCreator(::ImmediateTransactionManager2) + .build()).build()) try { base.evaluate() } finally { diff --git a/dbflow-tests/src/main/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt b/dbflow-tests/src/androidTest/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt similarity index 78% rename from dbflow-tests/src/main/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt rename to dbflow-tests/src/androidTest/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt index 28310385e..6dcd865c6 100644 --- a/dbflow-tests/src/main/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt +++ b/dbflow-tests/src/androidTest/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt @@ -14,23 +14,21 @@ class ImmediateTransactionManager(databaseDefinition: DatabaseDefinition) class ImmediateTransactionQueue : ITransactionQueue { - override fun add(transaction: Transaction?) { - if (transaction != null) { - transaction.newBuilder() + override fun add(transaction: Transaction) { + transaction.newBuilder() .runCallbacksOnSameThread(true) .build() .executeSync() - } } - override fun cancel(transaction: Transaction?) { + override fun cancel(transaction: Transaction) { } override fun startIfNotAlive() { } - override fun cancel(name: String?) { + override fun cancel(name: String) { } override fun quit() { diff --git a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt index 28310385e..5d815a65f 100644 --- a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt +++ b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/ImmediateTransactionManager.kt @@ -8,29 +8,27 @@ import com.raizlabs.android.dbflow.structure.database.transaction.Transaction /** * Description: Executes all transactions on same thread for testing. */ -class ImmediateTransactionManager(databaseDefinition: DatabaseDefinition) - : BaseTransactionManager(ImmediateTransactionQueue(), databaseDefinition) +class ImmediateTransactionManager2(databaseDefinition: DatabaseDefinition) + : BaseTransactionManager(ImmediateTransactionQueue2(), databaseDefinition) -class ImmediateTransactionQueue : ITransactionQueue { +class ImmediateTransactionQueue2 : ITransactionQueue { - override fun add(transaction: Transaction?) { - if (transaction != null) { - transaction.newBuilder() + override fun add(transaction: Transaction) { + transaction.newBuilder() .runCallbacksOnSameThread(true) .build() .executeSync() - } } - override fun cancel(transaction: Transaction?) { + override fun cancel(transaction: Transaction) { } override fun startIfNotAlive() { } - override fun cancel(name: String?) { + override fun cancel(name: String) { } override fun quit() { diff --git a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/IndexModels.kt b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/IndexModels.kt new file mode 100644 index 000000000..a0be122fe --- /dev/null +++ b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/IndexModels.kt @@ -0,0 +1,34 @@ +package com.raizlabs.android.dbflow.models + +import com.raizlabs.android.dbflow.TestDatabase +import com.raizlabs.android.dbflow.annotation.* +import java.util.* + +/** + * Description: + */ + +@Table(database = TestDatabase::class, indexGroups = arrayOf(IndexGroup(number = 1, name = "firstIndex"), + IndexGroup(number = 2, name = "secondIndex"), + IndexGroup(number = 3, name = "thirdIndex"))) +class IndexModel { + @Index(indexGroups = intArrayOf(1, 2, 3)) + @PrimaryKey + var id: Int = 0 + + @Index(indexGroups = intArrayOf(1)) + @Column + var first_name: String? = null + + @Index(indexGroups = intArrayOf(2)) + @Column + var last_name: String? = null + + @Index(indexGroups = intArrayOf(3)) + @Column + var created_date: Date? = null + + @Index(indexGroups = intArrayOf(2, 3)) + @Column + var isPro: Boolean = false +} \ No newline at end of file diff --git a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/QueryModels.kt b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/QueryModels.kt index 86d61f072..8341df1e5 100644 --- a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/QueryModels.kt +++ b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/QueryModels.kt @@ -6,9 +6,9 @@ import com.raizlabs.android.dbflow.annotation.QueryModel import com.raizlabs.android.dbflow.converter.TypeConverter import com.raizlabs.android.dbflow.data.Blob -@QueryModel(database = TestDatabase::class) -class AuthorNameQuery(@Column var blogName: String = "", - @Column var authorId: Int = 0, @Column var blogId: Int = 0) +@QueryModel(database = TestDatabase::class, allFields = true) +class AuthorNameQuery(var blogName: String = "", + var authorId: Int = 0, var blogId: Int = 0) @QueryModel(database = TestDatabase::class) diff --git a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/SimpleTestModels.kt b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/SimpleTestModels.kt index b6804b0da..f0c725365 100644 --- a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/SimpleTestModels.kt +++ b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/models/SimpleTestModels.kt @@ -6,6 +6,8 @@ import com.raizlabs.android.dbflow.converter.TypeConverter import com.raizlabs.android.dbflow.data.Blob import com.raizlabs.android.dbflow.structure.database.DatabaseStatement import com.raizlabs.android.dbflow.structure.listener.SQLiteStatementListener +import java.util.* + /** * Description: @@ -67,21 +69,34 @@ class TypeConverterModel(@PrimaryKey var id: Int = 0, @Column(typeConverter = CustomTypeConverter::class) @PrimaryKey var customType: CustomType? = null) +@Table(database = TestDatabase::class, allFields = true) +class FeedEntry(@PrimaryKey var id: Int = 0, + var title: String? = null, + var subtitle: String? = null) + +@Table(database = TestDatabase::class) +@ManyToMany( + generatedTableClassName = "Refund", referencedTable = Transfer::class, + referencedTableColumnName = "refund_in", thisTableColumnName = "refund_out", + saveForeignKeyModels = true +) +data class Transfer(@PrimaryKey var transfer_id: UUID = UUID.randomUUID()) + @Table(database = TestDatabase::class) class SqlListenerModel(@PrimaryKey var id: Int = 0) : SQLiteStatementListener { - override fun onBindToStatement(databaseStatement: DatabaseStatement?) { + override fun onBindToStatement(databaseStatement: DatabaseStatement) { TODO("not implemented") } - override fun onBindToInsertStatement(databaseStatement: DatabaseStatement?) { + override fun onBindToInsertStatement(databaseStatement: DatabaseStatement) { TODO("not implemented") } - override fun onBindToUpdateStatement(databaseStatement: DatabaseStatement?) { + override fun onBindToUpdateStatement(databaseStatement: DatabaseStatement) { TODO("not implemented") } - override fun onBindToDeleteStatement(databaseStatement: DatabaseStatement?) { + override fun onBindToDeleteStatement(databaseStatement: DatabaseStatement) { TODO("not implemented") } } diff --git a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/FromTest.kt b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/FromTest.kt index 95cc8d7ec..16e373322 100644 --- a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/FromTest.kt +++ b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/FromTest.kt @@ -1,7 +1,6 @@ package com.raizlabs.android.dbflow.sql.language import com.raizlabs.android.dbflow.BaseUnitTest -import com.raizlabs.android.dbflow.contentobserver.User import com.raizlabs.android.dbflow.kotlinextensions.* import com.raizlabs.android.dbflow.models.SimpleModel import com.raizlabs.android.dbflow.models.SimpleModel_Table.name @@ -28,7 +27,7 @@ class FromTest : BaseUnitTest() { @Test fun validateMultipleProjection() { assertEquals("SELECT `name`,`name`,`id` FROM `SimpleModel`", - (select(name, TwoColumnModel_Table.name, id) from SimpleModel::class).query.trim()) + (select(name, TwoColumnModel_Table.name, id) from SimpleModel::class).query.trim()) } @Test @@ -39,10 +38,10 @@ class FromTest : BaseUnitTest() { @Test fun validateJoins() { val from = (select from SimpleModel::class - innerJoin TwoColumnModel::class - on name.eq(TwoColumnModel_Table.name.withTable())) + innerJoin TwoColumnModel::class + on name.eq(TwoColumnModel_Table.name.withTable())) assertEquals("SELECT * FROM `SimpleModel` INNER JOIN `TwoColumnModel` ON `name`=`TwoColumnModel`.`name`", - from.query.trim()) + from.query.trim()) assertTrue(from.associatedTables.isNotEmpty()) } } \ No newline at end of file diff --git a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/JoinTest.kt b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/JoinTest.kt index 6724b6c29..808322621 100644 --- a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/JoinTest.kt +++ b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/JoinTest.kt @@ -9,6 +9,7 @@ import com.raizlabs.android.dbflow.models.TwoColumnModel_Table import junit.framework.Assert.assertEquals import org.junit.Test + class JoinTest : BaseUnitTest() { @Test @@ -67,5 +68,4 @@ class JoinTest : BaseUnitTest() { assertEquals("SELECT * FROM `SimpleModel` NATURAL JOIN `TwoColumnModel`", join.query.trim()) } - } \ No newline at end of file diff --git a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/OperatorTest.kt b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/OperatorTest.kt index 19dbd35c3..568d90aa2 100644 --- a/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/OperatorTest.kt +++ b/dbflow-tests/src/test/java/com/raizlabs/android/dbflow/sql/language/OperatorTest.kt @@ -1,13 +1,11 @@ package com.raizlabs.android.dbflow.sql.language import com.raizlabs.android.dbflow.BaseUnitTest -import com.raizlabs.android.dbflow.models.TwoColumnModel_Table.id import com.raizlabs.android.dbflow.annotation.Collate import com.raizlabs.android.dbflow.assertEquals -import com.raizlabs.android.dbflow.kotlinextensions.and -import com.raizlabs.android.dbflow.kotlinextensions.between -import com.raizlabs.android.dbflow.kotlinextensions.collate -import com.raizlabs.android.dbflow.kotlinextensions.op +import com.raizlabs.android.dbflow.kotlinextensions.* +import com.raizlabs.android.dbflow.models.SimpleModel +import com.raizlabs.android.dbflow.models.TwoColumnModel_Table.id import org.junit.Test class OperatorTest : BaseUnitTest() { @@ -58,5 +56,6 @@ class OperatorTest : BaseUnitTest() { @Test fun testIn() { assertEquals("`id` IN (5,6,7,8,9)", id.`in`(5, 6, 7, 8) and 9) + assertEquals("`id` NOT IN (SELECT * FROM `SimpleModel`)", id.notIn(select from SimpleModel::class)) } } \ No newline at end of file diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/config/DatabaseDefinition.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/config/DatabaseDefinition.java index b7607353a..42ed846aa 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/config/DatabaseDefinition.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/config/DatabaseDefinition.java @@ -70,7 +70,7 @@ public abstract class DatabaseDefinition { @Nullable private DatabaseConfig databaseConfig; - @NonNull + @Nullable private ModelNotifier modelNotifier; @SuppressWarnings("unchecked") diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/config/FlowConfig.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/config/FlowConfig.java index 63ba9c662..15481471c 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/config/FlowConfig.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/config/FlowConfig.java @@ -27,16 +27,18 @@ public final class FlowConfig { openDatabasesOnInit = builder.openDatabasesOnInit; } + @NonNull public Set> databaseHolders() { return databaseHolders; } + @NonNull public Map, DatabaseConfig> databaseConfigMap() { return databaseConfigMap; } @Nullable - public DatabaseConfig getConfigForDatabase(Class databaseClass) { + public DatabaseConfig getConfigForDatabase(@NonNull Class databaseClass) { return databaseConfigMap().get(databaseClass); } @@ -60,12 +62,14 @@ public Builder(Context context) { this.context = context.getApplicationContext(); } - public Builder addDatabaseHolder(Class databaseHolderClass) { + @NonNull + public Builder addDatabaseHolder(@NonNull Class databaseHolderClass) { databaseHolders.add(databaseHolderClass); return this; } - public Builder addDatabaseConfig(DatabaseConfig databaseConfig) { + @NonNull + public Builder addDatabaseConfig(@NonNull DatabaseConfig databaseConfig) { databaseConfigMap.put(databaseConfig.databaseClass(), databaseConfig); return this; } @@ -74,11 +78,13 @@ public Builder addDatabaseConfig(DatabaseConfig databaseConfig) { * @param openDatabasesOnInit true if we want all databases open. * @return True to open all associated databases in DBFlow on calling of {@link FlowManager#init(FlowConfig)} */ + @NonNull public Builder openDatabasesOnInit(boolean openDatabasesOnInit) { this.openDatabasesOnInit = openDatabasesOnInit; return this; } + @NonNull public FlowConfig build() { return new FlowConfig(this); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/config/TableConfig.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/config/TableConfig.java index 196a29a0f..cc1d955a9 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/config/TableConfig.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/config/TableConfig.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.config; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.queriable.ListModelLoader; import com.raizlabs.android.dbflow.sql.queriable.SingleModelLoader; @@ -27,18 +28,22 @@ public final class TableConfig { listModelLoader = builder.listModelLoader; } + @NonNull public Class tableClass() { return tableClass; } + @Nullable public ModelSaver modelSaver() { return modelSaver; } + @Nullable public ListModelLoader listModelLoader() { return listModelLoader; } + @Nullable public SingleModelLoader singleModelLoader() { return singleModelLoader; } @@ -50,7 +55,7 @@ public static final class Builder { SingleModelLoader singleModelLoader; ListModelLoader listModelLoader; - public Builder(Class tableClass) { + public Builder(@NonNull Class tableClass) { this.tableClass = tableClass; } @@ -58,6 +63,7 @@ public Builder(Class tableClass) { * Define how the {@link ModelAdapter} saves data into the DB from its associated {@link TModel}. This * will override the default. */ + @NonNull public Builder modelAdapterModelSaver(@NonNull ModelSaver modelSaver) { this.modelAdapterModelSaver = modelSaver; return this; @@ -66,6 +72,7 @@ public Builder modelAdapterModelSaver(@NonNull ModelSaver modelS /** * Define how the table loads single models. This will override the default. */ + @NonNull public Builder singleModelLoader(@NonNull SingleModelLoader singleModelLoader) { this.singleModelLoader = singleModelLoader; return this; @@ -74,6 +81,7 @@ public Builder singleModelLoader(@NonNull SingleModelLoader sing /** * Define how the table loads a {@link List} of items. This will override the default. */ + @NonNull public Builder listModelLoader(@NonNull ListModelLoader listModelLoader) { this.listModelLoader = listModelLoader; return this; @@ -83,6 +91,7 @@ public Builder listModelLoader(@NonNull ListModelLoader listMode * @return A new {@link TableConfig}. Subsequent calls to this method produce a new instance * of {@link TableConfig}. */ + @NonNull public TableConfig build() { return new TableConfig<>(this); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowCursorIterator.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowCursorIterator.java index 07de0cc76..e6a1347ae 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowCursorIterator.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowCursorIterator.java @@ -1,6 +1,8 @@ package com.raizlabs.android.dbflow.list; import android.database.Cursor; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.util.ConcurrentModificationException; import java.util.ListIterator; @@ -15,15 +17,15 @@ public class FlowCursorIterator implements ListIterator, AutoClo private long startingCount; private long count; - public FlowCursorIterator(IFlowCursorIterator cursorList) { + public FlowCursorIterator(@NonNull IFlowCursorIterator cursorList) { this(cursorList, 0, cursorList.getCount()); } - public FlowCursorIterator(IFlowCursorIterator cursorList, int startingLocation) { + public FlowCursorIterator(@NonNull IFlowCursorIterator cursorList, int startingLocation) { this(cursorList, startingLocation, cursorList.getCount() - startingLocation); } - public FlowCursorIterator(IFlowCursorIterator cursorList, int startingLocation, + public FlowCursorIterator(@NonNull IFlowCursorIterator cursorList, int startingLocation, long count) { this.cursorList = cursorList; this.count = count; @@ -51,7 +53,7 @@ public void close() throws Exception { } @Override - public void add(TModel object) { + public void add(@Nullable TModel object) { throw new UnsupportedOperationException("Cursor Iterator: Cannot add a model in the iterator"); } @@ -67,6 +69,7 @@ public boolean hasPrevious() { return reverseIndex < count; } + @Nullable @Override public TModel next() { checkSizes(); @@ -80,6 +83,7 @@ public int nextIndex() { return (int) (reverseIndex + 1); } + @Nullable @Override public TModel previous() { checkSizes(); @@ -99,7 +103,7 @@ public void remove() { } @Override - public void set(TModel object) { + public void set(@Nullable TModel object) { throw new UnsupportedOperationException("Cursor Iterator: cannot set on an active Iterator "); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowCursorList.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowCursorList.java index db7c0d637..411ab6eac 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowCursorList.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowCursorList.java @@ -35,7 +35,7 @@ public interface OnCursorRefreshListener { * * @param cursorList The object that changed. */ - void onCursorRefreshed(FlowCursorList cursorList); + void onCursorRefreshed(@NonNull FlowCursorList cursorList); } /** @@ -88,19 +88,23 @@ private FlowCursorList(final Builder builder) { setCacheModels(cacheModels); } + @NonNull InstanceAdapter getInstanceAdapter() { return instanceAdapter; } + @NonNull ModelAdapter getModelAdapter() { return (ModelAdapter) instanceAdapter; } + @NonNull @Override public FlowCursorIterator iterator() { return new FlowCursorIterator<>(this); } + @NonNull @Override public FlowCursorIterator iterator(int startingLocation, long limit) { return new FlowCursorIterator<>(this, startingLocation, limit); @@ -109,13 +113,13 @@ public FlowCursorIterator iterator(int startingLocation, long limit) { /** * Register listener for when cursor refreshes. */ - public void addOnCursorRefreshListener(OnCursorRefreshListener onCursorRefreshListener) { + public void addOnCursorRefreshListener(@NonNull OnCursorRefreshListener onCursorRefreshListener) { synchronized (cursorRefreshListenerSet) { cursorRefreshListenerSet.add(onCursorRefreshListener); } } - public void removeOnCursorRefreshListener(OnCursorRefreshListener onCursorRefreshListener) { + public void removeOnCursorRefreshListener(@NonNull OnCursorRefreshListener onCursorRefreshListener) { synchronized (cursorRefreshListenerSet) { cursorRefreshListenerSet.remove(onCursorRefreshListener); } @@ -204,6 +208,7 @@ public TModel getItem(long position) { * @return the full, converted {@link TModel} list from the database on this list. For large * data sets that require a large conversion, consider calling this on a BG thread. */ + @NonNull public List getAll() { throwIfCursorClosed(); warnEmptyCursor(); @@ -238,6 +243,7 @@ public long getCount() { return cursor != null ? cursor.getCount() : 0; } + @NonNull public ModelCache modelCache() { return modelCache; } @@ -266,6 +272,7 @@ public Cursor cursor() { return cursor; } + @NonNull public Class table() { return table; } @@ -286,6 +293,7 @@ private void warnEmptyCursor() { * @return A new {@link Builder} that contains the same cache, query statement, and other * underlying data, but allows for modification. */ + @NonNull public Builder newBuilder() { return new Builder<>(table) .modelQueriable(modelQueriable) @@ -307,7 +315,7 @@ public static class Builder { private boolean cacheModels = true; private ModelCache modelCache; - public Builder(Class modelClass) { + public Builder(@NonNull Class modelClass) { this.modelClass = modelClass; } @@ -316,22 +324,28 @@ public Builder(@NonNull ModelQueriable modelQueriable) { modelQueriable(modelQueriable); } - public Builder cursor(Cursor cursor) { - this.cursor = FlowCursor.from(cursor); + @NonNull + public Builder cursor(@Nullable Cursor cursor) { + if (cursor != null) { + this.cursor = FlowCursor.from(cursor); + } return this; } - public Builder modelQueriable(ModelQueriable modelQueriable) { + @NonNull + public Builder modelQueriable(@Nullable ModelQueriable modelQueriable) { this.modelQueriable = modelQueriable; return this; } + @NonNull public Builder cacheModels(boolean cacheModels) { this.cacheModels = cacheModels; return this; } - public Builder modelCache(ModelCache modelCache) { + @NonNull + public Builder modelCache(@Nullable ModelCache modelCache) { this.modelCache = modelCache; if (modelCache != null) { cacheModels(true); @@ -339,6 +353,7 @@ public Builder modelCache(ModelCache modelCache) { return this; } + @NonNull public FlowCursorList build() { return new FlowCursorList<>(this); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowQueryList.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowQueryList.java index 4d663d2de..fb7e9aef5 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowQueryList.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/list/FlowQueryList.java @@ -11,6 +11,7 @@ import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.FlowManager; +import com.raizlabs.android.dbflow.list.FlowCursorList.OnCursorRefreshListener; import com.raizlabs.android.dbflow.runtime.FlowContentObserver; import com.raizlabs.android.dbflow.sql.language.SQLite; import com.raizlabs.android.dbflow.sql.queriable.ModelQueriable; @@ -76,15 +77,15 @@ private FlowQueryList(Builder builder) { * {@link #beginTransaction()} to bunch up calls to model changes and then {@link #endTransactionAndNotify()} to dispatch * and refresh this list when completed. */ - public void registerForContentChanges(Context context) { + public void registerForContentChanges(@NonNull Context context) { super.registerForContentChanges(context, internalCursorList.table()); } - public void addOnCursorRefreshListener(FlowCursorList.OnCursorRefreshListener onCursorRefreshListener) { + public void addOnCursorRefreshListener(@NonNull OnCursorRefreshListener onCursorRefreshListener) { internalCursorList.addOnCursorRefreshListener(onCursorRefreshListener); } - public void removeOnCursorRefreshListener(FlowCursorList.OnCursorRefreshListener onCursorRefreshListener) { + public void removeOnCursorRefreshListener(@NonNull OnCursorRefreshListener onCursorRefreshListener) { internalCursorList.removeOnCursorRefreshListener(onCursorRefreshListener); } @@ -119,18 +120,22 @@ public void onChange(boolean selfChange, Uri uri) { /** * @return a mutable list that does not reflect changes on the underlying DB. */ + @NonNull public List getCopy() { return internalCursorList.getAll(); } + @NonNull public FlowCursorList cursorList() { return internalCursorList; } + @Nullable public Transaction.Error error() { return errorCallback; } + @Nullable public Transaction.Success success() { return successCallback; } @@ -143,10 +148,12 @@ public boolean transact() { return transact; } + @NonNull ModelAdapter getModelAdapter() { return internalCursorList.getModelAdapter(); } + @NonNull InstanceAdapter getInstanceAdapter() { return internalCursorList.getInstanceAdapter(); } @@ -155,6 +162,7 @@ InstanceAdapter getInstanceAdapter() { * @return Constructs a new {@link Builder} that reuses the underlying {@link Cursor}, cache, * callbacks, and other properties. */ + @NonNull public Builder newBuilder() { return new Builder<>(internalCursorList) .success(successCallback) @@ -201,7 +209,7 @@ public void endTransactionAndNotify() { * @param model The model to save */ @Override - public void add(int location, TModel model) { + public void add(int location, @Nullable TModel model) { add(model); } @@ -212,19 +220,23 @@ public void add(int location, TModel model) { * @return always true */ @Override - public boolean add(TModel model) { - Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table()) - .beginTransactionAsync(new ProcessModelTransaction.Builder<>(saveModel) - .add(model).build()) - .error(internalErrorCallback) - .success(internalSuccessCallback).build(); + public boolean add(@Nullable TModel model) { + if (model != null) { + Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table()) + .beginTransactionAsync(new ProcessModelTransaction.Builder<>(saveModel) + .add(model).build()) + .error(internalErrorCallback) + .success(internalSuccessCallback).build(); - if (transact) { - transaction.execute(); + if (transact) { + transaction.execute(); + } else { + transaction.executeSync(); + } + return true; } else { - transaction.executeSync(); + return false; } - return true; } /** @@ -236,7 +248,7 @@ public boolean add(TModel model) { * @return always true */ @Override - public boolean addAll(int location, Collection collection) { + public boolean addAll(int location, @NonNull Collection collection) { return addAll(collection); } @@ -248,7 +260,7 @@ public boolean addAll(int location, Collection collection) { */ @SuppressWarnings("unchecked") @Override - public boolean addAll(Collection collection) { + public boolean addAll(@NonNull Collection collection) { // cast to normal collection, we do not want subclasses of this table saved final Collection tmpCollection = (Collection) collection; @@ -293,9 +305,9 @@ public void clear() { */ @SuppressWarnings("unchecked") @Override - public boolean contains(Object object) { + public boolean contains(@Nullable Object object) { boolean contains = false; - if (internalCursorList.table().isAssignableFrom(object.getClass())) { + if (object != null && internalCursorList.table().isAssignableFrom(object.getClass())) { TModel model = ((TModel) object); contains = internalCursorList.getInstanceAdapter().exists(model); } @@ -334,6 +346,7 @@ public TModel getItem(long position) { return internalCursorList.getItem(position); } + @Nullable @Override public Cursor cursor() { return internalCursorList.cursor(); @@ -347,6 +360,7 @@ public Cursor cursor() { * @return A model converted from the internal {@link FlowCursorList}. For * performance improvements, ensure caching is turned on. */ + @Nullable @Override public TModel get(int row) { return internalCursorList.getItem(row); @@ -373,6 +387,7 @@ public FlowCursorIterator iterator() { return new FlowCursorIterator<>(this); } + @NonNull @Override public FlowCursorIterator iterator(int startingLocation, long limit) { return new FlowCursorIterator<>(this, startingLocation, limit); @@ -608,7 +623,7 @@ public void processModel(TModel model, DatabaseWrapper wrapper) { private final Transaction.Error internalErrorCallback = new Transaction.Error() { @Override - public void onError(Transaction transaction, Throwable error) { + public void onError(@NonNull Transaction transaction, @NonNull Throwable error) { if (errorCallback != null) { errorCallback.onError(transaction, error); @@ -618,7 +633,7 @@ public void onError(Transaction transaction, Throwable error) { private final Transaction.Success internalSuccessCallback = new Transaction.Success() { @Override - public void onSuccess(Transaction transaction) { + public void onSuccess(@NonNull Transaction transaction) { if (!isInTransaction) { refreshAsync(); } else { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/list/IFlowCursorIterator.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/list/IFlowCursorIterator.java index a04a32785..31b890603 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/list/IFlowCursorIterator.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/list/IFlowCursorIterator.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.list; import android.database.Cursor; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.io.Closeable; @@ -25,16 +26,19 @@ public interface IFlowCursorIterator extends Closeable { /** * @return The cursor. */ + @Nullable Cursor cursor(); /** * @return Can iterate the {@link Cursor}. */ + @NonNull FlowCursorIterator iterator(); /** * @return Can iterate the {@link Cursor}. Specifies a starting location + count limit of results. */ + @NonNull FlowCursorIterator iterator(int startingLocation, long limit); @Override diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/BaseContentProvider.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/BaseContentProvider.java index 3837adf76..c15a761bf 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/BaseContentProvider.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/BaseContentProvider.java @@ -32,7 +32,7 @@ public interface PropertyConverter { protected BaseContentProvider() { } - protected BaseContentProvider(Class databaseHolderClass) { + protected BaseContentProvider(@NonNull Class databaseHolderClass) { this.moduleClass = databaseHolderClass; } @@ -70,8 +70,9 @@ public void execute(DatabaseWrapper databaseWrapper) { protected abstract String getDatabaseName(); - protected abstract int bulkInsert(Uri uri, ContentValues contentValues); + protected abstract int bulkInsert(@NonNull Uri uri, @NonNull ContentValues contentValues); + @NonNull protected DatabaseDefinition getDatabase() { if (database == null) { database = FlowManager.getDatabase(getDatabaseName()); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/BaseTransactionManager.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/BaseTransactionManager.java index 5f01b8af6..ffdb2f7c1 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/BaseTransactionManager.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/BaseTransactionManager.java @@ -22,6 +22,7 @@ public BaseTransactionManager(@NonNull ITransactionQueue transactionQueue, checkQueue(); } + @NonNull public DBBatchSaveQueue getSaveQueue() { try { if (!saveQueue.isAlive()) { @@ -33,6 +34,7 @@ public DBBatchSaveQueue getSaveQueue() { return saveQueue; } + @NonNull public ITransactionQueue getQueue() { return transactionQueue; } @@ -56,7 +58,7 @@ public void stopQueue() { * * @param transaction The transaction to add. */ - public void addTransaction(Transaction transaction) { + public void addTransaction(@NonNull Transaction transaction) { getQueue().add(transaction); } @@ -65,7 +67,7 @@ public void addTransaction(Transaction transaction) { * * @param transaction */ - public void cancelTransaction(Transaction transaction) { + public void cancelTransaction(@NonNull Transaction transaction) { getQueue().cancel(transaction); } } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/ContentResolverNotifier.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/ContentResolverNotifier.java index 516288f0e..8adc6d539 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/ContentResolverNotifier.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/ContentResolverNotifier.java @@ -15,7 +15,7 @@ */ public class ContentResolverNotifier implements ModelNotifier { @Override - public void notifyModelChanged(@Nullable T model, @NonNull ModelAdapter adapter, + public void notifyModelChanged(@NonNull T model, @NonNull ModelAdapter adapter, @NonNull BaseModel.Action action) { if (FlowContentObserver.shouldNotify()) { FlowManager.getContext().getContentResolver() @@ -49,12 +49,12 @@ public FlowContentTableNotifierRegister() { } @Override - public void register(Class tClass) { + public void register(@NonNull Class tClass) { flowContentObserver.registerForContentChanges(FlowManager.getContext(), tClass); } @Override - public void unregister(Class tClass) { + public void unregister(@NonNull Class tClass) { flowContentObserver.unregisterForContentChanges(FlowManager.getContext()); } @@ -65,7 +65,7 @@ public void unregisterAll() { } @Override - public void setListener(OnTableChangedListener contentChangeListener) { + public void setListener(@Nullable OnTableChangedListener contentChangeListener) { this.tableChangedListener = contentChangeListener; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/DBBatchSaveQueue.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/DBBatchSaveQueue.java index b40310991..db91ff429 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/DBBatchSaveQueue.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/DBBatchSaveQueue.java @@ -1,6 +1,8 @@ package com.raizlabs.android.dbflow.runtime; import android.os.Looper; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.DatabaseDefinition; import com.raizlabs.android.dbflow.config.FlowLog; @@ -89,7 +91,7 @@ public void setModelSaveCheckTime(long time) { * * @param errorListener The listener to use. */ - public void setErrorListener(Transaction.Error errorListener) { + public void setErrorListener(@Nullable Transaction.Error errorListener) { this.errorListener = errorListener; } @@ -98,7 +100,7 @@ public void setErrorListener(Transaction.Error errorListener) { * * @param successListener The listener to get notified when changes are successful. */ - public void setSuccessListener(Transaction.Success successListener) { + public void setSuccessListener(@Nullable Transaction.Success successListener) { this.successListener = successListener; } @@ -107,7 +109,7 @@ public void setSuccessListener(Transaction.Success successListener) { * * @param emptyTransactionListener The listener to get notified when the save queue thread ran but was empty. */ - public void setEmptyTransactionListener(Runnable emptyTransactionListener) { + public void setEmptyTransactionListener(@Nullable Runnable emptyTransactionListener) { this.emptyTransactionListener = emptyTransactionListener; } @@ -159,7 +161,7 @@ public void purgeQueue() { /** * Adds an object to this queue. */ - public void add(final Object inModel) { + public void add(@NonNull final Object inModel) { synchronized (models) { models.add(inModel); @@ -172,7 +174,7 @@ public void add(final Object inModel) { /** * Adds a {@link java.util.Collection} of DB objects to this queue */ - public void addAll(final Collection list) { + public void addAll(@NonNull final Collection list) { synchronized (models) { models.addAll(list); @@ -185,7 +187,7 @@ public void addAll(final Collection list) { /** * Adds a {@link java.util.Collection} of class that extend Object to this queue */ - public void addAll2(final Collection list) { + public void addAll2(@NonNull final Collection list) { synchronized (models) { models.addAll(list); @@ -198,7 +200,7 @@ public void addAll2(final Collection list) { /** * Removes a DB object from this queue before it is processed. */ - public void remove(final Object outModel) { + public void remove(@NonNull final Object outModel) { synchronized (models) { models.remove(outModel); } @@ -208,7 +210,7 @@ public void remove(final Object outModel) { * Removes a {@link java.util.Collection} of DB object from this queue * before it is processed. */ - public void removeAll(final Collection outCollection) { + public void removeAll(@NonNull final Collection outCollection) { synchronized (models) { models.removeAll(outCollection); } @@ -218,7 +220,7 @@ public void removeAll(final Collection outCollection) { * Removes a {@link java.util.Collection} of DB objects from this queue * before it is processed. */ - public void removeAll2(final Collection outCollection) { + public void removeAll2(@NonNull final Collection outCollection) { synchronized (models) { models.removeAll(outCollection); } @@ -246,7 +248,7 @@ public void processModel(Object model, DatabaseWrapper wrapper) { private final Transaction.Success successCallback = new Transaction.Success() { @Override - public void onSuccess(Transaction transaction) { + public void onSuccess(@NonNull Transaction transaction) { if (successListener != null) { successListener.onSuccess(transaction); } @@ -255,7 +257,7 @@ public void onSuccess(Transaction transaction) { private final Transaction.Error errorCallback = new Transaction.Error() { @Override - public void onError(Transaction transaction, Throwable error) { + public void onError(@NonNull Transaction transaction, @NonNull Throwable error) { if (errorListener != null) { errorListener.onError(transaction, error); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/DirectModelNotifier.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/DirectModelNotifier.java index 0a9a25576..d82ac32ab 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/DirectModelNotifier.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/DirectModelNotifier.java @@ -23,6 +23,7 @@ public class DirectModelNotifier implements ModelNotifier { private static DirectModelNotifier notifier; + @NonNull public static DirectModelNotifier get() { if (notifier == null) { notifier = new DirectModelNotifier(); @@ -32,7 +33,7 @@ public static DirectModelNotifier get() { public interface OnModelStateChangedListener { - void onModelChanged(T model, BaseModel.Action action); + void onModelChanged(@NonNull T model, @NonNull BaseModel.Action action); } @@ -57,7 +58,7 @@ private DirectModelNotifier() { } @Override - public void notifyModelChanged(@Nullable T model, @NonNull ModelAdapter adapter, + public void notifyModelChanged(@NonNull T model, @NonNull ModelAdapter adapter, @NonNull BaseModel.Action action) { final Set listeners = modelChangedListenerMap.get(adapter.getModelClass()); if (listeners != null) { @@ -86,12 +87,14 @@ public TableNotifierRegister newRegister() { return singleRegister; } - public void registerForModelChanges(Class table, ModelChangedListener listener) { + public void registerForModelChanges(@NonNull Class table, + @NonNull ModelChangedListener listener) { registerForModelStateChanges(table, listener); registerForTableChanges(table, listener); } - public void registerForModelStateChanges(Class table, OnModelStateChangedListener listener) { + public void registerForModelStateChanges(@NonNull Class table, + @NonNull OnModelStateChangedListener listener) { Set listeners = modelChangedListenerMap.get(table); if (listeners == null) { listeners = new LinkedHashSet<>(); @@ -100,7 +103,8 @@ public void registerForModelStateChanges(Class table, OnModelStateChanged listeners.add(listener); } - public void registerForTableChanges(Class table, OnTableChangedListener listener) { + public void registerForTableChanges(@NonNull Class table, + @NonNull OnTableChangedListener listener) { Set listeners = tableChangedListenerMap.get(table); if (listeners == null) { listeners = new LinkedHashSet<>(); @@ -109,20 +113,23 @@ public void registerForTableChanges(Class table, OnTableChangedListener l listeners.add(listener); } - public void unregisterForModelChanges(Class table, ModelChangedListener listener) { + public void unregisterForModelChanges(@NonNull Class table, + @NonNull ModelChangedListener listener) { unregisterForModelStateChanges(table, listener); unregisterForTableChanges(table, listener); } - public void unregisterForModelStateChanges(Class table, OnModelStateChangedListener listener) { + public void unregisterForModelStateChanges(@NonNull Class table, + @NonNull OnModelStateChangedListener listener) { Set listeners = modelChangedListenerMap.get(table); if (listeners != null) { listeners.remove(listener); } } - public void unregisterForTableChanges(Class table, OnTableChangedListener listener) { + public void unregisterForTableChanges(@NonNull Class table, + @NonNull OnTableChangedListener listener) { Set listeners = tableChangedListenerMap.get(table); if (listeners != null) { listeners.remove(listener); @@ -136,13 +143,13 @@ private class DirectTableNotifierRegister implements TableNotifierRegister { private OnTableChangedListener modelChangedListener; @Override - public void register(Class tClass) { + public void register(@NonNull Class tClass) { registeredTables.add(tClass); registerForTableChanges(tClass, internalChangeListener); } @Override - public void unregister(Class tClass) { + public void unregister(@NonNull Class tClass) { registeredTables.remove(tClass); unregisterForTableChanges(tClass, internalChangeListener); } @@ -156,7 +163,7 @@ public void unregisterAll() { } @Override - public void setListener(OnTableChangedListener modelChangedListener) { + public void setListener(@Nullable OnTableChangedListener modelChangedListener) { this.modelChangedListener = modelChangedListener; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/FlowContentObserver.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/FlowContentObserver.java index d04a3b180..06aa336e4 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/FlowContentObserver.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/FlowContentObserver.java @@ -100,7 +100,7 @@ public FlowContentObserver() { super(null); } - public FlowContentObserver(Handler handler) { + public FlowContentObserver(@Nullable Handler handler) { super(handler); } @@ -159,7 +159,7 @@ public void endTransactionAndNotify() { * * @param modelChangeListener Generic model change events from an {@link Action} */ - public void addModelChangeListener(OnModelStateChangedListener modelChangeListener) { + public void addModelChangeListener(@NonNull OnModelStateChangedListener modelChangeListener) { modelChangeListeners.add(modelChangeListener); } @@ -168,15 +168,15 @@ public void addModelChangeListener(OnModelStateChangedListener modelChangeListen * * @param modelChangeListener Generic model change events from a {@link Action} */ - public void removeModelChangeListener(OnModelStateChangedListener modelChangeListener) { + public void removeModelChangeListener(@NonNull OnModelStateChangedListener modelChangeListener) { modelChangeListeners.remove(modelChangeListener); } - public void addOnTableChangedListener(OnTableChangedListener onTableChangedListener) { + public void addOnTableChangedListener(@NonNull OnTableChangedListener onTableChangedListener) { onTableChangedListeners.add(onTableChangedListener); } - public void removeTableChangedListener(OnTableChangedListener onTableChangedListener) { + public void removeTableChangedListener(@NonNull OnTableChangedListener onTableChangedListener) { onTableChangedListeners.remove(onTableChangedListener); } @@ -185,7 +185,7 @@ public void removeTableChangedListener(OnTableChangedListener onTableChangedList * * @param contentChangeListener Generic model change events from an {@link Action} */ - public void addContentChangeListener(ContentChangeListener contentChangeListener) { + public void addContentChangeListener(@NonNull ContentChangeListener contentChangeListener) { modelChangeListeners.add(contentChangeListener); onTableChangedListeners.add(contentChangeListener); } @@ -195,7 +195,7 @@ public void addContentChangeListener(ContentChangeListener contentChangeListener * * @param contentChangeListener Generic model change events from a {@link Action} */ - public void removeContentChangeListener(ContentChangeListener contentChangeListener) { + public void removeContentChangeListener(@NonNull ContentChangeListener contentChangeListener) { modelChangeListeners.remove(contentChangeListener); onTableChangedListeners.remove(contentChangeListener); } @@ -203,14 +203,16 @@ public void removeContentChangeListener(ContentChangeListener contentChangeListe /** * Registers the observer for model change events for specific class. */ - public void registerForContentChanges(Context context, Class table) { + public void registerForContentChanges(@NonNull Context context, + @NonNull Class table) { registerForContentChanges(context.getContentResolver(), table); } /** * Registers the observer for model change events for specific class. */ - public void registerForContentChanges(ContentResolver contentResolver, Class table) { + public void registerForContentChanges(@NonNull ContentResolver contentResolver, + @NonNull Class table) { contentResolver.registerContentObserver(SqlUtils.getNotificationUri(table, null), true, this); REGISTERED_COUNT.incrementAndGet(); if (!registeredTables.containsValue(table)) { @@ -221,7 +223,7 @@ public void registerForContentChanges(ContentResolver contentResolver, Class /** * Unregisters this list for model change events */ - public void unregisterForContentChanges(Context context) { + public void unregisterForContentChanges(@NonNull Context context) { context.getContentResolver().unregisterContentObserver(this); REGISTERED_COUNT.decrementAndGet(); registeredTables.clear(); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/ModelNotifier.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/ModelNotifier.java index 5c5bfaa98..279df9926 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/ModelNotifier.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/ModelNotifier.java @@ -1,7 +1,6 @@ package com.raizlabs.android.dbflow.runtime; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.structure.BaseModel; import com.raizlabs.android.dbflow.structure.ModelAdapter; @@ -11,7 +10,7 @@ */ public interface ModelNotifier { - void notifyModelChanged(@Nullable T model, @NonNull ModelAdapter adapter, + void notifyModelChanged(@NonNull T model, @NonNull ModelAdapter adapter, @NonNull BaseModel.Action action); void notifyTableChanged(@NonNull Class table, @NonNull BaseModel.Action action); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/NotifyDistributor.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/NotifyDistributor.java index 4af27928f..af8279455 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/NotifyDistributor.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/NotifyDistributor.java @@ -14,6 +14,7 @@ public class NotifyDistributor implements ModelNotifier { private static NotifyDistributor distributor; + @NonNull public static NotifyDistributor get() { if (distributor == null) { distributor = new NotifyDistributor(); @@ -27,7 +28,7 @@ public TableNotifierRegister newRegister() { } @Override - public void notifyModelChanged(@Nullable TModel model, + public void notifyModelChanged(@NonNull TModel model, @NonNull ModelAdapter adapter, @NonNull BaseModel.Action action) { FlowManager.getModelNotifierForTable(adapter.getModelClass()) diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/TableNotifierRegister.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/TableNotifierRegister.java index 01a82a121..6ff597db6 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/TableNotifierRegister.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/runtime/TableNotifierRegister.java @@ -1,17 +1,20 @@ package com.raizlabs.android.dbflow.runtime; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + /** * Description: Defines how {@link ModelNotifier} registers listeners. Abstracts that away. */ public interface TableNotifierRegister { - void register(Class tClass); + void register(@NonNull Class tClass); - void unregister(Class tClass); + void unregister(@NonNull Class tClass); void unregisterAll(); - void setListener(OnTableChangedListener listener); + void setListener(@Nullable OnTableChangedListener listener); boolean isSubscribed(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/BaseAsyncObject.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/BaseAsyncObject.java index 098e310bd..310012975 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/BaseAsyncObject.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/BaseAsyncObject.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.DatabaseDefinition; import com.raizlabs.android.dbflow.config.FlowManager; @@ -19,11 +20,12 @@ public class BaseAsyncObject { private final Class table; private final DatabaseDefinition databaseDefinition; - public BaseAsyncObject(Class table) { + public BaseAsyncObject(@NonNull Class table) { this.table = table; databaseDefinition = FlowManager.getDatabaseForTable(table); } + @NonNull public Class getTable() { return table; } @@ -32,7 +34,7 @@ public Class getTable() { * Listen for any errors that occur during operations on this {@link TAsync}. */ @SuppressWarnings("unchecked") - public TAsync error(Transaction.Error errorCallback) { + public TAsync error(@Nullable Transaction.Error errorCallback) { this.errorCallback = errorCallback; return (TAsync) this; } @@ -41,7 +43,7 @@ public TAsync error(Transaction.Error errorCallback) { * Listens for successes on this {@link TAsync}. Will return the {@link Transaction}. */ @SuppressWarnings("unchecked") - public TAsync success(Transaction.Success success) { + public TAsync success(@Nullable Transaction.Success success) { this.successCallback = success; return (TAsync) this; } @@ -75,7 +77,7 @@ protected void onSuccess(@NonNull Transaction transaction) { private final Transaction.Error error = new Transaction.Error() { @Override - public void onError(Transaction transaction, Throwable error) { + public void onError(@NonNull Transaction transaction, @NonNull Throwable error) { if (errorCallback != null) { errorCallback.onError(transaction, error); } @@ -86,7 +88,7 @@ public void onError(Transaction transaction, Throwable error) { private final Transaction.Success success = new Transaction.Success() { @Override - public void onSuccess(Transaction transaction) { + public void onSuccess(@NonNull Transaction transaction) { if (successCallback != null) { successCallback.onSuccess(transaction); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/SqlUtils.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/SqlUtils.java index ad8c8ac5b..8e894e1d7 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/SqlUtils.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/SqlUtils.java @@ -71,7 +71,9 @@ public static void notifyTableChanged(@NonNull Class table, * @param conditions The set of key-value {@link SQLOperator} to construct into a uri. * @return The {@link Uri}. */ - public static Uri getNotificationUri(Class modelClass, Action action, Iterable conditions) { + public static Uri getNotificationUri(@NonNull Class modelClass, + @Nullable Action action, + @Nullable Iterable conditions) { Uri.Builder uriBuilder = new Uri.Builder().scheme("dbflow") .authority(FlowManager.getTableName(modelClass)); if (action != null) { @@ -94,7 +96,8 @@ public static Uri getNotificationUri(Class modelClass, Action action, Iterabl * @param conditions The set of key-value {@link SQLOperator} to construct into a uri. * @return The {@link Uri}. */ - public static Uri getNotificationUri(Class modelClass, Action action, + public static Uri getNotificationUri(@NonNull Class modelClass, + @NonNull Action action, @Nullable SQLOperator[] conditions) { Uri.Builder uriBuilder = new Uri.Builder().scheme("dbflow") .authority(FlowManager.getTableName(modelClass)); @@ -121,8 +124,10 @@ public static Uri getNotificationUri(Class modelClass, Action action, * @return Notification uri. */ - public static Uri getNotificationUri(Class modelClass, Action action, - String notifyKey, Object notifyValue) { + public static Uri getNotificationUri(@NonNull Class modelClass, + @NonNull Action action, + @NonNull String notifyKey, + @Nullable Object notifyValue) { Operator operator = null; if (StringUtils.isNotNullOrEmpty(notifyKey)) { operator = Operator.op(new NameAlias.Builder(notifyKey).build()).value(notifyValue); @@ -135,7 +140,7 @@ public static Uri getNotificationUri(Class modelClass, Action action, * @param action The {@link Action} to use. * @return The uri for updates to {@link Model}, meant for general changes. */ - public static Uri getNotificationUri(Class modelClass, Action action) { + public static Uri getNotificationUri(@NonNull Class modelClass, @NonNull Action action) { return getNotificationUri(modelClass, action, null, null); } @@ -146,7 +151,7 @@ public static Uri getNotificationUri(Class modelClass, Action action) { * @param mOnTable The table that this trigger runs on * @param triggerName The name of the trigger */ - public static void dropTrigger(Class mOnTable, String triggerName) { + public static void dropTrigger(@NonNull Class mOnTable, @NonNull String triggerName) { QueryBuilder queryBuilder = new QueryBuilder("DROP TRIGGER IF EXISTS ") .append(triggerName); FlowManager.getDatabaseForTable(mOnTable).getWritableDatabase().execSQL(queryBuilder.getQuery()); @@ -157,13 +162,15 @@ public static void dropTrigger(Class mOnTable, String triggerName) { * * @param indexName The name of the index. */ - public static void dropIndex(DatabaseWrapper databaseWrapper, String indexName) { + public static void dropIndex(@NonNull DatabaseWrapper databaseWrapper, + @NonNull String indexName) { QueryBuilder queryBuilder = new QueryBuilder("DROP INDEX IF EXISTS ") .append(QueryBuilder.quoteIfNeeded(indexName)); databaseWrapper.execSQL(queryBuilder.getQuery()); } - public static void dropIndex(Class onTable, String indexName) { + public static void dropIndex(@NonNull Class onTable, + @NonNull String indexName) { dropIndex(FlowManager.getDatabaseForTable(onTable).getWritableDatabase(), indexName); } @@ -188,6 +195,7 @@ public static void addContentValues(@NonNull ContentValues contentValues, @NonNu * @param key The key to check. * @return The key, whether it's quoted or not. */ + @NonNull public static String getContentValuesKey(ContentValues contentValues, String key) { String quoted = QueryBuilder.quoteIfNeeded(key); if (contentValues.containsKey(quoted)) { @@ -202,7 +210,8 @@ public static String getContentValuesKey(ContentValues contentValues, String key } } - public static long longForQuery(DatabaseWrapper wrapper, String query) { + public static long longForQuery(@NonNull DatabaseWrapper wrapper, + @NonNull String query) { DatabaseStatement statement = wrapper.compileStatement(query); try { return statement.simpleQueryForLong(); @@ -214,6 +223,7 @@ public static long longForQuery(DatabaseWrapper wrapper, String query) { /** * Converts a byte[] to a String hex representation for within wrapper queries. */ + @NonNull public static String byteArrayToHexString(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Actionable.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Actionable.java index 5520f117b..f461f91d8 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Actionable.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Actionable.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.sql.language; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.structure.BaseModel.Action; /** @@ -7,5 +9,6 @@ */ public interface Actionable { + @NonNull Action getPrimaryAction(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseModelQueriable.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseModelQueriable.java index e4b9c0d04..419c3f2a0 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseModelQueriable.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseModelQueriable.java @@ -70,7 +70,7 @@ public TModel querySingle() { } @Override - public TModel querySingle(DatabaseWrapper wrapper) { + public TModel querySingle(@NonNull DatabaseWrapper wrapper) { String query = getQuery(); FlowLog.log(FlowLog.Level.V, "Executing query: " + query); return getSingleModelLoader().load(wrapper, query); @@ -78,7 +78,7 @@ public TModel querySingle(DatabaseWrapper wrapper) { @NonNull @Override - public List queryList(DatabaseWrapper wrapper) { + public List queryList(@NonNull DatabaseWrapper wrapper) { String query = getQuery(); FlowLog.log(FlowLog.Level.V, "Executing query: " + query); return getListModelLoader().load(wrapper, query); @@ -107,7 +107,7 @@ public long executeUpdateDelete() { } @Override - public long executeUpdateDelete(DatabaseWrapper databaseWrapper) { + public long executeUpdateDelete(@NonNull DatabaseWrapper databaseWrapper) { long affected = databaseWrapper.compileStatement(getQuery()).executeUpdateDelete(); // only notify for affected. @@ -125,7 +125,7 @@ public AsyncQuery async() { @NonNull @Override - public List queryCustomList(Class queryModelClass) { + public List queryCustomList(@NonNull Class queryModelClass) { String query = getQuery(); FlowLog.log(FlowLog.Level.V, "Executing query: " + query); QueryModelAdapter adapter = FlowManager.getQueryModelAdapter(queryModelClass); @@ -136,7 +136,7 @@ public List queryCustomList(Class queryMode @Nullable @Override - public QueryClass queryCustomSingle(Class queryModelClass) { + public QueryClass queryCustomSingle(@NonNull Class queryModelClass) { String query = getQuery(); FlowLog.log(FlowLog.Level.V, "Executing query: " + query); QueryModelAdapter adapter = FlowManager.getQueryModelAdapter(queryModelClass); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseOperator.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseOperator.java index 579b095a6..5b7535e63 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseOperator.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseOperator.java @@ -2,6 +2,7 @@ import android.database.DatabaseUtils; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.FlowManager; import com.raizlabs.android.dbflow.converter.TypeConverter; @@ -15,6 +16,7 @@ */ public abstract class BaseOperator implements SQLOperator { + @Nullable public static String convertValueToString(Object value, boolean appendInnerQueryParenthesis) { return convertValueToString(value, appendInnerQueryParenthesis, true); } @@ -43,7 +45,9 @@ public static String convertValueToString(Object value, boolean appendInnerQuery * @return Returns the result as a string that's safe for SQLite. */ @SuppressWarnings("unchecked") - public static String convertValueToString(Object value, boolean appendInnerQueryParenthesis, + @Nullable + public static String convertValueToString(@Nullable Object value, + boolean appendInnerQueryParenthesis, boolean typeConvert) { if (value == null) { return "NULL"; @@ -100,8 +104,10 @@ public static String convertValueToString(Object value, boolean appendInnerQuery * the objects by calling {@link #convertValueToString(Object, boolean)}. * @return A joined string */ - public static String joinArguments(CharSequence delimiter, Iterable tokens, - BaseOperator condition) { + @NonNull + public static String joinArguments(@NonNull CharSequence delimiter, + @NonNull Iterable tokens, + @NonNull BaseOperator condition) { StringBuilder sb = new StringBuilder(); boolean firstTime = true; for (Object token : tokens) { @@ -123,7 +129,8 @@ public static String joinArguments(CharSequence delimiter, Iterable tokens, * the objects by calling object.toString(). * @return A joined string */ - public static String joinArguments(CharSequence delimiter, Object[] tokens) { + @NonNull + public static String joinArguments(@NonNull CharSequence delimiter, @NonNull Object[] tokens) { StringBuilder sb = new StringBuilder(); boolean firstTime = true; for (Object token : tokens) { @@ -145,7 +152,8 @@ public static String joinArguments(CharSequence delimiter, Object[] tokens) { * the objects by calling object.toString(). * @return A joined string */ - public static String joinArguments(CharSequence delimiter, Iterable tokens) { + @NonNull + public static String joinArguments(@NonNull CharSequence delimiter, @NonNull Iterable tokens) { StringBuilder sb = new StringBuilder(); boolean firstTime = true; for (Object token : tokens) { @@ -172,6 +180,7 @@ public static String joinArguments(CharSequence delimiter, Iterable tokens) { /** * The column name */ + @NonNull protected NameAlias nameAlias; /** @@ -189,7 +198,7 @@ public static String joinArguments(CharSequence delimiter, Iterable tokens) { */ protected boolean isValueSet; - BaseOperator(NameAlias nameAlias) { + BaseOperator(@NonNull NameAlias nameAlias) { this.nameAlias = nameAlias; } @@ -204,6 +213,7 @@ public Object value() { /** * @return the column name */ + @NonNull @Override public String columnName() { return nameAlias.getQuery(); @@ -211,11 +221,12 @@ public String columnName() { @NonNull @Override - public SQLOperator separator(String separator) { + public SQLOperator separator(@NonNull String separator) { this.separator = separator; return this; } + @Nullable @Override public String separator() { return separator; @@ -232,6 +243,7 @@ public boolean hasSeparator() { /** * @return the operator such as "<", ">", or "=" */ + @NonNull public String operation() { return operation; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseQueriable.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseQueriable.java index e356774b9..207884723 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseQueriable.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseQueriable.java @@ -44,7 +44,7 @@ public Class getTable() { * catches a {@link SQLiteDoneException} if result is not found and returns 0. The error can safely be ignored. */ @Override - public long count(DatabaseWrapper databaseWrapper) { + public long count(@NonNull DatabaseWrapper databaseWrapper) { try { String query = getQuery(); FlowLog.log(FlowLog.Level.V, "Executing query: " + query); @@ -72,7 +72,7 @@ public boolean hasData() { } @Override - public boolean hasData(DatabaseWrapper databaseWrapper) { + public boolean hasData(@NonNull DatabaseWrapper databaseWrapper) { return count(databaseWrapper) > 0; } @@ -83,7 +83,7 @@ public FlowCursor query() { } @Override - public FlowCursor query(DatabaseWrapper databaseWrapper) { + public FlowCursor query(@NonNull DatabaseWrapper databaseWrapper) { if (getPrimaryAction().equals(BaseModel.Action.INSERT)) { // inserting, let's compile and insert DatabaseStatement databaseStatement = compileStatement(databaseWrapper); @@ -103,7 +103,7 @@ public long executeInsert() { } @Override - public long executeInsert(DatabaseWrapper databaseWrapper) { + public long executeInsert(@NonNull DatabaseWrapper databaseWrapper) { return compileStatement().executeInsert(); } @@ -119,7 +119,7 @@ public void execute() { } @Override - public void execute(DatabaseWrapper databaseWrapper) { + public void execute(@NonNull DatabaseWrapper databaseWrapper) { Cursor cursor = query(databaseWrapper); if (cursor != null) { cursor.close(); @@ -129,13 +129,15 @@ public void execute(DatabaseWrapper databaseWrapper) { } } + @NonNull @Override public DatabaseStatement compileStatement() { return compileStatement(FlowManager.getWritableDatabaseForTable(table)); } + @NonNull @Override - public DatabaseStatement compileStatement(DatabaseWrapper databaseWrapper) { + public DatabaseStatement compileStatement(@NonNull DatabaseWrapper databaseWrapper) { String query = getQuery(); FlowLog.log(FlowLog.Level.V, "Compiling Query Into Statement: " + query); return new DatabaseStatementWrapper<>(databaseWrapper.compileStatement(query), this); @@ -146,5 +148,6 @@ public String toString() { return getQuery(); } + @NonNull public abstract BaseModel.Action getPrimaryAction(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseTransformable.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseTransformable.java index 1bb0f2b7a..1e21b2996 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseTransformable.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/BaseTransformable.java @@ -34,7 +34,7 @@ public FlowCursor query() { } @Override - public FlowCursor query(DatabaseWrapper databaseWrapper) { + public FlowCursor query(@NonNull DatabaseWrapper databaseWrapper) { return where().query(databaseWrapper); } @@ -49,12 +49,12 @@ public long count() { } @Override - public long count(DatabaseWrapper databaseWrapper) { + public long count(@NonNull DatabaseWrapper databaseWrapper) { return where().count(databaseWrapper); } @Override - public long executeUpdateDelete(DatabaseWrapper databaseWrapper) { + public long executeUpdateDelete(@NonNull DatabaseWrapper databaseWrapper) { return where().executeUpdateDelete(databaseWrapper); } @@ -72,25 +72,25 @@ public Where groupBy(IProperty... properties) { @NonNull @Override - public Where orderBy(NameAlias nameAlias, boolean ascending) { + public Where orderBy(@NonNull NameAlias nameAlias, boolean ascending) { return where().orderBy(nameAlias, ascending); } @NonNull @Override - public Where orderBy(IProperty property, boolean ascending) { + public Where orderBy(@NonNull IProperty property, boolean ascending) { return where().orderBy(property, ascending); } @NonNull @Override - public Where orderByAll(List orderBies) { + public Where orderByAll(@NonNull List orderBies) { return where().orderByAll(orderBies); } @NonNull @Override - public Where orderBy(OrderBy orderBy) { + public Where orderBy(@NonNull OrderBy orderBy) { return where().orderBy(orderBy); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Case.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Case.java index d07cb2bd0..f18a31924 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Case.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Case.java @@ -38,7 +38,7 @@ public class Case implements Query { } @NonNull - public CaseCondition when(SQLOperator sqlOperator) { + public CaseCondition when(@NonNull SQLOperator sqlOperator) { if (efficientCase) { throw new IllegalStateException("When using the efficient CASE method," + "you must pass in value only, not condition."); @@ -49,7 +49,7 @@ public CaseCondition when(SQLOperator sqlOperator) { } @NonNull - public CaseCondition when(TReturn whenValue) { + public CaseCondition when(@Nullable TReturn whenValue) { if (!efficientCase) { throw new IllegalStateException("When not using the efficient CASE method, " + "you must pass in the SQLOperator as a parameter"); @@ -60,7 +60,7 @@ public CaseCondition when(TReturn whenValue) { } @NonNull - public CaseCondition when(IProperty property) { + public CaseCondition when(@NonNull IProperty property) { if (!efficientCase) { throw new IllegalStateException("When not using the efficient CASE method, " + "you must pass in the SQLOperator as a parameter"); @@ -74,7 +74,7 @@ public CaseCondition when(IProperty property) { * Default case here. If not specified, value will be NULL. */ @NonNull - public Case _else(TReturn elseValue) { + public Case _else(@Nullable TReturn elseValue) { this.elseValue = elseValue; elseSpecified = true; // ensure its set especially if null specified. return this; diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CaseCondition.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CaseCondition.java index d47a2899c..400fa818f 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CaseCondition.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CaseCondition.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.language; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.Query; import com.raizlabs.android.dbflow.sql.QueryBuilder; @@ -40,13 +41,13 @@ public class CaseCondition implements Query { * THEN part of this query, the value that gets set on column if condition is true. */ @NonNull - public Case then(TReturn value) { + public Case then(@Nullable TReturn value) { thenValue = value; return caze; } @NonNull - public Case then(IProperty value) { + public Case then(@NonNull IProperty value) { thenProperty = value; // in case values are null in some sense. isThenPropertySet = true; diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CompletedTrigger.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CompletedTrigger.java index 0950ded08..135ff6c3d 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CompletedTrigger.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CompletedTrigger.java @@ -35,7 +35,7 @@ public class CompletedTrigger implements Query { * Appends the nextStatement to this query as another line to be executed by trigger. */ @NonNull - public CompletedTrigger and(Query nextStatement) { + public CompletedTrigger and(@NonNull Query nextStatement) { this.triggerLogicQuery.add(nextStatement); return this; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CursorResult.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CursorResult.java index f53038135..27ff0ce74 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CursorResult.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/CursorResult.java @@ -26,7 +26,9 @@ public class CursorResult implements IFlowCursorIterator { @SuppressWarnings("unchecked") CursorResult(Class modelClass, @Nullable Cursor cursor) { - this.cursor = FlowCursor.from(cursor); + if (cursor != null) { + this.cursor = FlowCursor.from(cursor); + } retrievalAdapter = FlowManager.getInstanceAdapter(modelClass); } @@ -68,7 +70,7 @@ public List toListClose() { * @return A {@link List} of items from this object. You must call {@link #close()} when finished. */ @NonNull - public List toCustomList(Class customClass) { + public List toCustomList(@NonNull Class customClass) { return cursor != null ? FlowManager.getQueryModelAdapter(customClass) .getListModelLoader().convertToData(cursor, null) : new ArrayList(); } @@ -77,7 +79,7 @@ public List toCustomList(Class customClass) { * @return Converts the {@link Cursor} to a {@link List} of {@link TModel} and then closes it. */ @NonNull - public List toCustomListClose(Class customClass) { + public List toCustomListClose(@NonNull Class customClass) { final List customList = cursor != null ? FlowManager.getQueryModelAdapter(customClass) .getListModelLoader().load(cursor) : new ArrayList(); close(); @@ -106,7 +108,7 @@ public TModel toModelClose() { * @return The first {@link TModel} of items from the contained {@link Cursor}. You must call {@link #close()} when finished. */ @Nullable - public TCustom toCustomModel(Class customClass) { + public TCustom toCustomModel(@NonNull Class customClass) { return cursor != null ? FlowManager.getQueryModelAdapter(customClass) .getSingleModelLoader().convertToData(cursor, null) : null; } @@ -115,7 +117,7 @@ public TCustom toCustomModel(Class customClass) { * @return Converts the {@link Cursor} to a {@link TModel} and then closes it. */ @Nullable - public TCustom toCustomModelClose(Class customClass) { + public TCustom toCustomModelClose(@NonNull Class customClass) { final TCustom customList = cursor != null ? FlowManager.getQueryModelAdapter(customClass) .getSingleModelLoader().load(cursor) : null; close(); @@ -132,11 +134,13 @@ public TModel getItem(long position) { return model; } + @NonNull @Override public FlowCursorIterator iterator() { return new FlowCursorIterator<>(this); } + @NonNull @Override public FlowCursorIterator iterator(int startingLocation, long limit) { return new FlowCursorIterator<>(this, startingLocation, limit); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Delete.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Delete.java index 2e020f03e..5e2048d21 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Delete.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Delete.java @@ -17,7 +17,7 @@ public class Delete implements Query { * @param conditions The list of conditions to use to delete from the specified table * @param The class that implements {@link com.raizlabs.android.dbflow.structure.Model} */ - public static void table(Class table, SQLOperator... conditions) { + public static void table(@NonNull Class table, SQLOperator... conditions) { new Delete().from(table).where(conditions).executeUpdateDelete(); } @@ -41,7 +41,7 @@ public static void tables(Class... tables) { * @return */ @NonNull - public From from(Class table) { + public From from(@NonNull Class table) { return new From<>(this, table); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/ExistenceOperator.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/ExistenceOperator.java index b9d156acd..ae5786307 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/ExistenceOperator.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/ExistenceOperator.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.language; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.Query; import com.raizlabs.android.dbflow.sql.QueryBuilder; @@ -13,15 +14,17 @@ public class ExistenceOperator implements SQLOperator, Query { private Where innerWhere; @Override - public void appendConditionToQuery(QueryBuilder queryBuilder) { + public void appendConditionToQuery(@NonNull QueryBuilder queryBuilder) { queryBuilder.appendQualifier("EXISTS", "(" + innerWhere.getQuery().trim() + ")"); } + @NonNull @Override public String columnName() { throw new RuntimeException("Method not valid for ExistenceOperator"); } + @Nullable @Override public String separator() { throw new RuntimeException("Method not valid for ExistenceOperator"); @@ -29,7 +32,7 @@ public String separator() { @NonNull @Override - public SQLOperator separator(String separator) { + public SQLOperator separator(@NonNull String separator) { // not used. throw new RuntimeException("Method not valid for ExistenceOperator"); } @@ -39,6 +42,7 @@ public boolean hasSeparator() { return false; } + @NonNull @Override public String operation() { return ""; diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/From.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/From.java index 03f6b55dd..57a60389c 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/From.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/From.java @@ -194,6 +194,7 @@ public IndexedBy indexedBy(IndexProperty indexProperty) { return new IndexedBy<>(indexProperty, this); } + @NonNull @Override public BaseModel.Action getPrimaryAction() { return (queryBase instanceof Delete) ? BaseModel.Action.DELETE : BaseModel.Action.CHANGE; diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IConditional.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IConditional.java index 4b3e4b891..817c55c28 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IConditional.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IConditional.java @@ -11,119 +11,121 @@ public interface IConditional extends Query { @NonNull - Operator is(IConditional conditional); + Operator is(@NonNull IConditional conditional); @NonNull - Operator is(BaseModelQueriable baseModelQueriable); + Operator is(@NonNull BaseModelQueriable baseModelQueriable); @NonNull Operator isNull(); @NonNull - Operator eq(IConditional conditional); + Operator eq(@NonNull IConditional conditional); @NonNull - Operator eq(BaseModelQueriable baseModelQueriable); + Operator eq(@NonNull BaseModelQueriable baseModelQueriable); @NonNull Operator isNotNull(); @NonNull - Operator concatenate(IConditional conditional); + Operator concatenate(@NonNull IConditional conditional); @NonNull - Operator isNot(IConditional conditional); + Operator isNot(@NonNull IConditional conditional); @NonNull - Operator isNot(BaseModelQueriable baseModelQueriable); + Operator isNot(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator notEq(IConditional conditional); + Operator notEq(@NonNull IConditional conditional); @NonNull - Operator notEq(BaseModelQueriable baseModelQueriable); + Operator notEq(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator like(IConditional conditional); + Operator like(@NonNull IConditional conditional); @NonNull - Operator like(BaseModelQueriable baseModelQueriable); + Operator like(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator notLike(IConditional conditional); + Operator notLike(@NonNull IConditional conditional); @NonNull - Operator notLike(BaseModelQueriable baseModelQueriable); + Operator notLike(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator glob(IConditional conditional); + Operator glob(@NonNull IConditional conditional); @NonNull - Operator glob(BaseModelQueriable baseModelQueriable); + Operator glob(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator like(String value); + Operator like(@NonNull String value); @NonNull - Operator notLike(String value); + Operator notLike(@NonNull String value); @NonNull - Operator glob(String value); + Operator glob(@NonNull String value); @NonNull - Operator greaterThan(IConditional conditional); + Operator greaterThan(@NonNull IConditional conditional); @NonNull - Operator greaterThan(BaseModelQueriable baseModelQueriable); + Operator greaterThan(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator greaterThanOrEq(IConditional conditional); + Operator greaterThanOrEq(@NonNull IConditional conditional); @NonNull - Operator greaterThanOrEq(BaseModelQueriable baseModelQueriable); + Operator greaterThanOrEq(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator lessThan(IConditional conditional); + Operator lessThan(@NonNull IConditional conditional); @NonNull - Operator lessThan(BaseModelQueriable baseModelQueriable); + Operator lessThan(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator lessThanOrEq(IConditional conditional); + Operator lessThanOrEq(@NonNull IConditional conditional); @NonNull - Operator lessThanOrEq(BaseModelQueriable baseModelQueriable); + Operator lessThanOrEq(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator.Between between(IConditional conditional); + Operator.Between between(@NonNull IConditional conditional); @NonNull - Operator.Between between(BaseModelQueriable baseModelQueriable); + Operator.Between between(@NonNull BaseModelQueriable baseModelQueriable); @NonNull - Operator.In in(IConditional firstConditional, IConditional... conditionals); + Operator.In in(@NonNull IConditional firstConditional, @NonNull IConditional... conditionals); @NonNull - Operator.In in(BaseModelQueriable firstBaseModelQueriable, BaseModelQueriable... baseModelQueriables); + Operator.In in(@NonNull BaseModelQueriable firstBaseModelQueriable, + @NonNull BaseModelQueriable... baseModelQueriables); @NonNull - Operator.In notIn(IConditional firstConditional, IConditional... conditionals); + Operator.In notIn(@NonNull IConditional firstConditional, @NonNull IConditional... conditionals); @NonNull - Operator.In notIn(BaseModelQueriable firstBaseModelQueriable, BaseModelQueriable... baseModelQueriables); + Operator.In notIn(@NonNull BaseModelQueriable firstBaseModelQueriable, + @NonNull BaseModelQueriable... baseModelQueriables); @NonNull - Operator plus(BaseModelQueriable value); + Operator plus(@NonNull BaseModelQueriable value); @NonNull - Operator minus(BaseModelQueriable value); + Operator minus(@NonNull BaseModelQueriable value); @NonNull - Operator div(BaseModelQueriable value); + Operator div(@NonNull BaseModelQueriable value); @NonNull - Operator times(BaseModelQueriable value); + Operator times(@NonNull BaseModelQueriable value); @NonNull - Operator rem(BaseModelQueriable value); + Operator rem(@NonNull BaseModelQueriable value); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IOperator.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IOperator.java index 396069336..701b6bb07 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IOperator.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IOperator.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.language; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.Query; @@ -18,7 +19,7 @@ public interface IOperator extends Query, IConditional { * @return A {@link Operator} that represents equality between this and the parameter. */ @NonNull - Operator is(T value); + Operator is(@Nullable T value); /** * Assigns the operation to "=". Identical to {@link #is(T)} @@ -28,7 +29,7 @@ public interface IOperator extends Query, IConditional { * @see #is(T) */ @NonNull - Operator eq(T value); + Operator eq(@Nullable T value); /** * Generates a {@link Operator} that concatenates this {@link IOperator} with the {@link T} via "||" @@ -38,7 +39,7 @@ public interface IOperator extends Query, IConditional { * @return A {@link Operator} that represents concatenation. */ @NonNull - Operator concatenate(T value); + Operator concatenate(@Nullable T value); /** * Assigns the operation to "!=" @@ -47,7 +48,7 @@ public interface IOperator extends Query, IConditional { * @return A {@link Operator} that represents inequality between this and the parameter. */ @NonNull - Operator isNot(T value); + Operator isNot(@Nullable T value); /** * Assigns the operation to "!=" @@ -57,7 +58,7 @@ public interface IOperator extends Query, IConditional { * @see #notEq(T) */ @NonNull - Operator notEq(T value); + Operator notEq(@Nullable T value); /** * Assigns operation to ">" @@ -66,7 +67,7 @@ public interface IOperator extends Query, IConditional { * @return A {@link Operator} that represents greater than between this and the parameter. */ @NonNull - Operator greaterThan(T value); + Operator greaterThan(@NonNull T value); /** * Assigns operation to ">=" @@ -75,7 +76,7 @@ public interface IOperator extends Query, IConditional { * @return A {@link Operator} that represents greater than or equal between this and the parameter. */ @NonNull - Operator greaterThanOrEq(T value); + Operator greaterThanOrEq(@NonNull T value); /** @@ -85,7 +86,7 @@ public interface IOperator extends Query, IConditional { * @return A {@link Operator} that represents less than between this and the parameter. */ @NonNull - Operator lessThan(T value); + Operator lessThan(@NonNull T value); /** @@ -95,10 +96,10 @@ public interface IOperator extends Query, IConditional { * @return A {@link Operator} that represents less than or equal to between this and the parameter. */ @NonNull - Operator lessThanOrEq(T value); + Operator lessThanOrEq(@NonNull T value); @NonNull - Operator.Between between(T value); + Operator.Between between(@NonNull T value); /** * Turns this {@link IOperator} into an {@link Operator.In}. It means that this object should @@ -110,7 +111,7 @@ public interface IOperator extends Query, IConditional { */ @NonNull @SuppressWarnings("unchecked") - Operator.In in(T firstValue, T... values); + Operator.In in(@NonNull T firstValue, T... values); /** * Turns this {@link IOperator} into an {@link Operator.In} (not). It means that this object should NOT @@ -122,7 +123,7 @@ public interface IOperator extends Query, IConditional { */ @NonNull @SuppressWarnings("unchecked") - Operator.In notIn(T firstValue, T... values); + Operator.In notIn(@NonNull T firstValue, T... values); /** * Turns this {@link IOperator} into an {@link Operator.In}. It means that this object should @@ -132,7 +133,7 @@ public interface IOperator extends Query, IConditional { * @return A new {@link Operator.In} built from this {@link IOperator}. */ @NonNull - Operator.In in(Collection values); + Operator.In in(@NonNull Collection values); /** * Turns this {@link IOperator} into an {@link Operator.In} (not). It means that this object should NOT @@ -142,7 +143,7 @@ public interface IOperator extends Query, IConditional { * @return A new {@link Operator.In} (not) built from this {@link IOperator}. */ @NonNull - Operator.In notIn(Collection values); + Operator.In notIn(@NonNull Collection values); /** * Adds another value and returns the operator. i.e p1 + p2 @@ -150,7 +151,7 @@ public interface IOperator extends Query, IConditional { * @param value the value to add. */ @NonNull - Operator plus(T value); + Operator plus(@NonNull T value); /** * Subtracts another value and returns the operator. i.e p1 - p2 @@ -158,7 +159,7 @@ public interface IOperator extends Query, IConditional { * @param value the value to subtract. */ @NonNull - Operator minus(T value); + Operator minus(@NonNull T value); /** * Divides another value and returns as the operator. i.e p1 / p2 @@ -167,14 +168,14 @@ public interface IOperator extends Query, IConditional { * @return A new instance. */ @NonNull - Operator div(T value); + Operator div(@NonNull T value); /** * Multiplies another value and returns as the operator. i.e p1 * p2 * * @param value the value to multiply. */ - Operator times(T value); + Operator times(@NonNull T value); /** * Modulous another value and returns as the operator. i.e p1 % p2 @@ -182,5 +183,5 @@ public interface IOperator extends Query, IConditional { * @param value the value to calculate remainder of. */ @NonNull - Operator rem(T value); + Operator rem(@NonNull T value); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Index.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Index.java index 69887adee..c79f5e476 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Index.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Index.java @@ -72,7 +72,7 @@ public Index on(@NonNull Class table, IProperty... properties) { * @return This instance. */ @NonNull - public Index on(@NonNull Class table, NameAlias firstAlias, NameAlias... columns) { + public Index on(@NonNull Class table, @NonNull NameAlias firstAlias, NameAlias... columns) { this.table = table; and(firstAlias); for (NameAlias column : columns) { @@ -88,7 +88,7 @@ public Index on(@NonNull Class table, NameAlias firstAlias, Name * @return This instance. */ @NonNull - public Index and(IProperty property) { + public Index and(@NonNull IProperty property) { if (!columns.contains(property.getNameAlias())) { columns.add(property.getNameAlias()); } @@ -102,7 +102,7 @@ public Index and(IProperty property) { * @return This instance. */ @NonNull - public Index and(NameAlias columnName) { + public Index and(@NonNull NameAlias columnName) { if (!columns.contains(columnName)) { columns.add(columnName); } @@ -132,8 +132,7 @@ public boolean isUnique() { return isUnique; } - public void enable(DatabaseWrapper databaseWrapper) { - + public void enable(@NonNull DatabaseWrapper databaseWrapper) { if (table == null) { throw new IllegalStateException("Please call on() to set a table to use this index on."); } else if (columns == null || columns.isEmpty()) { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IndexedBy.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IndexedBy.java index 61673c8b7..b585984da 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IndexedBy.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/IndexedBy.java @@ -41,6 +41,7 @@ public String getQuery() { return queryBuilder.getQuery(); } + @NonNull @Override public BaseModel.Action getPrimaryAction() { return whereBase.getPrimaryAction(); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Insert.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Insert.java index 897dabf34..8a3ffd590 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Insert.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Insert.java @@ -2,6 +2,7 @@ import android.content.ContentValues; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.annotation.ConflictAction; import com.raizlabs.android.dbflow.config.FlowManager; @@ -46,7 +47,7 @@ public class Insert extends BaseQueriable implements Query { * * @param table The table to insert into */ - public Insert(Class table) { + public Insert(@NonNull Class table) { super(table); } @@ -57,7 +58,7 @@ public Insert(Class table) { * @param columns The columns to use */ @NonNull - public Insert columns(String... columns) { + public Insert columns(@NonNull String... columns) { this.columns = new IProperty[columns.length]; ModelAdapter modelClassModelAdapter = FlowManager.getModelAdapter(getTable()); for (int i = 0; i < columns.length; i++) { @@ -68,7 +69,7 @@ public Insert columns(String... columns) { } @NonNull - public Insert columns(IProperty... properties) { + public Insert columns(@NonNull IProperty... properties) { this.columns = new IProperty[properties.length]; for (int i = 0; i < properties.length; i++) { columns[i] = properties[i]; @@ -113,7 +114,7 @@ public Insert asColumnValues() { * @param values The non type-converted values */ @NonNull - public Insert values(Object... values) { + public Insert values(@Nullable Object... values) { if (this.valuesList == null) { this.valuesList = new ArrayList<>(); } @@ -128,7 +129,7 @@ public Insert values(Object... values) { * @param values The non type-converted values */ @NonNull - public Insert values(Collection values) { + public Insert values(@NonNull Collection values) { if (this.valuesList == null) { this.valuesList = new ArrayList<>(); } @@ -142,7 +143,7 @@ public Insert values(Collection values) { * @param conditions The conditions that we use to fill the columns and values of this INSERT */ @NonNull - public Insert columnValues(SQLOperator... conditions) { + public Insert columnValues(@NonNull SQLOperator... conditions) { String[] columns = new String[conditions.length]; Object[] values = new Object[conditions.length]; @@ -162,7 +163,7 @@ public Insert columnValues(SQLOperator... conditions) { * @param operatorGroup The OperatorGroup to use */ @NonNull - public Insert columnValues(OperatorGroup operatorGroup) { + public Insert columnValues(@NonNull OperatorGroup operatorGroup) { int size = operatorGroup.size(); String[] columns = new String[size]; @@ -178,7 +179,7 @@ public Insert columnValues(OperatorGroup operatorGroup) { } @NonNull - public Insert columnValues(ContentValues contentValues) { + public Insert columnValues(@NonNull ContentValues contentValues) { java.util.Set> entries = contentValues.valueSet(); int count = 0; String[] columns = new String[contentValues.size()]; @@ -199,7 +200,7 @@ public Insert columnValues(ContentValues contentValues) { * @param selectFrom The from that is continuation of {@link Select}. */ @NonNull - public Insert select(From selectFrom) { + public Insert select(@NonNull From selectFrom) { this.selectFrom = selectFrom; return this; } @@ -212,7 +213,7 @@ public Insert select(From selectFrom) { * @return */ @NonNull - public Insert or(ConflictAction action) { + public Insert or(@NonNull ConflictAction action) { conflictAction = action; return this; } @@ -270,7 +271,7 @@ public Insert orIgnore() { } @Override - public long executeUpdateDelete(DatabaseWrapper databaseWrapper) { + public long executeUpdateDelete(@NonNull DatabaseWrapper databaseWrapper) { throw new IllegalStateException("Cannot call executeUpdateDelete() from an Insert"); } @@ -323,6 +324,7 @@ public String getQuery() { return queryBuilder.getQuery(); } + @NonNull @Override public BaseModel.Action getPrimaryAction() { return BaseModel.Action.INSERT; diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Join.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Join.java index fb2444458..b607935f6 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Join.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Join.java @@ -82,15 +82,15 @@ public enum JoinType { */ private List using = new ArrayList<>(); - public Join(From from, Class table, @NonNull JoinType joinType) { + public Join(@NonNull From from, @NonNull Class table, @NonNull JoinType joinType) { this.from = from; this.table = table; type = joinType; alias = new NameAlias.Builder(FlowManager.getTableName(table)).build(); } - public Join(From from, @NonNull JoinType joinType, - ModelQueriable modelQueriable) { + public Join(@NonNull From from, @NonNull JoinType joinType, + @NonNull ModelQueriable modelQueriable) { table = modelQueriable.getTable(); this.from = from; type = joinType; @@ -104,7 +104,7 @@ public Join(From from, @NonNull JoinType joinType, * @return This instance */ @NonNull - public Join as(String alias) { + public Join as(@NonNull String alias) { this.alias = this.alias .newBuilder() .as(alias) @@ -174,6 +174,7 @@ public String getQuery() { return queryBuilder.getQuery(); } + @NonNull public Class getTable() { return table; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Method.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Method.java index a552c04f5..73b7e0172 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Method.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Method.java @@ -21,6 +21,7 @@ public class Method extends Property { * @return The average value of all properties within this group. The result is always a float from this statement * as long as there is at least one non-NULL input. The result may be NULL if there are no non-NULL columns. */ + @NonNull public static Method avg(IProperty... properties) { return new Method("AVG", properties); } @@ -30,6 +31,7 @@ public static Method avg(IProperty... properties) { * @return A count of the number of times that specified properties are not NULL in a group. Leaving * the properties empty returns COUNT(*), which is the total number of rows in the query. */ + @NonNull public static Method count(IProperty... properties) { return new Method("COUNT", properties); } @@ -38,6 +40,7 @@ public static Method count(IProperty... properties) { * @param properties Set of properties that the method acts on. * @return A string which is the concatenation of all non-NULL values of the properties. */ + @NonNull public static Method group_concat(IProperty... properties) { return new Method("GROUP_CONCAT", properties); } @@ -46,6 +49,7 @@ public static Method group_concat(IProperty... properties) { * @param properties Set of properties that the method acts on. * @return The method that represents the max of the specified columns/properties. */ + @NonNull public static Method max(IProperty... properties) { return new Method("MAX", properties); } @@ -54,6 +58,7 @@ public static Method max(IProperty... properties) { * @param properties Set of properties that the method acts on. * @return The method that represents the min of the specified columns/properties. */ + @NonNull public static Method min(IProperty... properties) { return new Method("MIN", properties); } @@ -62,6 +67,7 @@ public static Method min(IProperty... properties) { * @param properties Set of properties that the method acts on. * @return The method that represents the sum of the specified columns/properties. */ + @NonNull public static Method sum(IProperty... properties) { return new Method("SUM", properties); } @@ -70,6 +76,7 @@ public static Method sum(IProperty... properties) { * @param properties Set of properties that the method acts on. * @return The method that represents the total of the specified columns/properties. */ + @NonNull public static Method total(IProperty... properties) { return new Method("TOTAL", properties); } @@ -78,18 +85,21 @@ public static Method total(IProperty... properties) { * @param property The property to cast. * @return A new CAST object. To complete use the {@link Cast#as(SQLiteType)} method. */ + @NonNull public static Cast cast(@NonNull IProperty property) { return new Cast(property); } - public static Method replace(IProperty property, String findString, String replacement) { + @NonNull + public static Method replace(@NonNull IProperty property, String findString, String replacement) { return new Method("REPLACE", property, PropertyFactory.from(findString), PropertyFactory.from(replacement)); } /** * SQLite standard "strftime()" method. See SQLite documentation on this method. */ - public static Method strftime(String formatString, String timeString, String... modifiers) { + public static Method strftime(@NonNull String formatString, + @NonNull String timeString, String... modifiers) { List propertyList = new ArrayList<>(); propertyList.add(PropertyFactory.from(formatString)); propertyList.add(PropertyFactory.from(timeString)); @@ -114,7 +124,8 @@ public static Method datetime(long timeStamp, String... modifiers) { /** * Sqlite "date" method. See SQLite documentation on this method. */ - public static Method date(String timeString, String... modifiers) { + public static Method date(@NonNull String timeString, + String... modifiers) { List propertyList = new ArrayList<>(); propertyList.add(PropertyFactory.from(timeString)); for (String modifier : modifiers) { @@ -127,7 +138,8 @@ public static Method date(String timeString, String... modifiers) { * @return Constructs using the "IFNULL" method in SQLite. It will pick the first non null * value and set that. If both are NULL then it will use NULL. */ - public static Method ifNull(IProperty first, IProperty secondIfFirstNull) { + public static Method ifNull(@NonNull IProperty first, + @NonNull IProperty secondIfFirstNull) { return new Method("IFNULL", first, secondIfFirstNull); } @@ -135,7 +147,8 @@ public static Method ifNull(IProperty first, IProperty secondIfFirstNull) { * @return Constructs using the "NULLIF" method in SQLite. If both expressions are equal, then * NULL is set into the DB. */ - public static Method nullIf(IProperty first, IProperty second) { + public static Method nullIf(@NonNull IProperty first, + @NonNull IProperty second) { return new Method("NULLIF", first, second); } @@ -164,30 +177,30 @@ public Method(String methodName, IProperty... properties) { @NonNull @Override - public Method plus(IProperty property) { + public Method plus(@NonNull IProperty property) { return append(property, " " + Operator.Operation.PLUS); } @NonNull @Override - public Method minus(IProperty property) { + public Method minus(@NonNull IProperty property) { return append(property, " " + Operator.Operation.MINUS); } @NonNull @Override - public Property div(IProperty property) { + public Property div(@NonNull IProperty property) { return append(property, " " + Operator.Operation.DIVISION); } @Override - public Property times(IProperty property) { + public Property times(@NonNull IProperty property) { return append(property, " " + Operator.Operation.MULTIPLY); } @NonNull @Override - public Property rem(IProperty property) { + public Property rem(@NonNull IProperty property) { return append(property, " " + Operator.Operation.MOD); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/NameAlias.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/NameAlias.java index 12d09113f..c45b5e4da 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/NameAlias.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/NameAlias.java @@ -19,10 +19,7 @@ public class NameAlias implements Query { * @return The new namealias object. */ @NonNull - public static NameAlias joinNames(String operation, String... names) { - if (names.length == 0) { - return null; - } + public static NameAlias joinNames(@NonNull String operation, String... names) { String newName = ""; for (int i = 0; i < names.length; i++) { if (i > 0) { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Operator.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Operator.java index 054d49086..cb09983e0 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Operator.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Operator.java @@ -64,7 +64,7 @@ public static Operator op(NameAlias alias, TypeConverter typeConverter, b } @Override - public void appendConditionToQuery(QueryBuilder queryBuilder) { + public void appendConditionToQuery(@NonNull QueryBuilder queryBuilder) { queryBuilder.append(columnName()).append(operation()); // Do not use value for certain operators @@ -116,7 +116,7 @@ public Operator notEq(T value) { */ @NonNull @Override - public Operator like(String value) { + public Operator like(@NonNull String value) { operation = String.format(" %1s ", Operation.LIKE); return value(value); } @@ -133,7 +133,7 @@ public Operator like(String value) { */ @NonNull @Override - public Operator notLike(String value) { + public Operator notLike(@NonNull String value) { operation = String.format(" %1s ", Operation.NOT_LIKE); return value(value); } @@ -150,7 +150,7 @@ public Operator notLike(String value) { */ @NonNull @Override - public Operator glob(String value) { + public Operator glob(@NonNull String value) { operation = String.format(" %1s ", Operation.GLOB); return value(value); } @@ -169,58 +169,58 @@ public Operator value(Object value) { @NonNull @Override - public Operator greaterThan(T value) { + public Operator greaterThan(@NonNull T value) { operation = Operation.GREATER_THAN; return value(value); } @NonNull @Override - public Operator greaterThanOrEq(T value) { + public Operator greaterThanOrEq(@NonNull T value) { operation = Operation.GREATER_THAN_OR_EQUALS; return value(value); } @NonNull @Override - public Operator lessThan(T value) { + public Operator lessThan(@NonNull T value) { operation = Operation.LESS_THAN; return value(value); } @NonNull @Override - public Operator lessThanOrEq(T value) { + public Operator lessThanOrEq(@NonNull T value) { operation = Operation.LESS_THAN_OR_EQUALS; return value(value); } @NonNull @Override - public Operator plus(T value) { + public Operator plus(@NonNull T value) { return assignValueOp(value, Operation.PLUS); } @NonNull @Override - public Operator minus(T value) { + public Operator minus(@NonNull T value) { return assignValueOp(value, Operation.MINUS); } @NonNull @Override - public Operator div(T value) { + public Operator div(@NonNull T value) { return assignValueOp(value, Operation.DIVISION); } @Override - public Operator times(T value) { + public Operator times(@NonNull T value) { return assignValueOp(value, Operation.MULTIPLY); } @NonNull @Override - public Operator rem(T value) { + public Operator rem(@NonNull T value) { return assignValueOp(value, Operation.MOD); } @@ -296,168 +296,168 @@ public Operator isNotNull() { */ @NonNull @Override - public Operator separator(String separator) { + public Operator separator(@NonNull String separator) { this.separator = separator; return this; } @NonNull @Override - public Operator is(IConditional conditional) { + public Operator is(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.EQUALS); } @NonNull @Override - public Operator eq(IConditional conditional) { + public Operator eq(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.EQUALS); } @NonNull @Override - public Operator isNot(IConditional conditional) { + public Operator isNot(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.NOT_EQUALS); } @NonNull @Override - public Operator notEq(IConditional conditional) { + public Operator notEq(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.NOT_EQUALS); } @NonNull @Override - public Operator like(IConditional conditional) { + public Operator like(@NonNull IConditional conditional) { return like(conditional.getQuery()); } @NonNull @Override - public Operator glob(IConditional conditional) { + public Operator glob(@NonNull IConditional conditional) { return glob(conditional.getQuery()); } @NonNull @Override - public Operator greaterThan(IConditional conditional) { + public Operator greaterThan(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.GREATER_THAN); } @NonNull @Override - public Operator greaterThanOrEq(IConditional conditional) { + public Operator greaterThanOrEq(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.GREATER_THAN_OR_EQUALS); } @NonNull @Override - public Operator lessThan(IConditional conditional) { + public Operator lessThan(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.LESS_THAN); } @NonNull @Override - public Operator lessThanOrEq(IConditional conditional) { + public Operator lessThanOrEq(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.LESS_THAN_OR_EQUALS); } @NonNull @SuppressWarnings("unchecked") @Override - public Between between(IConditional conditional) { + public Between between(@NonNull IConditional conditional) { return new Between(this, conditional); } @NonNull @SuppressWarnings("unchecked") @Override - public In in(IConditional firstConditional, IConditional... conditionals) { - return new In(this, firstConditional, true, (Object) conditionals); + public In in(@NonNull IConditional firstConditional, @NonNull IConditional... conditionals) { + return new In(this, firstConditional, true, conditionals); } @NonNull @SuppressWarnings("unchecked") @Override - public In notIn(IConditional firstConditional, IConditional... conditionals) { - return new In(this, firstConditional, false, (Object) conditionals); + public In notIn(@NonNull IConditional firstConditional, @NonNull IConditional... conditionals) { + return new In(this, firstConditional, false, conditionals); } @NonNull @SuppressWarnings("unchecked") @Override - public In notIn(BaseModelQueriable firstBaseModelQueriable, BaseModelQueriable[] baseModelQueriables) { - return new In(this, firstBaseModelQueriable, false, (Object) baseModelQueriables); + public In notIn(@NonNull BaseModelQueriable firstBaseModelQueriable, @NonNull BaseModelQueriable[] baseModelQueriables) { + return new In(this, firstBaseModelQueriable, false, (Object[]) baseModelQueriables); } @NonNull @Override - public Operator is(BaseModelQueriable baseModelQueriable) { + public Operator is(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.EQUALS); } @NonNull @Override - public Operator eq(BaseModelQueriable baseModelQueriable) { + public Operator eq(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.EQUALS); } @NonNull @Override - public Operator isNot(BaseModelQueriable baseModelQueriable) { + public Operator isNot(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.NOT_EQUALS); } @NonNull @Override - public Operator notEq(BaseModelQueriable baseModelQueriable) { + public Operator notEq(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.NOT_EQUALS); } @NonNull @Override - public Operator like(BaseModelQueriable baseModelQueriable) { + public Operator like(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.LIKE); } @NonNull @Override - public Operator notLike(IConditional conditional) { + public Operator notLike(@NonNull IConditional conditional) { return assignValueOp(conditional, Operation.NOT_LIKE); } @NonNull @Override - public Operator notLike(BaseModelQueriable baseModelQueriable) { + public Operator notLike(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.NOT_LIKE); } @NonNull @Override - public Operator glob(BaseModelQueriable baseModelQueriable) { + public Operator glob(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.GLOB); } @NonNull @Override - public Operator greaterThan(BaseModelQueriable baseModelQueriable) { + public Operator greaterThan(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.GREATER_THAN); } @NonNull @Override - public Operator greaterThanOrEq(BaseModelQueriable baseModelQueriable) { + public Operator greaterThanOrEq(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.GREATER_THAN_OR_EQUALS); } @NonNull @Override - public Operator lessThan(BaseModelQueriable baseModelQueriable) { + public Operator lessThan(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.LESS_THAN); } @NonNull @Override - public Operator lessThanOrEq(BaseModelQueriable baseModelQueriable) { + public Operator lessThanOrEq(@NonNull BaseModelQueriable baseModelQueriable) { return assignValueOp(baseModelQueriable, Operation.LESS_THAN_OR_EQUALS); } @@ -488,46 +488,46 @@ public Operator rem(IConditional value) { @NonNull @Override - public Operator plus(BaseModelQueriable value) { + public Operator plus(@NonNull BaseModelQueriable value) { return assignValueOp(value, Operation.PLUS); } @NonNull @Override - public Operator minus(BaseModelQueriable value) { + public Operator minus(@NonNull BaseModelQueriable value) { return assignValueOp(value, Operation.MINUS); } @NonNull @Override - public Operator div(BaseModelQueriable value) { + public Operator div(@NonNull BaseModelQueriable value) { return assignValueOp(value, Operation.DIVISION); } @NonNull @Override - public Operator times(BaseModelQueriable value) { + public Operator times(@NonNull BaseModelQueriable value) { return assignValueOp(value, Operation.MULTIPLY); } @NonNull @Override - public Operator rem(BaseModelQueriable value) { + public Operator rem(@NonNull BaseModelQueriable value) { return assignValueOp(value, Operation.MOD); } @NonNull @SuppressWarnings("unchecked") @Override - public Between between(BaseModelQueriable baseModelQueriable) { + public Between between(@NonNull BaseModelQueriable baseModelQueriable) { return new Between(this, baseModelQueriable); } @NonNull @SuppressWarnings("unchecked") @Override - public In in(BaseModelQueriable firstBaseModelQueriable, BaseModelQueriable... baseModelQueriables) { - return new In(this, firstBaseModelQueriable, true, (Object[]) baseModelQueriables); + public In in(@NonNull BaseModelQueriable firstBaseModelQueriable, @NonNull BaseModelQueriable... baseModelQueriables) { + return new In(this, firstBaseModelQueriable, true, baseModelQueriables); } @Override @@ -566,7 +566,7 @@ public Operator concatenate(Object value) { @NonNull @Override - public Operator concatenate(IConditional conditional) { + public Operator concatenate(@NonNull IConditional conditional) { return concatenate((Object) conditional); } @@ -578,33 +578,33 @@ public Operator concatenate(IConditional conditional) { */ @NonNull @Override - public Between between(T value) { + public Between between(@NonNull T value) { return new Between<>(this, value); } @NonNull @SafeVarargs @Override - public final In in(T firstArgument, T... arguments) { + public final In in(@NonNull T firstArgument, T... arguments) { return new In<>(this, firstArgument, true, arguments); } @NonNull @SafeVarargs @Override - public final In notIn(T firstArgument, T... arguments) { + public final In notIn(@NonNull T firstArgument, T... arguments) { return new In<>(this, firstArgument, false, arguments); } @NonNull @Override - public In in(Collection values) { + public In in(@NonNull Collection values) { return new In<>(this, values, true); } @NonNull @Override - public In notIn(Collection values) { + public In notIn(@NonNull Collection values) { return new In<>(this, values, false); } @@ -790,7 +790,7 @@ public T secondValue() { } @Override - public void appendConditionToQuery(QueryBuilder queryBuilder) { + public void appendConditionToQuery(@NonNull QueryBuilder queryBuilder) { queryBuilder.append(columnName()).append(operation()) .append(convertObjectToString(value(), true)) .appendSpaceSeparated(Operation.AND) @@ -850,7 +850,7 @@ public In and(@Nullable T argument) { } @Override - public void appendConditionToQuery(QueryBuilder queryBuilder) { + public void appendConditionToQuery(@NonNull QueryBuilder queryBuilder) { queryBuilder.append(columnName()).append(operation()) .append("(").append(OperatorGroup.joinArguments(",", inArguments, this)).append(")"); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/OperatorGroup.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/OperatorGroup.java index 7457c105c..11280ecf2 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/OperatorGroup.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/OperatorGroup.java @@ -175,7 +175,7 @@ private OperatorGroup operator(String operator, @Nullable SQLOperator sqlOperato } @Override - public void appendConditionToQuery(QueryBuilder queryBuilder) { + public void appendConditionToQuery(@NonNull QueryBuilder queryBuilder) { int conditionListSize = conditionsList.size(); if (useParenthesis && conditionListSize > 0) { queryBuilder.append("("); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/OrderBy.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/OrderBy.java index 0a64626a3..6b21c0f1a 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/OrderBy.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/OrderBy.java @@ -23,17 +23,17 @@ public class OrderBy implements Query { private String orderByString; @NonNull - public static OrderBy fromProperty(IProperty property) { + public static OrderBy fromProperty(@NonNull IProperty property) { return new OrderBy(property.getNameAlias()); } @NonNull - public static OrderBy fromNameAlias(NameAlias nameAlias) { + public static OrderBy fromNameAlias(@NonNull NameAlias nameAlias) { return new OrderBy(nameAlias); } @NonNull - public static OrderBy fromString(String orderByString) { + public static OrderBy fromString(@NonNull String orderByString) { return new OrderBy(orderByString); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/SQLOperator.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/SQLOperator.java index 8742e389f..22fb92b5b 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/SQLOperator.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/SQLOperator.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.language; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.QueryBuilder; @@ -14,13 +15,14 @@ public interface SQLOperator { * * @param queryBuilder The builder to append to. */ - void appendConditionToQuery(QueryBuilder queryBuilder); + void appendConditionToQuery(@NonNull QueryBuilder queryBuilder); /** * The name of the column. * * @return The column name. */ + @NonNull String columnName(); /** @@ -28,6 +30,7 @@ public interface SQLOperator { * * @return The separator, an AND, OR, or other kinds. */ + @Nullable String separator(); /** @@ -37,7 +40,7 @@ public interface SQLOperator { * @return This instance. */ @NonNull - SQLOperator separator(String separator); + SQLOperator separator(@NonNull String separator); /** * @return true if it has a separator, false if not. @@ -47,11 +50,13 @@ public interface SQLOperator { /** * @return the operation that is used. */ + @NonNull String operation(); /** * @return The raw value of the condition. */ + @Nullable Object value(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/SQLite.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/SQLite.java index dd5917449..e0be50892 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/SQLite.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/SQLite.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.language; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.language.property.IProperty; import com.raizlabs.android.dbflow.sql.language.property.Property; @@ -38,7 +39,7 @@ public static Select selectCountOf(IProperty... properties) { * @return A new UPDATE statement. */ @NonNull - public static Update update(Class table) { + public static Update update(@NonNull Class table) { return new Update<>(table); } @@ -48,7 +49,7 @@ public static Update update(Class table) { * @return A new INSERT statement. */ @NonNull - public static Insert insert(Class table) { + public static Insert insert(@NonNull Class table) { return new Insert<>(table); } @@ -68,7 +69,7 @@ public static Delete delete() { * @return A {@link From} with specified DELETE on table. */ @NonNull - public static From delete(Class table) { + public static From delete(@NonNull Class table) { return delete().from(table); } @@ -80,7 +81,7 @@ public static From delete(Class table) { * @return A new INDEX statement. */ @NonNull - public static Index index(String name) { + public static Index index(@NonNull String name) { return new Index<>(name); } @@ -91,7 +92,7 @@ public static Index index(String name) { * @return A new TRIGGER statement. */ @NonNull - public static Trigger createTrigger(String name) { + public static Trigger createTrigger(@NonNull String name) { return Trigger.create(name); } @@ -113,7 +114,7 @@ public static CaseCondition caseWhen(@NonNull SQLOperator ope * @param caseColumn The value */ @NonNull - public static Case _case(Property caseColumn) { + public static Case _case(@NonNull Property caseColumn) { return new Case<>(caseColumn); } @@ -124,7 +125,7 @@ public static Case _case(Property caseColumn) { * @param caseColumn The value */ @NonNull - public static Case _case(IProperty caseColumn) { + public static Case _case(@NonNull IProperty caseColumn) { return new Case<>(caseColumn); } } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Select.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Select.java index 2dddc4428..76986122b 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Select.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Select.java @@ -56,7 +56,7 @@ public Select(IProperty... properties) { * @return the From part of this query */ @NonNull - public From from(Class table) { + public From from(@NonNull Class table) { return new From<>(this, table); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Set.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Set.java index de2970351..f685e0959 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Set.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Set.java @@ -17,7 +17,7 @@ public class Set extends BaseTransformable implements WhereBase< private Query update; - public Set(Query update, Class table) { + public Set(@NonNull Query update, @NonNull Class table) { super(table); this.update = update; operatorGroup = OperatorGroup.nonGroupingClause().setAllCommaSeparated(true); @@ -36,7 +36,7 @@ public Set conditions(SQLOperator... conditions) { } @NonNull - public Set conditionValues(ContentValues contentValues) { + public Set conditionValues(@NonNull ContentValues contentValues) { SqlUtils.addContentValues(contentValues, operatorGroup); return this; } @@ -56,6 +56,7 @@ public Query getQueryBuilderBase() { return update; } + @NonNull @Override public BaseModel.Action getPrimaryAction() { return BaseModel.Action.UPDATE; diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Transformable.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Transformable.java index d2145b95d..298e411b1 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Transformable.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Transformable.java @@ -19,13 +19,13 @@ public interface Transformable { Where groupBy(IProperty... properties); @NonNull - Where orderBy(NameAlias nameAlias, boolean ascending); + Where orderBy(@NonNull NameAlias nameAlias, boolean ascending); @NonNull - Where orderBy(IProperty property, boolean ascending); + Where orderBy(@NonNull IProperty property, boolean ascending); @NonNull - Where orderBy(OrderBy orderBy); + Where orderBy(@NonNull OrderBy orderBy); @NonNull Where limit(int count); @@ -37,5 +37,5 @@ public interface Transformable { Where having(SQLOperator... conditions); @NonNull - Where orderByAll(List orderBies); + Where orderByAll(@NonNull List orderBies); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Trigger.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Trigger.java index e9b929c75..f264fddcf 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Trigger.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Trigger.java @@ -43,7 +43,7 @@ public class Trigger implements Query { * @return A new trigger. */ @NonNull - public static Trigger create(String triggerName) { + public static Trigger create(@NonNull String triggerName) { return new Trigger(triggerName); } @@ -53,7 +53,7 @@ public static Trigger create(String triggerName) { * * @param triggerName What we should call this trigger */ - private Trigger(String triggerName) { + private Trigger(@NonNull String triggerName) { this.triggerName = triggerName; } @@ -99,7 +99,7 @@ public Trigger insteadOf() { * @param onTable The table ON */ @NonNull - public TriggerMethod deleteOn(Class onTable) { + public TriggerMethod deleteOn(@NonNull Class onTable) { return new TriggerMethod<>(this, TriggerMethod.DELETE, onTable); } @@ -109,7 +109,7 @@ public TriggerMethod deleteOn(Class onTable) { * @param onTable The table ON */ @NonNull - public TriggerMethod insertOn(Class onTable) { + public TriggerMethod insertOn(@NonNull Class onTable) { return new TriggerMethod<>(this, TriggerMethod.INSERT, onTable); } @@ -121,13 +121,14 @@ public TriggerMethod insertOn(Class onTable) { * the UPDATE OF column1, column2,... will be used. */ @NonNull - public TriggerMethod updateOn(Class onTable, IProperty... properties) { + public TriggerMethod updateOn(@NonNull Class onTable, IProperty... properties) { return new TriggerMethod<>(this, TriggerMethod.UPDATE, onTable, properties); } /** * @return The name of this TRIGGER */ + @NonNull public String getName() { return triggerName; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/TriggerMethod.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/TriggerMethod.java index 35cf2ff85..270045074 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/TriggerMethod.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/TriggerMethod.java @@ -52,7 +52,7 @@ public TriggerMethod forEachRow() { * @return */ @NonNull - public TriggerMethod when(SQLOperator condition) { + public TriggerMethod when(@NonNull SQLOperator condition) { whenCondition = condition; return this; } @@ -66,7 +66,7 @@ public TriggerMethod when(SQLOperator condition) { * @return This trigger */ @NonNull - public CompletedTrigger begin(Query triggerLogicQuery) { + public CompletedTrigger begin(@NonNull Query triggerLogicQuery) { return new CompletedTrigger<>(this, triggerLogicQuery); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/UnSafeStringOperator.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/UnSafeStringOperator.java index 94b52c741..f9d225000 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/UnSafeStringOperator.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/UnSafeStringOperator.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.language; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.StringUtils; import com.raizlabs.android.dbflow.sql.Query; @@ -27,15 +28,17 @@ public UnSafeStringOperator(String selection, String[] selectionArgs) { } @Override - public void appendConditionToQuery(QueryBuilder queryBuilder) { + public void appendConditionToQuery(@NonNull QueryBuilder queryBuilder) { queryBuilder.append(conditionString); } + @NonNull @Override public String columnName() { return ""; } + @Nullable @Override public String separator() { return separator; @@ -43,7 +46,7 @@ public String separator() { @NonNull @Override - public SQLOperator separator(String separator) { + public SQLOperator separator(@NonNull String separator) { this.separator = separator; return this; } @@ -53,6 +56,7 @@ public boolean hasSeparator() { return StringUtils.isNotNullOrEmpty(separator); } + @NonNull @Override public String operation() { return ""; diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Update.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Update.java index 3ed5b56f8..ea1764d3e 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Update.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Update.java @@ -29,13 +29,13 @@ public Update(Class table) { } @NonNull - public Update conflictAction(ConflictAction conflictAction) { + public Update conflictAction(@NonNull ConflictAction conflictAction) { this.conflictAction = conflictAction; return this; } @NonNull - public Update or(ConflictAction conflictAction) { + public Update or(@NonNull ConflictAction conflictAction) { return conflictAction(conflictAction); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Where.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Where.java index 5fd3d11fd..6c73082f4 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Where.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Where.java @@ -52,7 +52,7 @@ public class Where extends BaseModelQueriable implements ModelQu * * @param whereBase The FROM or SET statement chunk */ - public Where(WhereBase whereBase, SQLOperator... conditions) { + public Where(@NonNull WhereBase whereBase, SQLOperator... conditions) { super(whereBase.getTable()); this.whereBase = whereBase; operatorGroup = OperatorGroup.nonGroupingClause(); @@ -65,7 +65,7 @@ public Where(WhereBase whereBase, SQLOperator... conditions) { * Joins the {@link SQLOperator} by the prefix of "AND" (unless its the first condition). */ @NonNull - public Where and(SQLOperator condition) { + public Where and(@NonNull SQLOperator condition) { operatorGroup.and(condition); return this; } @@ -74,7 +74,7 @@ public Where and(SQLOperator condition) { * Joins the {@link SQLOperator} by the prefix of "OR" (unless its the first condition). */ @NonNull - public Where or(SQLOperator condition) { + public Where or(@NonNull SQLOperator condition) { operatorGroup.or(condition); return this; } @@ -83,7 +83,7 @@ public Where or(SQLOperator condition) { * Joins all of the {@link SQLOperator} by the prefix of "AND" (unless its the first condition). */ @NonNull - public Where andAll(List conditions) { + public Where andAll(@NonNull List conditions) { operatorGroup.andAll(conditions); return this; } @@ -124,19 +124,19 @@ public Where having(SQLOperator... conditions) { } @NonNull - public Where orderBy(NameAlias nameAlias, boolean ascending) { + public Where orderBy(@NonNull NameAlias nameAlias, boolean ascending) { orderByList.add(new OrderBy(nameAlias, ascending)); return this; } @NonNull - public Where orderBy(IProperty property, boolean ascending) { + public Where orderBy(@NonNull IProperty property, boolean ascending) { orderByList.add(new OrderBy(property.getNameAlias(), ascending)); return this; } @NonNull - public Where orderBy(OrderBy orderBy) { + public Where orderBy(@NonNull OrderBy orderBy) { orderByList.add(orderBy); return this; } @@ -148,10 +148,8 @@ public Where orderBy(OrderBy orderBy) { * @return this instance. */ @NonNull - public Where orderByAll(List orderBies) { - if (orderBies != null) { - orderByList.addAll(orderBies); - } + public Where orderByAll(@NonNull List orderBies) { + orderByList.addAll(orderBies); return this; } @@ -180,6 +178,7 @@ public Where exists(@NonNull Where where) { return this; } + @NonNull @Override public BaseModel.Action getPrimaryAction() { return whereBase.getPrimaryAction(); @@ -208,7 +207,7 @@ public String getQuery() { * @return the result of the query as a {@link Cursor}. */ @Override - public FlowCursor query(DatabaseWrapper wrapper) { + public FlowCursor query(@NonNull DatabaseWrapper wrapper) { // Query the sql here FlowCursor cursor; if (whereBase.getQueryBuilderBase() instanceof Select) { @@ -250,6 +249,7 @@ public TModel querySingle() { return super.querySingle(); } + @NonNull public WhereBase getWhereBase() { return whereBase; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/IProperty.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/IProperty.java index 94e417a31..7ffc60677 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/IProperty.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/IProperty.java @@ -19,7 +19,7 @@ public interface IProperty

extends Query { * @return A new {@link P} that expresses the current column name with the specified Alias name. */ @NonNull - P as(String aliasName); + P as(@NonNull String aliasName); /** * Adds another property and returns as a new property. i.e p1 + p2 @@ -28,7 +28,7 @@ public interface IProperty

extends Query { * @return A new instance. */ @NonNull - P plus(IProperty iProperty); + P plus(@NonNull IProperty iProperty); /** * Subtracts another property and returns as a new property. i.e p1 - p2 @@ -37,7 +37,7 @@ public interface IProperty

extends Query { * @return A new instance. */ @NonNull - P minus(IProperty iProperty); + P minus(@NonNull IProperty iProperty); /** * Divides another property and returns as a new property. i.e p1 / p2 @@ -46,7 +46,7 @@ public interface IProperty

extends Query { * @return A new instance. */ @NonNull - P div(IProperty iProperty); + P div(@NonNull IProperty iProperty); /** * Multiplies another property and returns as a new property. i.e p1 * p2 @@ -54,7 +54,7 @@ public interface IProperty

extends Query { * @param iProperty the property to multiply. * @return A new instance. */ - P times(IProperty iProperty); + P times(@NonNull IProperty iProperty); /** * Modulous another property and returns as a new property. i.e p1 % p2 @@ -63,7 +63,7 @@ public interface IProperty

extends Query { * @return A new instance. */ @NonNull - P rem(IProperty iProperty); + P rem(@NonNull IProperty iProperty); /** * Concats another property and returns as a new propert.y i.e. p1 || p2 @@ -72,7 +72,7 @@ public interface IProperty

extends Query { * @return A new instance. */ @NonNull - P concatenate(IProperty iProperty); + P concatenate(@NonNull IProperty iProperty); /** * @return Appends DISTINCT to the property name. This is handy in {@link Method} queries. @@ -99,7 +99,7 @@ public interface IProperty

extends Query { * The resulting column name becomes `tableName`.`columnName`. */ @NonNull - P withTable(NameAlias tableNameAlias); + P withTable(@NonNull NameAlias tableNameAlias); /** * @return The underlying {@link NameAlias} that represents the name of this property. diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/IndexProperty.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/IndexProperty.java index a9dcdf680..dcb2d5061 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/IndexProperty.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/IndexProperty.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.sql.language.property; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.annotation.Table; import com.raizlabs.android.dbflow.sql.QueryBuilder; import com.raizlabs.android.dbflow.sql.language.Index; @@ -21,7 +23,7 @@ public IndexProperty(String indexName, boolean unique, Class table, IProperty .unique(unique); } - public void createIfNotExists(DatabaseWrapper wrapper) { + public void createIfNotExists(@NonNull DatabaseWrapper wrapper) { index.enable(wrapper); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/Property.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/Property.java index 6faab5a00..75543ffc5 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/Property.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/Property.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.language.property; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.FlowManager; import com.raizlabs.android.dbflow.sql.language.BaseModelQueriable; @@ -37,22 +38,24 @@ public String toString() { public static final Property WILDCARD = new Property(null, NameAlias.rawBuilder("?").build()); + @Nullable final Class table; + protected NameAlias nameAlias; - public Property(Class table, NameAlias nameAlias) { + public Property(@Nullable Class table, @NonNull NameAlias nameAlias) { this.table = table; this.nameAlias = nameAlias; } - public Property(Class table, String columnName) { + public Property(@Nullable Class table, @Nullable String columnName) { this.table = table; if (columnName != null) { nameAlias = new NameAlias.Builder(columnName).build(); } } - public Property(Class table, String columnName, String aliasName) { + public Property(@Nullable Class table, @NonNull String columnName, @NonNull String aliasName) { this(table, NameAlias.builder(columnName).as(aliasName).build()); } @@ -79,6 +82,7 @@ public String getCursorKey() { return getNameAlias().getQuery(); } + @NonNull public String getDefinition() { return getNameAlias().getFullQuery(); } @@ -90,103 +94,103 @@ public String toString() { @NonNull @Override - public Operator is(IConditional conditional) { + public Operator is(@NonNull IConditional conditional) { return getCondition().is(conditional); } @NonNull @Override - public Operator eq(IConditional conditional) { + public Operator eq(@NonNull IConditional conditional) { return getCondition().eq(conditional); } @NonNull @Override - public Operator isNot(IConditional conditional) { + public Operator isNot(@NonNull IConditional conditional) { return getCondition().isNot(conditional); } @NonNull @Override - public Operator notEq(IConditional conditional) { + public Operator notEq(@NonNull IConditional conditional) { return getCondition().notEq(conditional); } @NonNull @Override - public Operator like(IConditional conditional) { + public Operator like(@NonNull IConditional conditional) { return getCondition().like(conditional); } @NonNull @Override - public Operator glob(IConditional conditional) { + public Operator glob(@NonNull IConditional conditional) { return getCondition().glob(conditional); } @NonNull @Override - public Operator like(String value) { + public Operator like(@NonNull String value) { return getCondition().like(value); } @NonNull @Override - public Operator notLike(String value) { + public Operator notLike(@NonNull String value) { return getCondition().notLike(value); } @NonNull @Override - public Operator glob(String value) { + public Operator glob(@NonNull String value) { return getCondition().glob(value); } @NonNull @Override - public Operator greaterThan(IConditional conditional) { + public Operator greaterThan(@NonNull IConditional conditional) { return getCondition().greaterThan(conditional); } @NonNull @Override - public Operator greaterThanOrEq(IConditional conditional) { + public Operator greaterThanOrEq(@NonNull IConditional conditional) { return getCondition().greaterThanOrEq(conditional); } @NonNull @Override - public Operator lessThan(IConditional conditional) { + public Operator lessThan(@NonNull IConditional conditional) { return getCondition().lessThan(conditional); } @NonNull @Override - public Operator lessThanOrEq(IConditional conditional) { + public Operator lessThanOrEq(@NonNull IConditional conditional) { return getCondition().lessThanOrEq(conditional); } @NonNull @Override - public Operator.Between between(IConditional conditional) { + public Operator.Between between(@NonNull IConditional conditional) { return getCondition().between(conditional); } @NonNull @Override - public Operator.In in(IConditional firstConditional, IConditional... conditionals) { + public Operator.In in(@NonNull IConditional firstConditional, @NonNull IConditional... conditionals) { return getCondition().in(firstConditional, conditionals); } @NonNull @Override - public Operator.In notIn(IConditional firstConditional, IConditional... conditionals) { + public Operator.In notIn(@NonNull IConditional firstConditional, @NonNull IConditional... conditionals) { return getCondition().notIn(firstConditional, conditionals); } @NonNull @Override - public Operator is(BaseModelQueriable baseModelQueriable) { + public Operator is(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().is(baseModelQueriable); } @@ -198,13 +202,13 @@ public Operator isNull() { @NonNull @Override - public Operator eq(BaseModelQueriable baseModelQueriable) { + public Operator eq(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().eq(baseModelQueriable); } @NonNull @Override - public Operator isNot(BaseModelQueriable baseModelQueriable) { + public Operator isNot(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().isNot(baseModelQueriable); } @@ -216,109 +220,109 @@ public Operator isNotNull() { @NonNull @Override - public Operator notEq(BaseModelQueriable baseModelQueriable) { + public Operator notEq(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().notEq(baseModelQueriable); } @NonNull @Override - public Operator like(BaseModelQueriable baseModelQueriable) { + public Operator like(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().like(baseModelQueriable); } @NonNull @Override - public Operator notLike(IConditional conditional) { + public Operator notLike(@NonNull IConditional conditional) { return getCondition().notLike(conditional); } @NonNull @Override - public Operator notLike(BaseModelQueriable baseModelQueriable) { + public Operator notLike(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().notLike(baseModelQueriable); } @NonNull @Override - public Operator glob(BaseModelQueriable baseModelQueriable) { + public Operator glob(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().glob(baseModelQueriable); } @NonNull @Override - public Operator greaterThan(BaseModelQueriable baseModelQueriable) { + public Operator greaterThan(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().greaterThan(baseModelQueriable); } @NonNull @Override - public Operator greaterThanOrEq(BaseModelQueriable baseModelQueriable) { + public Operator greaterThanOrEq(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().greaterThanOrEq(baseModelQueriable); } @NonNull @Override - public Operator lessThan(BaseModelQueriable baseModelQueriable) { + public Operator lessThan(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().lessThan(baseModelQueriable); } @NonNull @Override - public Operator lessThanOrEq(BaseModelQueriable baseModelQueriable) { + public Operator lessThanOrEq(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().lessThanOrEq(baseModelQueriable); } @NonNull @Override - public Operator.Between between(BaseModelQueriable baseModelQueriable) { + public Operator.Between between(@NonNull BaseModelQueriable baseModelQueriable) { return getCondition().between(baseModelQueriable); } @NonNull @Override - public Operator.In in(BaseModelQueriable firstBaseModelQueriable, BaseModelQueriable... baseModelQueriables) { + public Operator.In in(@NonNull BaseModelQueriable firstBaseModelQueriable, @NonNull BaseModelQueriable... baseModelQueriables) { return getCondition().in(firstBaseModelQueriable, baseModelQueriables); } @NonNull @Override - public Operator.In notIn(BaseModelQueriable firstBaseModelQueriable, BaseModelQueriable... baseModelQueriables) { + public Operator.In notIn(@NonNull BaseModelQueriable firstBaseModelQueriable, @NonNull BaseModelQueriable... baseModelQueriables) { return getCondition().notIn(firstBaseModelQueriable, baseModelQueriables); } @NonNull @Override - public Operator concatenate(IConditional conditional) { + public Operator concatenate(@NonNull IConditional conditional) { return getCondition().concatenate(conditional); } @NonNull @Override - public Operator plus(BaseModelQueriable value) { + public Operator plus(@NonNull BaseModelQueriable value) { return getCondition().plus(value); } @NonNull @Override - public Operator minus(BaseModelQueriable value) { + public Operator minus(@NonNull BaseModelQueriable value) { return getCondition().minus(value); } @NonNull @Override - public Operator div(BaseModelQueriable value) { + public Operator div(@NonNull BaseModelQueriable value) { return getCondition().div(value); } @NonNull @Override - public Operator times(BaseModelQueriable value) { + public Operator times(@NonNull BaseModelQueriable value) { return getCondition().times(value); } @NonNull @Override - public Operator rem(BaseModelQueriable value) { + public Operator rem(@NonNull BaseModelQueriable value) { return getCondition().rem(value); } @@ -330,48 +334,48 @@ public Class getTable() { @NonNull @Override - public Property plus(IProperty iProperty) { + public Property plus(@NonNull IProperty iProperty) { return new Property<>(table, NameAlias.joinNames(Operator.Operation.PLUS, nameAlias.fullName(), iProperty.toString())); } @NonNull @Override - public Property minus(IProperty iProperty) { + public Property minus(@NonNull IProperty iProperty) { return new Property<>(table, NameAlias.joinNames(Operator.Operation.MINUS, nameAlias.fullName(), iProperty.toString())); } @NonNull @Override - public Property div(IProperty iProperty) { + public Property div(@NonNull IProperty iProperty) { return new Property<>(table, NameAlias.joinNames(Operator.Operation.DIVISION, nameAlias.fullName(), iProperty.toString())); } @Override - public Property times(IProperty iProperty) { + public Property times(@NonNull IProperty iProperty) { return new Property<>(table, NameAlias.joinNames(Operator.Operation.MULTIPLY, nameAlias.fullName(), iProperty.toString())); } @NonNull @Override - public Property rem(IProperty iProperty) { + public Property rem(@NonNull IProperty iProperty) { return new Property<>(table, NameAlias.joinNames(Operator.Operation.MOD, nameAlias.fullName(), iProperty.toString())); } @NonNull @Override - public Property concatenate(IProperty iProperty) { + public Property concatenate(@NonNull IProperty iProperty) { return new Property<>(table, NameAlias.joinNames(Operator.Operation.CONCATENATE, nameAlias.fullName(), iProperty.toString())); } @NonNull @Override - public Property as(String aliasName) { + public Property as(@NonNull String aliasName) { return new Property<>(table, getNameAlias() .newBuilder() .as(aliasName) @@ -386,7 +390,7 @@ public Property distinct() { @NonNull @Override - public Property withTable(NameAlias tableNameAlias) { + public Property withTable(@NonNull NameAlias tableNameAlias) { return new Property<>(table, getNameAlias() .newBuilder() .withTable(tableNameAlias.getQuery()) @@ -419,57 +423,57 @@ public Operator notEq(T value) { @NonNull @Override - public Operator greaterThan(T value) { + public Operator greaterThan(@NonNull T value) { return getCondition().greaterThan(value); } @NonNull @Override - public Operator greaterThanOrEq(T value) { + public Operator greaterThanOrEq(@NonNull T value) { return getCondition().greaterThanOrEq(value); } @NonNull @Override - public Operator lessThan(T value) { + public Operator lessThan(@NonNull T value) { return getCondition().lessThan(value); } @NonNull @Override - public Operator lessThanOrEq(T value) { + public Operator lessThanOrEq(@NonNull T value) { return getCondition().lessThanOrEq(value); } @NonNull @Override - public Operator.Between between(T value) { + public Operator.Between between(@NonNull T value) { return getCondition().between(value); } @NonNull @SuppressWarnings({"ConfusingArgumentToVarargsMethod", "unchecked"}) @Override - public Operator.In in(T firstValue, T... values) { + public Operator.In in(@NonNull T firstValue, T... values) { return getCondition().in(firstValue, values); } @NonNull @SuppressWarnings({"ConfusingArgumentToVarargsMethod", "unchecked"}) @Override - public Operator.In notIn(T firstValue, T... values) { + public Operator.In notIn(@NonNull T firstValue, T... values) { return getCondition().notIn(firstValue, values); } @NonNull @Override - public Operator.In in(Collection values) { + public Operator.In in(@NonNull Collection values) { return getCondition().in(values); } @NonNull @Override - public Operator.In notIn(Collection values) { + public Operator.In notIn(@NonNull Collection values) { return getCondition().notIn(values); } @@ -481,30 +485,30 @@ public Operator concatenate(T value) { @NonNull @Override - public Operator plus(T value) { + public Operator plus(@NonNull T value) { return getCondition().plus(value); } @NonNull @Override - public Operator minus(T value) { + public Operator minus(@NonNull T value) { return getCondition().minus(value); } @NonNull @Override - public Operator div(T value) { + public Operator div(@NonNull T value) { return getCondition().div(value); } @Override - public Operator times(T value) { + public Operator times(@NonNull T value) { return getCondition().times(value); } @NonNull @Override - public Operator rem(T value) { + public Operator rem(@NonNull T value) { return getCondition().rem(value); } @@ -531,6 +535,7 @@ protected NameAlias getDistinctAliasName() { .build(); } + @NonNull protected Operator getCondition() { return op(getNameAlias()); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/PropertyFactory.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/PropertyFactory.java index 87a7e5d51..6b6457b5d 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/PropertyFactory.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/PropertyFactory.java @@ -135,7 +135,7 @@ public static Property from(@NonNull ModelQueriable que * @return A new property with its type. */ @NonNull - public static Property from(@Nullable Class type, String stringRepresentation) { + public static Property from(@Nullable Class type, @Nullable String stringRepresentation) { return new Property<>(null, NameAlias.rawBuilder(stringRepresentation) .build()); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/TypeConvertedProperty.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/TypeConvertedProperty.java index ca5fb13ff..2d2255129 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/TypeConvertedProperty.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/TypeConvertedProperty.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.sql.language.property; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.converter.TypeConverter; import com.raizlabs.android.dbflow.sql.language.NameAlias; import com.raizlabs.android.dbflow.sql.language.Operator; @@ -46,6 +48,7 @@ public TypeConvertedProperty(Class table, String columnName, this.getter = getter; } + @NonNull @Override protected Operator getCondition() { return op(getNameAlias(), getter.getTypeConverter(table), convertToDB); @@ -55,6 +58,7 @@ protected Operator getCondition() { * @return A new {@link Property} that corresponds to the inverted type of the {@link TypeConvertedProperty}. * Provides a convenience for supplying type converted methods within the DataClass of the {@link TypeConverter} */ + @NonNull public Property invertProperty() { if (databaseProperty == null) { databaseProperty = new TypeConvertedProperty<>(table, nameAlias, diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/WrapperProperty.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/WrapperProperty.java index fe3a39781..e7e3dba35 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/WrapperProperty.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/property/WrapperProperty.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.sql.language.property; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.sql.language.NameAlias; /** @@ -11,11 +13,11 @@ public class WrapperProperty extends Property { private WrapperProperty databaseProperty; - public WrapperProperty(Class table, NameAlias nameAlias) { + public WrapperProperty(@NonNull Class table, @NonNull NameAlias nameAlias) { super(table, nameAlias); } - public WrapperProperty(Class table, String columnName) { + public WrapperProperty(@NonNull Class table, @NonNull String columnName) { super(table, columnName); } @@ -23,6 +25,8 @@ public WrapperProperty(Class table, String columnName) { * @return A new {@link Property} that corresponds to the inverted type of the {@link WrapperProperty}. Convenience * for types that have different DB representations. */ + @SuppressWarnings("ConstantConditions") + @NonNull public Property invertProperty() { if (databaseProperty == null) { databaseProperty = new WrapperProperty<>(table, nameAlias); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/AlterTableMigration.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/AlterTableMigration.java index f0d4fe0d8..75d17f6de 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/AlterTableMigration.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/AlterTableMigration.java @@ -50,7 +50,7 @@ public AlterTableMigration(Class table) { } @Override - public final void migrate(DatabaseWrapper database) { + public final void migrate(@NonNull DatabaseWrapper database) { // "ALTER TABLE " String sql = getAlterTableQueryBuilder().getQuery(); String tableName = FlowManager.getTableName(table); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/BaseMigration.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/BaseMigration.java index 1da10d628..d2a6ff687 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/BaseMigration.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/BaseMigration.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.sql.migration; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; /** @@ -15,7 +17,7 @@ public void onPreMigrate() { } @Override - public abstract void migrate(DatabaseWrapper database); + public abstract void migrate(@NonNull DatabaseWrapper database); @Override public void onPostMigrate() { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/IndexMigration.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/IndexMigration.java index 5a0f5f7a1..4a97b6632 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/IndexMigration.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/IndexMigration.java @@ -41,7 +41,7 @@ public void onPreMigrate() { } @Override - public final void migrate(DatabaseWrapper database) { + public final void migrate(@NonNull DatabaseWrapper database) { database.execSQL(getIndex().getQuery()); } @@ -59,6 +59,7 @@ public void onPostMigrate() { * @param property The name of the column to add to the Index * @return This migration */ + @NonNull public IndexMigration addColumn(IProperty property) { getIndex().and(property); return this; @@ -69,6 +70,7 @@ public IndexMigration addColumn(IProperty property) { * * @return This migration. */ + @NonNull public IndexMigration unique() { getIndex().unique(true); return this; @@ -77,6 +79,7 @@ public IndexMigration unique() { /** * @return The index object based on the contents of this migration. */ + @NonNull public Index getIndex() { if (index == null) { index = new Index(name).on(onTable); @@ -87,6 +90,7 @@ public Index getIndex() { /** * @return the query backing this migration. */ + @NonNull public String getIndexQuery() { return getIndex().getQuery(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/IndexPropertyMigration.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/IndexPropertyMigration.java index 20ac33428..6a7a7ab68 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/IndexPropertyMigration.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/IndexPropertyMigration.java @@ -21,7 +21,7 @@ public boolean shouldCreate() { } @Override - public void migrate(DatabaseWrapper database) { + public void migrate(@NonNull DatabaseWrapper database) { if (shouldCreate()) { getIndexProperty().createIfNotExists(database); } else { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/Migration.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/Migration.java index 2f6e4b4d8..3b4980d0a 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/Migration.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/Migration.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.sql.migration; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; /** @@ -18,7 +20,7 @@ public interface Migration { * * @param database The database to operate on */ - void migrate(DatabaseWrapper database); + void migrate(@NonNull DatabaseWrapper database); /** * Called after the migration completes. Release migration data here. diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/UpdateTableMigration.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/UpdateTableMigration.java index 6aa328552..5d4824444 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/UpdateTableMigration.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/migration/UpdateTableMigration.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.migration; import android.support.annotation.CallSuper; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.language.BaseQueriable; @@ -38,7 +39,7 @@ public class UpdateTableMigration extends BaseMigration { * * @param table The table to update */ - public UpdateTableMigration(Class table) { + public UpdateTableMigration(@NonNull Class table) { this.table = table; } @@ -48,6 +49,7 @@ public UpdateTableMigration(Class table) { * * @param conditions The conditions to append */ + @NonNull public UpdateTableMigration set(SQLOperator... conditions) { if (setOperatorGroup == null) { setOperatorGroup = OperatorGroup.nonGroupingClause(); @@ -57,6 +59,7 @@ public UpdateTableMigration set(SQLOperator... conditions) { return this; } + @NonNull public UpdateTableMigration where(SQLOperator... conditions) { if (whereOperatorGroup == null) { whereOperatorGroup = OperatorGroup.nonGroupingClause(); @@ -67,7 +70,7 @@ public UpdateTableMigration where(SQLOperator... conditions) { } @Override - public final void migrate(DatabaseWrapper database) { + public final void migrate(@NonNull DatabaseWrapper database) { getUpdateStatement().execute(database); } @@ -79,6 +82,7 @@ public void onPostMigrate() { whereOperatorGroup = null; } + @NonNull public BaseQueriable getUpdateStatement() { return SQLite.update(table) .set(setOperatorGroup) diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/AsyncQuery.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/AsyncQuery.java index 71f1c6669..b44cd8fd6 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/AsyncQuery.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/AsyncQuery.java @@ -4,6 +4,9 @@ import com.raizlabs.android.dbflow.sql.BaseAsyncObject; import com.raizlabs.android.dbflow.structure.database.transaction.QueryTransaction; +import com.raizlabs.android.dbflow.structure.database.transaction.QueryTransaction.QueryResultCallback; +import com.raizlabs.android.dbflow.structure.database.transaction.QueryTransaction.QueryResultListCallback; +import com.raizlabs.android.dbflow.structure.database.transaction.QueryTransaction.QueryResultSingleCallback; /** * Description: Adds async methods to a {@link ModelQueriable} @@ -11,9 +14,9 @@ public class AsyncQuery extends BaseAsyncObject> { private final ModelQueriable modelQueriable; - private QueryTransaction.QueryResultCallback queryResultCallback; - private QueryTransaction.QueryResultListCallback queryResultListCallback; - private QueryTransaction.QueryResultSingleCallback queryResultSingleCallback; + private QueryResultCallback queryResultCallback; + private QueryResultListCallback queryResultListCallback; + private QueryResultSingleCallback queryResultSingleCallback; /** * Constructs an instance of this async query. @@ -28,7 +31,7 @@ public AsyncQuery(@NonNull ModelQueriable queriable) { /** * @param queryResultCallback Called when query is executed and has a result. */ - public AsyncQuery queryResultCallback(QueryTransaction.QueryResultCallback queryResultCallback) { + public AsyncQuery queryResultCallback(@NonNull QueryResultCallback queryResultCallback) { this.queryResultCallback = queryResultCallback; return this; } @@ -36,7 +39,7 @@ public AsyncQuery queryResultCallback(QueryTransaction.QueryResultCallba /** * @param queryResultSingleCallback Called when query is executed and has a result. */ - public AsyncQuery querySingleResultCallback(QueryTransaction.QueryResultSingleCallback queryResultSingleCallback) { + public AsyncQuery querySingleResultCallback(@NonNull QueryResultSingleCallback queryResultSingleCallback) { this.queryResultSingleCallback = queryResultSingleCallback; return this; } @@ -44,7 +47,7 @@ public AsyncQuery querySingleResultCallback(QueryTransaction.QueryResult /** * @param queryResultListCallback Called when query is executed and has a result. */ - public AsyncQuery queryListResultCallback(QueryTransaction.QueryResultListCallback queryResultListCallback) { + public AsyncQuery queryListResultCallback(@NonNull QueryResultListCallback queryResultListCallback) { this.queryResultListCallback = queryResultListCallback; return this; } @@ -54,10 +57,10 @@ public AsyncQuery queryListResultCallback(QueryTransaction.QueryResultLi */ public void execute() { executeTransaction(new QueryTransaction.Builder<>(modelQueriable) - .queryResult(queryResultCallback) - .queryListResult(queryResultListCallback) - .querySingleResult(queryResultSingleCallback) - .build()); + .queryResult(queryResultCallback) + .queryListResult(queryResultListCallback) + .querySingleResult(queryResultSingleCallback) + .build()); } /** diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/CacheableListModelLoader.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/CacheableListModelLoader.java index 4c8c96a64..99a7c07f6 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/CacheableListModelLoader.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/CacheableListModelLoader.java @@ -19,10 +19,11 @@ public class CacheableListModelLoader extends ListModelLoader { private ModelAdapter modelAdapter; private ModelCache modelCache; - public CacheableListModelLoader(Class modelClass) { + public CacheableListModelLoader(@NonNull Class modelClass) { super(modelClass); } + @NonNull public ModelCache getModelCache() { if (modelCache == null) { modelCache = modelAdapter.getModelCache(); @@ -33,6 +34,7 @@ public CacheableListModelLoader(Class modelClass) { return modelCache; } + @NonNull @SuppressWarnings("unchecked") public ModelAdapter getModelAdapter() { if (modelAdapter == null) { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/CacheableModelLoader.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/CacheableModelLoader.java index b3716c4a7..cfe9744f8 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/CacheableModelLoader.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/CacheableModelLoader.java @@ -17,10 +17,11 @@ public class CacheableModelLoader extends SingleModelLoader { private ModelAdapter modelAdapter; private ModelCache modelCache; - public CacheableModelLoader(Class modelClass) { + public CacheableModelLoader(@NonNull Class modelClass) { super(modelClass); } + @NonNull @SuppressWarnings("unchecked") public ModelAdapter getModelAdapter() { if (modelAdapter == null) { @@ -36,6 +37,7 @@ public ModelAdapter getModelAdapter() { return modelAdapter; } + @NonNull public ModelCache getModelCache() { if (modelCache == null) { modelCache = getModelAdapter().getModelCache(); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ListModelLoader.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ListModelLoader.java index ea3bc4283..296bdacfc 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ListModelLoader.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ListModelLoader.java @@ -15,7 +15,7 @@ @SuppressWarnings("ConstantConditions") public class ListModelLoader extends ModelLoader> { - public ListModelLoader(Class modelClass) { + public ListModelLoader(@NonNull Class modelClass) { super(modelClass); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ModelLoader.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ModelLoader.java index 5aa6d0d95..3d79d59d2 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ModelLoader.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ModelLoader.java @@ -21,7 +21,7 @@ public abstract class ModelLoader { private DatabaseDefinition databaseDefinition; private InstanceAdapter instanceAdapter; - public ModelLoader(Class modelClass) { + public ModelLoader(@NonNull Class modelClass) { this.modelClass = modelClass; } @@ -32,12 +32,12 @@ public ModelLoader(Class modelClass) { * @return The data loaded from the database. */ @Nullable - public TReturn load(String query) { + public TReturn load(@NonNull String query) { return load(getDatabaseDefinition().getWritableDatabase(), query); } @Nullable - public TReturn load(String query, @Nullable TReturn data) { + public TReturn load(@NonNull String query, @Nullable TReturn data) { return load(getDatabaseDefinition().getWritableDatabase(), query, data); } @@ -49,12 +49,13 @@ public TReturn load(String query, @Nullable TReturn data) { * @return The data loaded from the database. */ @Nullable - public TReturn load(@NonNull DatabaseWrapper databaseWrapper, String query) { + public TReturn load(@NonNull DatabaseWrapper databaseWrapper, @NonNull String query) { return load(databaseWrapper, query, null); } @Nullable - public TReturn load(@NonNull DatabaseWrapper databaseWrapper, String query, @Nullable TReturn data) { + public TReturn load(@NonNull DatabaseWrapper databaseWrapper, @NonNull String query, + @Nullable TReturn data) { final FlowCursor cursor = databaseWrapper.rawQuery(query, null); return load(cursor, data); } @@ -76,6 +77,7 @@ public TReturn load(@Nullable FlowCursor cursor, @Nullable TReturn data) { return data; } + @NonNull public Class getModelClass() { return modelClass; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ModelQueriable.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ModelQueriable.java index acfffaa0f..e40edf87b 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ModelQueriable.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/ModelQueriable.java @@ -38,7 +38,7 @@ public interface ModelQueriable extends Queriable { * @return a list of model converted items */ @NonNull - List queryList(DatabaseWrapper wrapper); + List queryList(@NonNull DatabaseWrapper wrapper); /** * @return Single model, the first of potentially many results @@ -52,7 +52,7 @@ public interface ModelQueriable extends Queriable { * @return Single model, the first of potentially many results */ @Nullable - TModel querySingle(DatabaseWrapper wrapper); + TModel querySingle(@NonNull DatabaseWrapper wrapper); /** * @return the table that this query comes from. @@ -88,7 +88,7 @@ public interface ModelQueriable extends Queriable { * @return A list of custom models that are not tied to a table. */ @NonNull - List queryCustomList(Class queryModelClass); + List queryCustomList(@NonNull Class queryModelClass); /** * Returns a single {@link TQueryModel} from this query. @@ -98,7 +98,7 @@ public interface ModelQueriable extends Queriable { * @return A single model from the query. */ @Nullable - TQueryModel queryCustomSingle(Class queryModelClass); + TQueryModel queryCustomSingle(@NonNull Class queryModelClass); /** * Disables caching on this query for the object retrieved from DB (if caching enabled). If diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/Queriable.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/Queriable.java index ab6f79e1c..ba2003fa8 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/Queriable.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/Queriable.java @@ -1,5 +1,6 @@ package com.raizlabs.android.dbflow.sql.queriable; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.Query; @@ -31,19 +32,21 @@ public interface Queriable extends Query { * @return A cursor from the DB based on this query */ @Nullable - FlowCursor query(DatabaseWrapper databaseWrapper); + FlowCursor query(@NonNull DatabaseWrapper databaseWrapper); /** * @return A new {@link DatabaseStatement} from this query. */ + @NonNull DatabaseStatement compileStatement(); /** * @param databaseWrapper The wrapper to use. * @return A new {@link DatabaseStatement} from this query with database specified. */ - DatabaseStatement compileStatement(DatabaseWrapper databaseWrapper); + @NonNull + DatabaseStatement compileStatement(@NonNull DatabaseWrapper databaseWrapper); /** * @return the count of the results of the query. @@ -55,13 +58,13 @@ public interface Queriable extends Query { * * @return the count of the results of the query. */ - long count(DatabaseWrapper databaseWrapper); + long count(@NonNull DatabaseWrapper databaseWrapper); /** * @return This may return the number of rows affected from a {@link Set} or {@link Delete} statement. * If not, returns {@link Model#INVALID_ROW_ID} */ - long executeUpdateDelete(DatabaseWrapper databaseWrapper); + long executeUpdateDelete(@NonNull DatabaseWrapper databaseWrapper); /** * @return This may return the number of rows affected from a {@link Set} or {@link Delete} statement. @@ -79,7 +82,7 @@ public interface Queriable extends Query { * @return This may return the number of rows affected from a {@link Insert} statement. * If not, returns {@link Model#INVALID_ROW_ID} */ - long executeInsert(DatabaseWrapper databaseWrapper); + long executeInsert(@NonNull DatabaseWrapper databaseWrapper); /** * @return True if this query has data. It will run a {@link #count()} greater than 0. @@ -91,7 +94,7 @@ public interface Queriable extends Query { * * @return True if this query has data. It will run a {@link #count()} greater than 0. */ - boolean hasData(DatabaseWrapper databaseWrapper); + boolean hasData(@NonNull DatabaseWrapper databaseWrapper); /** * Will not return a result, rather simply will execute a SQL statement. Use this for non-SELECT statements or when @@ -103,7 +106,8 @@ public interface Queriable extends Query { * Will not return a result, rather simply will execute a SQL statement. Use this for non-SELECT statements or when * you're not interested in the result. */ - void execute(DatabaseWrapper databaseWrapper); + void execute(@NonNull DatabaseWrapper databaseWrapper); + @NonNull BaseModel.Action getPrimaryAction(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleKeyCacheableListModelLoader.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleKeyCacheableListModelLoader.java index 101eb8add..d6614275e 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleKeyCacheableListModelLoader.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleKeyCacheableListModelLoader.java @@ -13,7 +13,7 @@ */ public class SingleKeyCacheableListModelLoader extends CacheableListModelLoader { - public SingleKeyCacheableListModelLoader(Class tModelClass) { + public SingleKeyCacheableListModelLoader(@NonNull Class tModelClass) { super(tModelClass); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleKeyCacheableModelLoader.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleKeyCacheableModelLoader.java index da4a2774f..4bb81e459 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleKeyCacheableModelLoader.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleKeyCacheableModelLoader.java @@ -12,7 +12,7 @@ */ public class SingleKeyCacheableModelLoader extends CacheableModelLoader { - public SingleKeyCacheableModelLoader(Class modelClass) { + public SingleKeyCacheableModelLoader(@NonNull Class modelClass) { super(modelClass); } @@ -24,7 +24,8 @@ public SingleKeyCacheableModelLoader(Class modelClass) { */ @Nullable @Override - public TModel convertToData(@NonNull FlowCursor cursor, @Nullable TModel data, boolean moveToFirst) { + public TModel convertToData(@NonNull FlowCursor cursor, @Nullable TModel data, + boolean moveToFirst) { if (!moveToFirst || cursor.moveToFirst()) { Object value = getModelAdapter().getCachingColumnValueFromCursor(cursor); TModel model = getModelCache().get(value); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleModelLoader.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleModelLoader.java index 01dd7da1c..e1e4cabe4 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleModelLoader.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/SingleModelLoader.java @@ -16,7 +16,8 @@ public SingleModelLoader(Class modelClass) { @SuppressWarnings("unchecked") @Nullable - public TModel convertToData(@NonNull final FlowCursor cursor, @Nullable TModel data, boolean moveToFirst) { + public TModel convertToData(@NonNull final FlowCursor cursor, @Nullable TModel data, + boolean moveToFirst) { if (!moveToFirst || cursor.moveToFirst()) { if (data == null) { data = getInstanceAdapter().newInstance(); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/StringQuery.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/StringQuery.java index efdb1b5bb..230dd0c44 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/StringQuery.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/queriable/StringQuery.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.sql.queriable; import android.database.sqlite.SQLiteDatabase; +import android.support.annotation.NonNull; import com.raizlabs.android.dbflow.config.FlowManager; import com.raizlabs.android.dbflow.sql.Query; @@ -30,7 +31,7 @@ public class StringQuery extends BaseModelQueriable implements Q * @param sql The sql statement to query the DB with. Does not work with {@link Delete}, * this must be done with {@link SQLiteDatabase#execSQL(String)} */ - public StringQuery(Class table, String sql) { + public StringQuery(@NonNull Class table, @NonNull String sql) { super(table); query = sql; } @@ -46,18 +47,20 @@ public FlowCursor query() { } @Override - public FlowCursor query(DatabaseWrapper databaseWrapper) { + public FlowCursor query(@NonNull DatabaseWrapper databaseWrapper) { return databaseWrapper.rawQuery(query, args); } /** * Set selection arguments to execute on this raw query. */ - public StringQuery setSelectionArgs(String[] args) { + @NonNull + public StringQuery setSelectionArgs(@NonNull String[] args) { this.args = args; return this; } + @NonNull @Override public BaseModel.Action getPrimaryAction() { return BaseModel.Action.CHANGE; // we don't explicitly know the change, but something changed. diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/CacheableListModelSaver.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/CacheableListModelSaver.java index c02c8ad74..c44478cd9 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/CacheableListModelSaver.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/CacheableListModelSaver.java @@ -14,13 +14,13 @@ public class CacheableListModelSaver extends ListModelSaver { - public CacheableListModelSaver(ModelSaver modelSaver) { + public CacheableListModelSaver(@NonNull ModelSaver modelSaver) { super(modelSaver); } @Override public synchronized void saveAll(@NonNull Collection tableCollection, - DatabaseWrapper wrapper) { + @NonNull DatabaseWrapper wrapper) { // skip if empty. if (tableCollection.isEmpty()) { return; @@ -44,7 +44,7 @@ public synchronized void saveAll(@NonNull Collection tableCollection, @Override public synchronized void insertAll(@NonNull Collection tableCollection, - DatabaseWrapper wrapper) { + @NonNull DatabaseWrapper wrapper) { // skip if empty. if (tableCollection.isEmpty()) { return; diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ListModelSaver.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ListModelSaver.java index f7038f9cb..6cbbe1aa0 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ListModelSaver.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ListModelSaver.java @@ -11,7 +11,7 @@ public class ListModelSaver { private final ModelSaver modelSaver; - public ListModelSaver(ModelSaver modelSaver) { + public ListModelSaver(@NonNull ModelSaver modelSaver) { this.modelSaver = modelSaver; } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ModelSaver.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ModelSaver.java index 9999e63ff..02d3892dd 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ModelSaver.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ModelSaver.java @@ -37,7 +37,8 @@ public synchronized boolean save(@NonNull TModel model, } @SuppressWarnings("unchecked") - public synchronized boolean save(@NonNull TModel model, DatabaseWrapper wrapper, + public synchronized boolean save(@NonNull TModel model, + @NonNull DatabaseWrapper wrapper, @NonNull DatabaseStatement insertStatement, @NonNull DatabaseStatement updateStatement) { boolean exists = modelAdapter.exists(model, wrapper); @@ -150,6 +151,7 @@ public synchronized boolean delete(@NonNull TModel model, return success; } + @NonNull protected DatabaseWrapper getWritableDatabase() { return FlowManager.getDatabaseForTable(modelAdapter.getModelClass()).getWritableDatabase(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/AsyncModel.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/AsyncModel.java index f2d15e5bd..a477d8b5f 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/AsyncModel.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/AsyncModel.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.structure; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.FlowManager; import com.raizlabs.android.dbflow.sql.BaseAsyncObject; @@ -24,7 +25,7 @@ public interface OnModelChangedListener { /** * Called when the change finishes on the {@link DefaultTransactionQueue}. This method is called on the UI thread. */ - void onModelChanged(T model); + void onModelChanged(@NonNull T model); } private final TModel model; @@ -42,7 +43,7 @@ public AsyncModel(@NonNull TModel referenceModel) { * * @param onModelChangedListener The listener to use for a corresponding call to a method. */ - public AsyncModel withListener(OnModelChangedListener onModelChangedListener) { + public AsyncModel withListener(@Nullable OnModelChangedListener onModelChangedListener) { this.onModelChangedListener = new WeakReference<>(onModelChangedListener); return this; } @@ -124,7 +125,7 @@ public void processModel(TModel model, DatabaseWrapper wrapper) { } @Override - public void load(DatabaseWrapper wrapper) { + public void load(@NonNull DatabaseWrapper wrapper) { load(); } @@ -140,7 +141,7 @@ public void processModel(TModel model, DatabaseWrapper wrapper) { } @Override - public boolean exists(DatabaseWrapper wrapper) { + public boolean exists(@NonNull DatabaseWrapper wrapper) { return exists(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/BaseModel.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/BaseModel.java index 6bbbe80a5..1deeaa793 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/BaseModel.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/BaseModel.java @@ -53,7 +53,7 @@ public void load() { } @Override - public void load(DatabaseWrapper wrapper) { + public void load(@NonNull DatabaseWrapper wrapper) { getModelAdapter().load(this, wrapper); } @@ -104,7 +104,7 @@ public boolean exists() { } @Override - public boolean exists(DatabaseWrapper databaseWrapper) { + public boolean exists(@NonNull DatabaseWrapper databaseWrapper) { return getModelAdapter().exists(this, databaseWrapper); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/BaseQueryModel.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/BaseQueryModel.java index 0238eb62a..36333d667 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/BaseQueryModel.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/BaseQueryModel.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.annotation.QueryModel; import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; @@ -15,7 +17,7 @@ public boolean exists() { } @Override - public boolean exists(DatabaseWrapper databaseWrapper) { + public boolean exists(@NonNull DatabaseWrapper databaseWrapper) { return exists(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ModelViewAdapter.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ModelViewAdapter.java index 04e31e3c6..337e4cd1a 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ModelViewAdapter.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ModelViewAdapter.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.config.DatabaseDefinition; /** @@ -8,7 +10,7 @@ public abstract class ModelViewAdapter extends InstanceAdapter { - public ModelViewAdapter(DatabaseDefinition databaseDefinition) { + public ModelViewAdapter(@NonNull DatabaseDefinition databaseDefinition) { super(databaseDefinition); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/NoModificationModel.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/NoModificationModel.java index eb6016224..fdb59a9d7 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/NoModificationModel.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/NoModificationModel.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.config.FlowManager; import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; @@ -16,7 +18,7 @@ public boolean exists() { } @SuppressWarnings("unchecked") - public boolean exists(DatabaseWrapper databaseWrapper) { + public boolean exists(@NonNull DatabaseWrapper databaseWrapper) { return getRetrievalAdapter().exists(this, databaseWrapper); } @@ -26,7 +28,7 @@ public void load() { } @SuppressWarnings("unchecked") - public void load(DatabaseWrapper wrapper) { + public void load(@NonNull DatabaseWrapper wrapper) { getRetrievalAdapter().load(this, wrapper); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ReadOnlyModel.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ReadOnlyModel.java index 01d2c3c6d..d0bb43f31 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ReadOnlyModel.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ReadOnlyModel.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.sql.migration.Migration; import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; @@ -15,7 +17,7 @@ public interface ReadOnlyModel { * * @param wrapper Database object to use. Useful for {@link Migration} classes. */ - void load(DatabaseWrapper wrapper); + void load(@NonNull DatabaseWrapper wrapper); /** * @return true if this object exists in the DB. It combines all of it's primary key fields @@ -24,9 +26,9 @@ public interface ReadOnlyModel { boolean exists(); /** + * @param wrapper Database object to use. Useful for {@link Migration} classes. * @return true if this object exists in the DB. It combines all of it's primary key fields * into a SELECT query and checks to see if any results occur. - * @param wrapper Database object to use. Useful for {@link Migration} classes. */ - boolean exists(DatabaseWrapper wrapper); + boolean exists(@NonNull DatabaseWrapper wrapper); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/LruCache.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/LruCache.java index 92733744f..be531cd68 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/LruCache.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/LruCache.java @@ -24,7 +24,11 @@ * Static library version of {@link android.util.LruCache}. Used to write apps that run on API levels prior to 12. When * running on API level 12 or above, this implementation is still used; it does not try to switch to the framework's * implementation. See the framework SDK documentation for a class overview. + * + * @see {@link android.util.LruCache} + * @deprecated */ +@Deprecated public class LruCache { private final LinkedHashMap map; @@ -327,8 +331,8 @@ public synchronized final String toString() { int accesses = hitCount + missCount; int hitPercent = accesses != 0 ? (100 * hitCount / accesses) : 0; return String.format(Locale.getDefault(), - "LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]", maxSize, - hitCount, missCount, hitPercent); + "LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]", maxSize, + hitCount, missCount, hitPercent); } } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/ModelCache.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/ModelCache.java index a8fadf02d..1bf321a05 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/ModelCache.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/ModelCache.java @@ -1,5 +1,8 @@ package com.raizlabs.android.dbflow.structure.cache; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + /** * Description: A generic cache for models that is implemented or can be implemented to your liking. */ @@ -12,7 +15,7 @@ public abstract class ModelCache { * * @param cache The arbitrary underlying cache class. */ - public ModelCache(CacheClass cache) { + public ModelCache(@NonNull CacheClass cache) { this.cache = cache; } @@ -22,14 +25,14 @@ public ModelCache(CacheClass cache) { * @param id The id of the model to use. * @param model The model to add */ - public abstract void addModel(Object id, TModel model); + public abstract void addModel(@Nullable Object id, @NonNull TModel model); /** * Removes a model from this cache. * * @param id The id of the model to remove. */ - public abstract TModel removeModel(Object id); + public abstract TModel removeModel(@NonNull Object id); /** * Clears out all models from this cache. @@ -40,7 +43,7 @@ public ModelCache(CacheClass cache) { * @param id The id of the model to retrieve. * @return a model for the specified id. May be null. */ - public abstract TModel get(Object id); + public abstract TModel get(@Nullable Object id); /** * Sets a new size for the underlying cache (if applicable) and may destroy the cache. diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/ModelLruCache.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/ModelLruCache.java index 85ed0d70f..e7b72b431 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/ModelLruCache.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/ModelLruCache.java @@ -1,5 +1,8 @@ package com.raizlabs.android.dbflow.structure.cache; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + import com.raizlabs.android.dbflow.annotation.Table; /** @@ -23,7 +26,7 @@ protected ModelLruCache(int size) { } @Override - public void addModel(Object id, TModel model) { + public void addModel(@Nullable Object id, @NonNull TModel model) { if (id instanceof Number) { synchronized (getCache()) { Number number = ((Number) id); @@ -36,7 +39,7 @@ public void addModel(Object id, TModel model) { } @Override - public TModel removeModel(Object id) { + public TModel removeModel(@NonNull Object id) { TModel model; if (id instanceof Number) { synchronized (getCache()) { @@ -62,7 +65,7 @@ public void setCacheSize(int size) { } @Override - public TModel get(Object id) { + public TModel get(@Nullable Object id) { if (id instanceof Number) { return getCache().get(((Number) id).longValue()); } else { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/SimpleMapCache.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/SimpleMapCache.java index 14930f690..59bbdeb5e 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/SimpleMapCache.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/SimpleMapCache.java @@ -1,5 +1,8 @@ package com.raizlabs.android.dbflow.structure.cache; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + import com.raizlabs.android.dbflow.config.FlowLog; import com.raizlabs.android.dbflow.structure.Model; @@ -25,17 +28,17 @@ public SimpleMapCache(int capacity) { * * @param cache The arbitrary underlying cache class. */ - public SimpleMapCache(Map cache) { + public SimpleMapCache(@NonNull Map cache) { super(cache); } @Override - public void addModel(Object id, TModel model) { + public void addModel(@Nullable Object id, @NonNull TModel model) { getCache().put(id, model); } @Override - public TModel removeModel(Object id) { + public TModel removeModel(@NonNull Object id) { return getCache().remove(id); } @@ -45,7 +48,7 @@ public void clear() { } @Override - public TModel get(Object id) { + public TModel get(@Nullable Object id) { return getCache().get(id); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/SparseArrayBasedCache.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/SparseArrayBasedCache.java index d09543763..4db00dca0 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/SparseArrayBasedCache.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/cache/SparseArrayBasedCache.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure.cache; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.util.SparseArray; import com.raizlabs.android.dbflow.config.FlowLog; @@ -30,12 +32,12 @@ public SparseArrayBasedCache(int initialCapacity) { * * @param sparseArray The sparse array to use. */ - public SparseArrayBasedCache(SparseArray sparseArray) { + public SparseArrayBasedCache(@NonNull SparseArray sparseArray) { super(sparseArray); } @Override - public void addModel(Object id, TModel model) { + public void addModel(@Nullable Object id, @NonNull TModel model) { if (id instanceof Number) { synchronized (getCache()) { getCache().put(((Number) id).intValue(), model); @@ -47,7 +49,7 @@ public void addModel(Object id, TModel model) { } @Override - public TModel removeModel(Object id) { + public TModel removeModel(@NonNull Object id) { TModel model = get(id); synchronized (getCache()) { getCache().remove(((Number) id).intValue()); @@ -68,7 +70,7 @@ public void setCacheSize(int size) { } @Override - public TModel get(Object id) { + public TModel get(@Nullable Object id) { if (id instanceof Number) { return getCache().get(((Number) id).intValue()); } else { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/AndroidDatabase.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/AndroidDatabase.java index 902245c65..bad1e661b 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/AndroidDatabase.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/AndroidDatabase.java @@ -11,7 +11,7 @@ */ public class AndroidDatabase implements DatabaseWrapper { - public static AndroidDatabase from(SQLiteDatabase database) { + public static AndroidDatabase from(@NonNull SQLiteDatabase database) { return new AndroidDatabase(database); } @@ -22,7 +22,7 @@ public static AndroidDatabase from(SQLiteDatabase database) { } @Override - public void execSQL(String query) { + public void execSQL(@NonNull String query) { database.execSQL(query); } @@ -50,18 +50,20 @@ public SQLiteDatabase getDatabase() { return database; } + @NonNull @Override - public DatabaseStatement compileStatement(String rawQuery) { + public DatabaseStatement compileStatement(@NonNull String rawQuery) { return AndroidDatabaseStatement.from(database.compileStatement(rawQuery), database); } + @NonNull @Override - public FlowCursor rawQuery(String query, String[] selectionArgs) { + public FlowCursor rawQuery(@NonNull String query, @Nullable String[] selectionArgs) { return FlowCursor.from(database.rawQuery(query, selectionArgs)); } @Override - public long updateWithOnConflict(String tableName, ContentValues contentValues, String where, String[] whereArgs, int conflictAlgorithm) { + public long updateWithOnConflict(@NonNull String tableName, @NonNull ContentValues contentValues, @Nullable String where, @Nullable String[] whereArgs, int conflictAlgorithm) { long count; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { count = database.updateWithOnConflict(tableName, contentValues, where, whereArgs, conflictAlgorithm); @@ -72,7 +74,7 @@ public long updateWithOnConflict(String tableName, ContentValues contentValues, } @Override - public long insertWithOnConflict(String tableName, String nullColumnHack, ContentValues values, int sqLiteDatabaseAlgorithmInt) { + public long insertWithOnConflict(@NonNull String tableName, @Nullable String nullColumnHack, @NonNull ContentValues values, int sqLiteDatabaseAlgorithmInt) { long count; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { count = database.insertWithOnConflict(tableName, nullColumnHack, values, sqLiteDatabaseAlgorithmInt); @@ -82,6 +84,7 @@ public long insertWithOnConflict(String tableName, String nullColumnHack, Conten return count; } + @NonNull @Override public FlowCursor query(@NonNull String tableName, @Nullable String[] columns, diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/AndroidDatabaseStatement.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/AndroidDatabaseStatement.java index 739b8a187..df44ce5c8 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/AndroidDatabaseStatement.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/AndroidDatabaseStatement.java @@ -5,24 +5,29 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteStatement; import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; /** * Description: */ public class AndroidDatabaseStatement extends BaseDatabaseStatement { - public static AndroidDatabaseStatement from(SQLiteStatement sqLiteStatement, SQLiteDatabase database) { + public static AndroidDatabaseStatement from(@NonNull SQLiteStatement sqLiteStatement, + @NonNull SQLiteDatabase database) { return new AndroidDatabaseStatement(sqLiteStatement, database); } private final SQLiteStatement statement; private final SQLiteDatabase database; - AndroidDatabaseStatement(SQLiteStatement statement, SQLiteDatabase database) { + AndroidDatabaseStatement(@NonNull SQLiteStatement statement, + @NonNull SQLiteDatabase database) { this.statement = statement; this.database = database; } + @NonNull public SQLiteStatement getStatement() { return statement; } @@ -67,6 +72,7 @@ public long simpleQueryForLong() { return statement.simpleQueryForLong(); } + @Nullable @Override public String simpleQueryForString() { return statement.simpleQueryForString(); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/BaseDatabaseHelper.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/BaseDatabaseHelper.java index 35a9a3663..21839602c 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/BaseDatabaseHelper.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/BaseDatabaseHelper.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.structure.database; import android.database.sqlite.SQLiteException; +import android.support.annotation.NonNull; import com.raizlabs.android.dbflow.config.DatabaseDefinition; import com.raizlabs.android.dbflow.config.FlowLog; @@ -33,38 +34,39 @@ public class BaseDatabaseHelper { public static final String MIGRATION_PATH = "migrations"; private final DatabaseDefinition databaseDefinition; - public BaseDatabaseHelper(DatabaseDefinition databaseDefinition) { + public BaseDatabaseHelper(@NonNull DatabaseDefinition databaseDefinition) { this.databaseDefinition = databaseDefinition; } + @NonNull public DatabaseDefinition getDatabaseDefinition() { return databaseDefinition; } - public void onCreate(DatabaseWrapper db) { + public void onCreate(@NonNull DatabaseWrapper db) { checkForeignKeySupport(db); executeCreations(db); executeMigrations(db, -1, db.getVersion()); } - public void onUpgrade(DatabaseWrapper db, int oldVersion, int newVersion) { + public void onUpgrade(@NonNull DatabaseWrapper db, int oldVersion, int newVersion) { checkForeignKeySupport(db); executeCreations(db); executeMigrations(db, oldVersion, newVersion); } - public void onOpen(DatabaseWrapper db) { + public void onOpen(@NonNull DatabaseWrapper db) { checkForeignKeySupport(db); } - public void onDowngrade(DatabaseWrapper db, int oldVersion, int newVersion) { + public void onDowngrade(@NonNull DatabaseWrapper db, int oldVersion, int newVersion) { checkForeignKeySupport(db); } /** * If foreign keys are supported, we turn it on the DB specified. */ - protected void checkForeignKeySupport(DatabaseWrapper database) { + protected void checkForeignKeySupport(@NonNull DatabaseWrapper database) { if (databaseDefinition.isForeignKeysSupported()) { database.execSQL("PRAGMA foreign_keys=ON;"); FlowLog.log(FlowLog.Level.I, "Foreign Keys supported. Enabling foreign key features."); @@ -74,7 +76,7 @@ protected void checkForeignKeySupport(DatabaseWrapper database) { /** * This method executes CREATE TABLE statements as well as CREATE VIEW on the database passed. */ - protected void executeCreations(final DatabaseWrapper database) { + protected void executeCreations(@NonNull final DatabaseWrapper database) { try { database.beginTransaction(); List modelAdapters = databaseDefinition.getModelAdapters(); @@ -107,7 +109,8 @@ protected void executeCreations(final DatabaseWrapper database) { } - protected void executeMigrations(final DatabaseWrapper db, final int oldVersion, final int newVersion) { + protected void executeMigrations(@NonNull final DatabaseWrapper db, + final int oldVersion, final int newVersion) { // will try migrations file or execute migrations from code try { @@ -147,20 +150,18 @@ protected void executeMigrations(final DatabaseWrapper db, final int oldVersion, } } - if (migrationMap != null) { - List migrationsList = migrationMap.get(i); - if (migrationsList != null) { - for (Migration migration : migrationsList) { - // before migration - migration.onPreMigrate(); + List migrationsList = migrationMap.get(i); + if (migrationsList != null) { + for (Migration migration : migrationsList) { + // before migration + migration.onPreMigrate(); - // migrate - migration.migrate(db); + // migrate + migration.migrate(db); - // after migration cleanup - migration.onPostMigrate(); - FlowLog.log(FlowLog.Level.I, migration.getClass() + " executed successfully."); - } + // after migration cleanup + migration.onPostMigrate(); + FlowLog.log(FlowLog.Level.I, migration.getClass() + " executed successfully."); } } } @@ -180,7 +181,8 @@ protected void executeMigrations(final DatabaseWrapper db, final int oldVersion, * @param db The database to run it on * @param file the file name in assets/migrations that we read from */ - private void executeSqlScript(DatabaseWrapper db, String file) { + private void executeSqlScript(@NonNull DatabaseWrapper db, + @NonNull String file) { try { final InputStream input = FlowManager.getContext().getAssets().open(MIGRATION_PATH + "/" + getDatabaseDefinition().getDatabaseName() + "/" + file); final BufferedReader reader = new BufferedReader(new InputStreamReader(input)); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseHelperDelegate.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseHelperDelegate.java index 399624068..edfb62be7 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseHelperDelegate.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseHelperDelegate.java @@ -2,6 +2,7 @@ import android.content.Context; import android.database.sqlite.SQLiteOpenHelper; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.DatabaseDefinition; @@ -63,7 +64,7 @@ public void setDatabaseHelperListener(DatabaseHelperListener databaseHelperListe } @Override - public void onCreate(DatabaseWrapper db) { + public void onCreate(@NonNull DatabaseWrapper db) { if (databaseHelperListener != null) { databaseHelperListener.onCreate(db); } @@ -71,7 +72,7 @@ public void onCreate(DatabaseWrapper db) { } @Override - public void onUpgrade(DatabaseWrapper db, int oldVersion, int newVersion) { + public void onUpgrade(@NonNull DatabaseWrapper db, int oldVersion, int newVersion) { if (databaseHelperListener != null) { databaseHelperListener.onUpgrade(db, oldVersion, newVersion); } @@ -79,7 +80,7 @@ public void onUpgrade(DatabaseWrapper db, int oldVersion, int newVersion) { } @Override - public void onOpen(DatabaseWrapper db) { + public void onOpen(@NonNull DatabaseWrapper db) { if (databaseHelperListener != null) { databaseHelperListener.onOpen(db); } @@ -87,7 +88,7 @@ public void onOpen(DatabaseWrapper db) { } @Override - public void onDowngrade(DatabaseWrapper db, int oldVersion, int newVersion) { + public void onDowngrade(@NonNull DatabaseWrapper db, int oldVersion, int newVersion) { if (databaseHelperListener != null) { databaseHelperListener.onDowngrade(db, oldVersion, newVersion); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseHelperListener.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseHelperListener.java index d8de94442..7d787642a 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseHelperListener.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseHelperListener.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure.database; +import android.support.annotation.NonNull; + /** * Description: Provides callbacks for {@link OpenHelper} methods */ @@ -10,14 +12,14 @@ public interface DatabaseHelperListener { * * @param database The database that is opened */ - void onOpen(DatabaseWrapper database); + void onOpen(@NonNull DatabaseWrapper database); /** * Called when the DB is created * * @param database The database that is created */ - void onCreate(DatabaseWrapper database); + void onCreate(@NonNull DatabaseWrapper database); /** * Called when the DB is upgraded. @@ -26,7 +28,7 @@ public interface DatabaseHelperListener { * @param oldVersion The previous DB version * @param newVersion The new DB version */ - void onUpgrade(DatabaseWrapper database, int oldVersion, int newVersion); + void onUpgrade(@NonNull DatabaseWrapper database, int oldVersion, int newVersion); /** * Called when DB is downgraded. Note that this may not be supported by all implementations of the DB. @@ -35,5 +37,5 @@ public interface DatabaseHelperListener { * @param oldVersion The old. higher version. * @param newVersion The new lower version. */ - void onDowngrade(DatabaseWrapper databaseWrapper, int oldVersion, int newVersion); + void onDowngrade(@NonNull DatabaseWrapper databaseWrapper, int oldVersion, int newVersion); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseStatement.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseStatement.java index 5af8fdad0..55635b7c1 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseStatement.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseStatement.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.structure.database; import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; /** @@ -16,6 +17,7 @@ public interface DatabaseStatement { long simpleQueryForLong(); + @Nullable String simpleQueryForString(); long executeInsert(); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseStatementWrapper.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseStatementWrapper.java index 8a03d7f50..1eac49388 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseStatementWrapper.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseStatementWrapper.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.structure.database; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.runtime.NotifyDistributor; import com.raizlabs.android.dbflow.sql.language.BaseQueriable; @@ -16,7 +17,7 @@ public class DatabaseStatementWrapper extends BaseDatabaseStatement { private final BaseQueriable modelQueriable; public DatabaseStatementWrapper(@NonNull DatabaseStatement databaseStatement, - BaseQueriable modelQueriable) { + @NonNull BaseQueriable modelQueriable) { this.databaseStatement = databaseStatement; this.modelQueriable = modelQueriable; } @@ -46,6 +47,7 @@ public long simpleQueryForLong() { return databaseStatement.simpleQueryForLong(); } + @Nullable @Override public String simpleQueryForString() { return databaseStatement.simpleQueryForString(); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseWrapper.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseWrapper.java index 537916adf..8e7d8ffb2 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseWrapper.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/DatabaseWrapper.java @@ -10,7 +10,7 @@ */ public interface DatabaseWrapper { - void execSQL(String query); + void execSQL(@NonNull String query); void beginTransaction(); @@ -20,16 +20,23 @@ public interface DatabaseWrapper { int getVersion(); - DatabaseStatement compileStatement(String rawQuery); + @NonNull + DatabaseStatement compileStatement(@NonNull String rawQuery); - FlowCursor rawQuery(String query, String[] selectionArgs); + @NonNull + FlowCursor rawQuery(@NonNull String query, @Nullable String[] selectionArgs); - long updateWithOnConflict(String tableName, ContentValues contentValues, String where, - String[] whereArgs, int conflictAlgorithm); + long updateWithOnConflict(@NonNull String tableName, + @NonNull ContentValues contentValues, + @Nullable String where, + @Nullable String[] whereArgs, int conflictAlgorithm); - long insertWithOnConflict(String tableName, String nullColumnHack, ContentValues values, + long insertWithOnConflict(@NonNull String tableName, + @Nullable String nullColumnHack, + @NonNull ContentValues values, int sqLiteDatabaseAlgorithmInt); + @NonNull FlowCursor query(@NonNull String tableName, @Nullable String[] columns, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String groupBy, @Nullable String having, @Nullable String orderBy); diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/FlowCursor.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/FlowCursor.java index 715b95ed9..3a767958c 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/FlowCursor.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/FlowCursor.java @@ -11,7 +11,7 @@ */ public class FlowCursor extends CursorWrapper { - public static FlowCursor from(Cursor cursor) { + public static FlowCursor from(@NonNull Cursor cursor) { if (cursor instanceof FlowCursor) { return (FlowCursor) cursor; } else { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/FlowSQLiteOpenHelper.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/FlowSQLiteOpenHelper.java index bd9492b63..99ef042d2 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/FlowSQLiteOpenHelper.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/FlowSQLiteOpenHelper.java @@ -3,6 +3,8 @@ import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.DatabaseDefinition; import com.raizlabs.android.dbflow.config.FlowManager; @@ -15,13 +17,17 @@ public class FlowSQLiteOpenHelper extends SQLiteOpenHelper implements OpenHelper private DatabaseHelperDelegate databaseHelperDelegate; private AndroidDatabase androidDatabase; - public FlowSQLiteOpenHelper(DatabaseDefinition databaseDefinition, DatabaseHelperListener listener) { - super(FlowManager.getContext(), databaseDefinition.isInMemory() ? null : databaseDefinition.getDatabaseFileName(), null, databaseDefinition.getDatabaseVersion()); + public FlowSQLiteOpenHelper(@NonNull DatabaseDefinition databaseDefinition, + @NonNull DatabaseHelperListener listener) { + super(FlowManager.getContext(), + databaseDefinition.isInMemory() ? null : databaseDefinition.getDatabaseFileName(), + null, databaseDefinition.getDatabaseVersion()); OpenHelper backupHelper = null; if (databaseDefinition.backupEnabled()) { // Temp database mirrors existing - backupHelper = new BackupHelper(FlowManager.getContext(), DatabaseHelperDelegate.getTempDbFileName(databaseDefinition), + backupHelper = new BackupHelper(FlowManager.getContext(), + DatabaseHelperDelegate.getTempDbFileName(databaseDefinition), databaseDefinition.getDatabaseVersion(), databaseDefinition); } @@ -33,6 +39,7 @@ public void performRestoreFromBackup() { databaseHelperDelegate.performRestoreFromBackup(); } + @Nullable @Override public DatabaseHelperDelegate getDelegate() { return databaseHelperDelegate; @@ -48,6 +55,7 @@ public void backupDB() { databaseHelperDelegate.backupDB(); } + @NonNull @Override public DatabaseWrapper getDatabase() { if (androidDatabase == null || !androidDatabase.getDatabase().isOpen()) { @@ -62,27 +70,27 @@ public DatabaseWrapper getDatabase() { * * @param listener */ - public void setDatabaseListener(DatabaseHelperListener listener) { + public void setDatabaseListener(@Nullable DatabaseHelperListener listener) { databaseHelperDelegate.setDatabaseHelperListener(listener); } @Override - public void onCreate(SQLiteDatabase db) { + public void onCreate(@NonNull SQLiteDatabase db) { databaseHelperDelegate.onCreate(AndroidDatabase.from(db)); } @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + public void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) { databaseHelperDelegate.onUpgrade(AndroidDatabase.from(db), oldVersion, newVersion); } @Override - public void onOpen(SQLiteDatabase db) { + public void onOpen(@NonNull SQLiteDatabase db) { databaseHelperDelegate.onOpen(AndroidDatabase.from(db)); } @Override - public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { + public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) { databaseHelperDelegate.onDowngrade(AndroidDatabase.from(db), oldVersion, newVersion); } @@ -105,6 +113,7 @@ public BackupHelper(Context context, String name, int version, DatabaseDefinitio this.baseDatabaseHelper = new BaseDatabaseHelper(databaseDefinition); } + @NonNull @Override public DatabaseWrapper getDatabase() { if (androidDatabase == null) { @@ -117,6 +126,7 @@ public DatabaseWrapper getDatabase() { public void performRestoreFromBackup() { } + @Nullable @Override public DatabaseHelperDelegate getDelegate() { return null; @@ -132,7 +142,7 @@ public void backupDB() { } @Override - public void setDatabaseListener(DatabaseHelperListener helperListener) { + public void setDatabaseListener(@Nullable DatabaseHelperListener helperListener) { } @Override diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/OpenHelper.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/OpenHelper.java index a5549fc08..280e3b80a 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/OpenHelper.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/OpenHelper.java @@ -1,5 +1,8 @@ package com.raizlabs.android.dbflow.structure.database; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + /** * Description: Abstracts out the {@link DatabaseHelperDelegate} into the one used in this library. */ @@ -7,15 +10,17 @@ public interface OpenHelper { void performRestoreFromBackup(); + @NonNull DatabaseWrapper getDatabase(); + @Nullable DatabaseHelperDelegate getDelegate(); boolean isDatabaseIntegrityOk(); void backupDB(); - void setDatabaseListener(DatabaseHelperListener helperListener); + void setDatabaseListener(@Nullable DatabaseHelperListener helperListener); void closeDB(); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/DefaultTransactionManager.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/DefaultTransactionManager.java index 427d7209e..4f8d81ced 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/DefaultTransactionManager.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/DefaultTransactionManager.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure.database.transaction; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.config.DatabaseDefinition; import com.raizlabs.android.dbflow.runtime.BaseTransactionManager; @@ -9,11 +11,12 @@ */ public class DefaultTransactionManager extends BaseTransactionManager { - public DefaultTransactionManager(DatabaseDefinition databaseDefinition) { + public DefaultTransactionManager(@NonNull DatabaseDefinition databaseDefinition) { super(new DefaultTransactionQueue("DBFlow Transaction Queue"), databaseDefinition); } - public DefaultTransactionManager(ITransactionQueue transactionQueue, DatabaseDefinition databaseDefinition) { + public DefaultTransactionManager(@NonNull ITransactionQueue transactionQueue, + @NonNull DatabaseDefinition databaseDefinition) { super(transactionQueue, databaseDefinition); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/DefaultTransactionQueue.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/DefaultTransactionQueue.java index 6b2aa3604..75503e926 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/DefaultTransactionQueue.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/DefaultTransactionQueue.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.structure.database.transaction; import android.os.Looper; +import android.support.annotation.NonNull; import com.raizlabs.android.dbflow.config.FlowLog; @@ -56,7 +57,7 @@ public void run() { } @Override - public void add(Transaction runnable) { + public void add(@NonNull Transaction runnable) { synchronized (queue) { if (!queue.contains(runnable)) { queue.add(runnable); @@ -70,7 +71,7 @@ public void add(Transaction runnable) { * @param runnable */ @Override - public void cancel(Transaction runnable) { + public void cancel(@NonNull Transaction runnable) { synchronized (queue) { if (queue.contains(runnable)) { queue.remove(runnable); @@ -84,7 +85,7 @@ public void cancel(Transaction runnable) { * @param tag */ @Override - public void cancel(String tag) { + public void cancel(@NonNull String tag) { synchronized (queue) { Iterator it = queue.iterator(); while (it.hasNext()) { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/ITransactionQueue.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/ITransactionQueue.java index efdd54291..581b39374 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/ITransactionQueue.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/ITransactionQueue.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure.database.transaction; +import android.support.annotation.NonNull; + /** * Description: Interface for a queue that manages transactions. */ @@ -10,14 +12,14 @@ public interface ITransactionQueue { * * @param transaction The transaction to run on the queue. */ - void add(Transaction transaction); + void add(@NonNull Transaction transaction); /** * Cancels a transaction. * * @param transaction The transaction to cancel on the queue. */ - void cancel(Transaction transaction); + void cancel(@NonNull Transaction transaction); /** * Starts if not alive. @@ -29,7 +31,7 @@ public interface ITransactionQueue { * * @param name the {@link Transaction#name()} property. */ - void cancel(String name); + void cancel(@NonNull String name); /** * Stops/interrupts the queue. diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/PriorityTransactionQueue.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/PriorityTransactionQueue.java index 20f134459..280e5e431 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/PriorityTransactionQueue.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/PriorityTransactionQueue.java @@ -52,7 +52,7 @@ public void run() { } @Override - public void add(Transaction transaction) { + public void add(@NonNull Transaction transaction) { synchronized (queue) { PriorityEntry priorityEntry = new PriorityEntry<>(transaction); if (!queue.contains(priorityEntry)) { @@ -67,7 +67,7 @@ public void add(Transaction transaction) { * @param transaction The transaction to cancel (if still in the queue). */ @Override - public void cancel(Transaction transaction) { + public void cancel(@NonNull Transaction transaction) { synchronized (queue) { PriorityEntry priorityEntry = new PriorityEntry<>(transaction); if (queue.contains(priorityEntry)) { @@ -82,7 +82,7 @@ public void cancel(Transaction transaction) { * @param tag */ @Override - public void cancel(String tag) { + public void cancel(@NonNull String tag) { synchronized (queue) { Iterator> it = queue.iterator(); while (it.hasNext()) { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/Transaction.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/Transaction.java index 93528f4c5..5f5a4bd64 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/Transaction.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/database/transaction/Transaction.java @@ -3,6 +3,7 @@ import android.os.Handler; import android.os.Looper; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.DatabaseDefinition; import com.raizlabs.android.dbflow.config.FlowLog; @@ -29,7 +30,8 @@ public interface Error { * @param transaction The transaction that failed. * @param error The error that was thrown. */ - void onError(Transaction transaction, Throwable error); + void onError(@NonNull Transaction transaction, + @NonNull Throwable error); } /** @@ -42,7 +44,7 @@ public interface Success { * * @param transaction The transaction that succeeded. */ - void onSuccess(Transaction transaction); + void onSuccess(@NonNull Transaction transaction); } private static Handler TRANSACTION_HANDLER; @@ -74,18 +76,22 @@ static Handler getTransactionHandler() { runCallbacksOnSameThread = builder.runCallbacksOnSameThread; } + @Nullable public Error error() { return errorCallback; } + @Nullable public Success success() { return successCallback; } + @NonNull public ITransaction transaction() { return transaction; } + @Nullable public String name() { return name; } @@ -147,13 +153,14 @@ public void run() { } } + @NonNull public Builder newBuilder() { return new Builder(transaction, databaseDefinition) - .error(errorCallback) - .success(successCallback) - .name(name) - .shouldRunInTransaction(shouldRunInTransaction) - .runCallbacksOnSameThread(runCallbacksOnSameThread); + .error(errorCallback) + .success(successCallback) + .name(name) + .shouldRunInTransaction(shouldRunInTransaction) + .runCallbacksOnSameThread(runCallbacksOnSameThread); } /** @@ -183,7 +190,8 @@ public Builder(@NonNull ITransaction transaction, @NonNull DatabaseDefinition da /** * Specify an error callback to return all and any {@link Throwable} that occured during a {@link Transaction}. */ - public Builder error(Error errorCallback) { + @NonNull + public Builder error(@Nullable Error errorCallback) { this.errorCallback = errorCallback; return this; } @@ -194,7 +202,8 @@ public Builder error(Error errorCallback) { * * @param successCallback The callback, invoked on the UI thread. */ - public Builder success(Success successCallback) { + @NonNull + public Builder success(@Nullable Success successCallback) { this.successCallback = successCallback; return this; } @@ -205,7 +214,8 @@ public Builder success(Success successCallback) { * @param name The name of this transaction. Should be unique for any transaction currently * running in the {@link ITransactionQueue}. */ - public Builder name(String name) { + @NonNull + public Builder name(@Nullable String name) { this.name = name; return this; } @@ -216,6 +226,7 @@ public Builder name(String name) { * {@link QueryTransaction}), you should specify false. * @return */ + @NonNull public Builder shouldRunInTransaction(boolean shouldRunInTransaction) { this.shouldRunInTransaction = shouldRunInTransaction; return this; @@ -226,6 +237,7 @@ public Builder shouldRunInTransaction(boolean shouldRunInTransaction) { * this {@link Transaction} on the same thread we call * {@link #execute()} from. */ + @NonNull public Builder runCallbacksOnSameThread(boolean runCallbacksOnSameThread) { this.runCallbacksOnSameThread = runCallbacksOnSameThread; return this; @@ -235,6 +247,7 @@ public Builder runCallbacksOnSameThread(boolean runCallbacksOnSameThread) { * @return A new instance of {@link Transaction}. Subsequent calls to this method produce * new instances. */ + @NonNull public Transaction build() { return new Transaction(this); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/listener/LoadFromCursorListener.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/listener/LoadFromCursorListener.java index 77426a716..e0d52053a 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/listener/LoadFromCursorListener.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/listener/LoadFromCursorListener.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.structure.listener; import android.database.Cursor; +import android.support.annotation.NonNull; import com.raizlabs.android.dbflow.structure.Model; @@ -15,5 +16,5 @@ public interface LoadFromCursorListener { * * @param cursor The cursor that is loaded. */ - void onLoadFromCursor(Cursor cursor); + void onLoadFromCursor(@NonNull Cursor cursor); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/listener/SQLiteStatementListener.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/listener/SQLiteStatementListener.java index 7792b7ef2..788f89a6c 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/listener/SQLiteStatementListener.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/listener/SQLiteStatementListener.java @@ -1,5 +1,7 @@ package com.raizlabs.android.dbflow.structure.listener; +import android.support.annotation.NonNull; + import com.raizlabs.android.dbflow.structure.InternalAdapter; import com.raizlabs.android.dbflow.structure.Model; import com.raizlabs.android.dbflow.structure.ModelAdapter; @@ -17,7 +19,7 @@ public interface SQLiteStatementListener { * * @param databaseStatement The statement from the {@link ModelAdapter} */ - void onBindToStatement(DatabaseStatement databaseStatement); + void onBindToStatement(@NonNull DatabaseStatement databaseStatement); /** * Called at the end of {@link InternalAdapter#bindToInsertStatement(DatabaseStatement, Object)} @@ -25,7 +27,7 @@ public interface SQLiteStatementListener { * * @param databaseStatement The insert statement from the {@link ModelAdapter} */ - void onBindToInsertStatement(DatabaseStatement databaseStatement); + void onBindToInsertStatement(@NonNull DatabaseStatement databaseStatement); /** * Called at the end of {@link InternalAdapter#bindToUpdateStatement(DatabaseStatement, Object)} @@ -33,7 +35,7 @@ public interface SQLiteStatementListener { * * @param databaseStatement The insert statement from the {@link ModelAdapter} */ - void onBindToUpdateStatement(DatabaseStatement databaseStatement); + void onBindToUpdateStatement(@NonNull DatabaseStatement databaseStatement); - void onBindToDeleteStatement(DatabaseStatement databaseStatement); + void onBindToDeleteStatement(@NonNull DatabaseStatement databaseStatement); } diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/BaseProviderModel.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/BaseProviderModel.java index 44437bd40..99442795f 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/BaseProviderModel.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/BaseProviderModel.java @@ -2,6 +2,8 @@ import android.content.ContentProvider; import android.database.Cursor; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.FlowManager; import com.raizlabs.android.dbflow.sql.language.OperatorGroup; @@ -63,8 +65,8 @@ public boolean exists() { @Override @SuppressWarnings("unchecked") - public void load(OperatorGroup whereConditions, - String orderBy, String... columns) { + public void load(@NonNull OperatorGroup whereConditions, + @Nullable String orderBy, String... columns) { FlowCursor cursor = FlowCursor.from(ContentUtils.query(FlowManager.getContext().getContentResolver(), getQueryUri(), whereConditions, orderBy, columns)); if (cursor != null && cursor.moveToFirst()) { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/BaseSyncableProviderModel.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/BaseSyncableProviderModel.java index 5b4e4b991..8699e99d8 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/BaseSyncableProviderModel.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/BaseSyncableProviderModel.java @@ -1,6 +1,8 @@ package com.raizlabs.android.dbflow.structure.provider; import android.content.ContentProvider; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.config.FlowManager; import com.raizlabs.android.dbflow.sql.language.OperatorGroup; @@ -42,8 +44,8 @@ public boolean update() { @Override @SuppressWarnings("unchecked") - public void load(OperatorGroup whereOperatorGroup, - String orderBy, String... columns) { + public void load(@NonNull OperatorGroup whereOperatorGroup, + @Nullable String orderBy, String... columns) { FlowCursor cursor = FlowCursor.from(ContentUtils.query(FlowManager.getContext().getContentResolver(), getQueryUri(), whereOperatorGroup, orderBy, columns)); if (cursor != null && cursor.moveToFirst()) { diff --git a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/ModelProvider.java b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/ModelProvider.java index f01ec605b..d1d8eae33 100644 --- a/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/ModelProvider.java +++ b/dbflow/src/main/java/com/raizlabs/android/dbflow/structure/provider/ModelProvider.java @@ -2,6 +2,8 @@ import android.content.ContentResolver; import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import com.raizlabs.android.dbflow.sql.language.Operator; import com.raizlabs.android.dbflow.sql.language.OperatorGroup; @@ -16,11 +18,11 @@ public interface ModelProvider { * populates this object with the first row from the returned data. * * @param whereOperatorGroup The set of {@link Operator} to filter the query by. - * @param orderBy The order by without the ORDER BY - * @param columns The list of columns to select. Leave blank for * + * @param orderBy The order by without the ORDER BY + * @param columns The list of columns to select. Leave blank for * */ - void load(OperatorGroup whereOperatorGroup, - String orderBy, String... columns); + void load(@NonNull OperatorGroup whereOperatorGroup, + @Nullable String orderBy, String... columns); /** * Queries the {@link ContentResolver} of the app based on the primary keys of the object and populates diff --git a/gradle.properties b/gradle.properties index a40befee1..2c5effac9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=4.0.2 +version=4.0.3 version_code=1 group=com.raizlabs.android bt_siteUrl=https://github.com/Raizlabs/DBFlow