Skip to content

Commit

Permalink
Merge pull request #1311 from Raizlabs/develop
Browse files Browse the repository at this point in the history
4.0.3
  • Loading branch information
agrosner authored Jun 2, 2017
2 parents baa5270 + a1ff1b0 commit 8b1e3f7
Show file tree
Hide file tree
Showing 132 changed files with 982 additions and 649 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <reified T : Any> T.save(databaseWrapper: DatabaseWrapper = writableDatabaseForTable<T>()) = modelAdapter<T>().save(this, databaseWrapper)
Expand All @@ -10,4 +11,6 @@ inline fun <reified T : Any> T.update(databaseWrapper: DatabaseWrapper = writabl

inline fun <reified T : Any> T.delete(databaseWrapper: DatabaseWrapper = writableDatabaseForTable<T>()) = modelAdapter<T>().delete(this, databaseWrapper)

inline fun <reified T : Any> T.exists(databaseWrapper: DatabaseWrapper = writableDatabaseForTable<T>()) = modelAdapter<T>().exists(this, databaseWrapper)
inline fun <reified T : Any> T.exists(databaseWrapper: DatabaseWrapper = writableDatabaseForTable<T>()) = modelAdapter<T>().exists(this, databaseWrapper)

inline fun <reified T : Any> T.async(databaseWrapper: DatabaseWrapper = writableDatabaseForTable<T>()) = AsyncModel(this)
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ infix fun <T : Any> Case<T>.`else`(value: T?) = _else(value)

infix fun <T : Any> Case<T>.end(columnName: String) = end(columnName)

fun <T : Any> case(caseColumn: IProperty<*>? = null) = SQLite._case<T>(caseColumn)
fun <T : Any> case(caseColumn: IProperty<*>) = SQLite._case<T>(caseColumn)

fun <T : Any> caseWhen(operator: SQLOperator) = SQLite.caseWhen<T>(operator)

Expand Down Expand Up @@ -100,16 +100,16 @@ inline val <T : Any> ModelQueriable<T>.async
get() = async()

infix inline fun <T : Any> AsyncQuery<T>.list(crossinline callback: (QueryTransaction<*>, MutableList<T>) -> Unit)
= queryListResultCallback { queryTransaction, mutableList -> callback(queryTransaction, mutableList) }
.execute()
= queryListResultCallback { queryTransaction, mutableList -> callback(queryTransaction, mutableList) }
.execute()

infix inline fun <T : Any> AsyncQuery<T>.result(crossinline callback: (QueryTransaction<*>, T?) -> Unit)
= querySingleResultCallback { queryTransaction, model -> callback(queryTransaction, model) }
.execute()
= querySingleResultCallback { queryTransaction, model -> callback(queryTransaction, model) }
.execute()

infix inline fun <T : Any> AsyncQuery<T>.cursorResult(crossinline callback: (QueryTransaction<*>, CursorResult<T>) -> Unit)
= queryResultCallback { queryTransaction, cursorResult -> callback(queryTransaction, cursorResult) }
.execute()
= queryResultCallback { queryTransaction, cursorResult -> callback(queryTransaction, cursorResult) }
.execute()

inline val Model.async
get() = async()
Expand Down Expand Up @@ -163,7 +163,7 @@ infix fun <T : Any> Update<T>.set(sqlOperator: SQLOperator) = set(sqlOperator)
inline fun <reified T : Any> delete() = SQLite.delete(T::class.java)

inline fun <reified T : Any> delete(deleteClause: From<T>.() -> BaseModelQueriable<T>)
= deleteClause(SQLite.delete(T::class.java))
= deleteClause(SQLite.delete(T::class.java))

// insert methods

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@ class IndexGroupsDefinition(private val tableDefinition: TableDefinition, indexG

val columnDefinitionList: MutableList<ColumnDefinition> = 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()!!

}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -50,30 +50,33 @@ 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));
}

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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,6 +44,7 @@ public void performRestoreFromBackup() {
databaseHelperDelegate.performRestoreFromBackup();
}

@Nullable
@Override
public DatabaseHelperDelegate getDelegate() {
return databaseHelperDelegate;
Expand All @@ -57,6 +60,7 @@ public void backupDB() {
databaseHelperDelegate.backupDB();
}

@NonNull
@Override
public DatabaseWrapper getDatabase() {
if (cipherDatabase == null || !cipherDatabase.getDatabase().isOpen()) {
Expand All @@ -71,7 +75,7 @@ public DatabaseWrapper getDatabase() {
*
* @param listener
*/
public void setDatabaseListener(DatabaseHelperListener listener) {
public void setDatabaseListener(@Nullable DatabaseHelperListener listener) {
databaseHelperDelegate.setDatabaseHelperListener(listener);
}

Expand Down Expand Up @@ -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) {
Expand All @@ -126,6 +131,7 @@ public DatabaseWrapper getDatabase() {
public void performRestoreFromBackup() {
}

@Nullable
@Override
public DatabaseHelperDelegate getDelegate() {
return null;
Expand All @@ -145,7 +151,7 @@ public void closeDB() {
}

@Override
public void setDatabaseListener(DatabaseHelperListener helperListener) {
public void setDatabaseListener(@Nullable DatabaseHelperListener helperListener) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -45,6 +47,7 @@ public long simpleQueryForLong() {
return statement.simpleQueryForLong();
}

@Nullable
@Override
public String simpleQueryForString() {
return statement.simpleQueryForString();
Expand Down
1 change: 0 additions & 1 deletion dbflow-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'com.getkeepsafe.dexcount'

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit 8b1e3f7

Please sign in to comment.