Skip to content

Commit

Permalink
Merge pull request agrosner#1370 from Raizlabs/develop
Browse files Browse the repository at this point in the history
4.0.5
  • Loading branch information
agrosner authored Jul 17, 2017
2 parents 43dd2f6 + ea8079f commit 38fe8f0
Show file tree
Hide file tree
Showing 31 changed files with 208 additions and 140 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![Image](https://github.com/agrosner/DBFlow/blob/develop/dbflow_banner.png?raw=true)

[![JitPack.io](https://img.shields.io/badge/JitPack.io-4.0.0-red.svg?style=flat)](https://jitpack.io/#Raizlabs/DBFlow) [![Android Weekly](http://img.shields.io/badge/Android%20Weekly-%23129-2CB3E5.svg?style=flat)](http://androidweekly.net/issues/issue-129) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-DBFlow-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1134)
[![JitPack.io](https://img.shields.io/badge/JitPack.io-4.0.5-red.svg?style=flat)](https://jitpack.io/#Raizlabs/DBFlow) [![Android Weekly](http://img.shields.io/badge/Android%20Weekly-%23129-2CB3E5.svg?style=flat)](http://androidweekly.net/issues/issue-129) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-DBFlow-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1134)

A robust, powerful, and very simple ORM android database library with **annotation processing**.

Expand Down 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.4"
def dbflow_version = "4.0.5"
// 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 Expand Up @@ -83,7 +83,7 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl

# Pull Requests
I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:
1. Match coding style (braces, spacing, etc.) This is best achieved using CMD+Option+L (Reformat code) on Mac (not sure for Windows) with Android Studio defaults.
1. Match coding style (braces, spacing, etc.) This is best achieved using **Reformat Code** shortcut, <kbd>command</kbd>+<kbd>option</kbd>+<kbd>L</kbd> on Mac and <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>L</kbd> on Windows, with Android Studio defaults.
2. If its a feature, bugfix, or anything please only change code to what you specify.
3. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
4. Pull requests _must_ be made against `develop` branch. Any other branch (unless specified by the maintainers) will get rejected.
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
buildscript {
ext.kotlin_version = '1.1.2-3'
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ inline fun <reified T : Any> T.delete(databaseWrapper: DatabaseWrapper = writabl

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)
inline fun <reified T : Any> T.async() = AsyncModel(this)
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.raizlabs.android.dbflow.kotlinextensions
import com.raizlabs.android.dbflow.annotation.Collate
import com.raizlabs.android.dbflow.sql.language.NameAlias
import com.raizlabs.android.dbflow.sql.language.Operator
import com.raizlabs.android.dbflow.sql.language.OperatorGroup
import com.raizlabs.android.dbflow.sql.language.OperatorGroup.clause
import com.raizlabs.android.dbflow.sql.language.SQLOperator

fun SQLOperator.clause() = OperatorGroup.clause(this)

fun <T : Any> NameAlias.op() = Operator.op<T>(this)

Expand All @@ -29,3 +31,10 @@ infix fun <T : Any> Operator<T>.andAll(sqlOperator: Collection<SQLOperator>) = c

infix fun <T : Any> Operator<T>.orAll(sqlOperator: Collection<SQLOperator>) = clause(this).orAll(sqlOperator)

infix fun OperatorGroup.and(sqlOperator: SQLOperator) = and(sqlOperator)

infix fun OperatorGroup.or(sqlOperator: SQLOperator) = or(sqlOperator)

infix fun OperatorGroup.and(sqlOperator: OperatorGroup) = clause().and(sqlOperator)

infix fun OperatorGroup.or(sqlOperator: OperatorGroup) = clause().or(sqlOperator)
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.raizlabs.android.dbflow.kotlinextensions

import com.raizlabs.android.dbflow.sql.language.property.Property
import com.raizlabs.android.dbflow.sql.language.property.PropertyFactory.from
import com.raizlabs.android.dbflow.sql.queriable.ModelQueriable
import kotlin.reflect.KClass

/**
* Description: Provides some very nice Property class extensions.
Expand Down Expand Up @@ -34,4 +36,6 @@ val <T : Any> T?.property
val <T : Any> ModelQueriable<T>.property
get() = from(this)

inline fun <reified T : Any> propertyString(stringRepresentation: String?) = from(T::class.java, stringRepresentation)
inline fun <reified T : Any> propertyString(stringRepresentation: String?) = from(T::class.java, stringRepresentation)

inline fun <reified T : Any> KClass<T>.allProperty() = Property.allProperty(this.java)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ package com.raizlabs.android.dbflow.processor
import com.google.common.collect.Lists
import com.google.common.collect.Maps
import com.google.common.collect.Sets
import com.raizlabs.android.dbflow.processor.definition.*
import com.raizlabs.android.dbflow.processor.definition.BaseTableDefinition
import com.raizlabs.android.dbflow.processor.definition.ContentProviderDefinition
import com.raizlabs.android.dbflow.processor.definition.DatabaseDefinition
import com.raizlabs.android.dbflow.processor.definition.DatabaseHolderDefinition
import com.raizlabs.android.dbflow.processor.definition.DatabaseObjectHolder
import com.raizlabs.android.dbflow.processor.definition.ManyToManyDefinition
import com.raizlabs.android.dbflow.processor.definition.MigrationDefinition
import com.raizlabs.android.dbflow.processor.definition.ModelViewDefinition
import com.raizlabs.android.dbflow.processor.definition.QueryModelDefinition
import com.raizlabs.android.dbflow.processor.definition.TableDefinition
import com.raizlabs.android.dbflow.processor.definition.TableEndpointDefinition
import com.raizlabs.android.dbflow.processor.definition.TypeConverterDefinition
import com.raizlabs.android.dbflow.processor.utils.WriterUtils
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.JavaFile
Expand Down Expand Up @@ -209,7 +220,7 @@ class ProcessorManager internal constructor(val processingEnvironment: Processin

fun logError(error: String?, vararg args: Any?) = logError(callingClass = null, error = error, args = args)

fun logWarning(error: String, vararg args: Any) {
fun logWarning(error: String?, vararg args: Any) {
messager.printMessage(Diagnostic.Kind.WARNING, String.format("*==========*\n$error\n*==========*", *args))
}

Expand Down Expand Up @@ -317,18 +328,16 @@ class ProcessorManager internal constructor(val processingEnvironment: Processin

}

if (roundEnvironment.processingOver()) {
try {
val databaseHolderDefinition = DatabaseHolderDefinition(processorManager)
if (!databaseHolderDefinition.isGarbage()) {
JavaFile.builder(ClassNames.FLOW_MANAGER_PACKAGE,
databaseHolderDefinition.typeSpec).build()
.writeTo(processorManager.processingEnvironment.filer)
}
} catch (e: IOException) {
logError(e.message)
try {
val databaseHolderDefinition = DatabaseHolderDefinition(processorManager)
if (!databaseHolderDefinition.isGarbage()) {
JavaFile.builder(ClassNames.FLOW_MANAGER_PACKAGE,
databaseHolderDefinition.typeSpec).build()
.writeTo(processorManager.processingEnvironment.filer)
}

} catch (e: FilerException) {
} catch (e: IOException) {
logError(e.message)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ProcessorUtils {
val typeElement = processingEnvironment.elementUtils.getTypeElement(fqTn)
if (typeElement == null) {
processingEnvironment.messager.printMessage(Diagnostic.Kind.ERROR,
"Type Element was null for: $fqTn ensure that the visibility of the class is not private.")
"Type Element was null for: $fqTn ensure that the visibility of the class is not private.")
return false
} else {
val classMirror: TypeMirror? = typeElement.asType().erasure()
Expand Down Expand Up @@ -67,14 +67,12 @@ object ProcessorUtils {
}

fun fromTypeMirror(typeMirror: TypeMirror, processorManager: ProcessorManager): ClassName? {
var className: ClassName? = null
val element = getTypeElement(typeMirror)
if (element != null) {
className = ClassName.get(element)
return if (element != null) {
ClassName.get(element)
} else {
className = ElementUtility.getClassName(typeMirror.toString(), processorManager)
ElementUtility.getClassName(typeMirror.toString(), processorManager)
}
return className
}

fun getTypeElement(element: Element): TypeElement? {
Expand All @@ -100,7 +98,7 @@ object ProcessorUtils {
fun ensureVisibleStatic(element: Element, typeElement: TypeElement,
name: String) {
if (element.modifiers.contains(Modifier.PRIVATE)
|| element.modifiers.contains(Modifier.PROTECTED)) {
|| element.modifiers.contains(Modifier.PROTECTED)) {
manager.logError("$name must be visible from: " + typeElement)
}
if (!element.modifiers.contains(Modifier.STATIC)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,8 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab
val columnDefinition = ColumnDefinition(manager, variableElement, this, isPackagePrivateNotInSamePackage)
if (columnValidator.validate(manager, columnDefinition)) {
columnDefinitions.add(columnDefinition)

if (isPackagePrivate) {
columnDefinitions.add(columnDefinition)
packagePrivateList.add(columnDefinition)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class TableEndpointDefinition(typeElement: Element, processorManager: ProcessorM
notifyDefinitionList = arrayListOf()
methodListMap.put(notifyDefinition.method, notifyDefinitionList)
}
notifyDefinitionList!!.add(notifyDefinition)
notifyDefinitionList.add(notifyDefinition)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ abstract class ColumnAccessCombiner(val combiner: Combiner) {
fieldAccess = CodeBlock.of("${nameAllocator.newName(customPrefixName)}ref" + fieldLevelAccessor.propertyName)

if (defineProperty) {
existingBuilder.addStatement("\$T \$L = \$L != null ? \$L : null",
wrapperFieldTypeName, fieldAccess,
fieldLevelAccessor.get(modelBlock),
wrapperLevelAccessor.get(fieldLevelAccessor.get(modelBlock)))
val fieldAccessorBlock = fieldLevelAccessor.get(modelBlock)
val wrapperAccessorBlock = wrapperLevelAccessor.get(fieldAccessorBlock)
// if same, don't extra null check.
if (fieldLevelAccessor.toString() != wrapperLevelAccessor.toString()) {
existingBuilder.addStatement("\$T \$L = \$L != null ? \$L : null",
wrapperFieldTypeName, fieldAccess, fieldAccessorBlock, wrapperAccessorBlock)
} else {
existingBuilder.addStatement("\$T \$L = \$L", wrapperFieldTypeName,
fieldAccess, fieldAccessorBlock)
}
}
} else {
if (useWrapper && wrapperLevelAccessor != null) {
Expand Down Expand Up @@ -101,9 +107,9 @@ class ExistenceAccessCombiner(combiner: Combiner,
}

add("\$T.selectCountOf()\n.from(\$T.class)\n" +
".where(getPrimaryConditionClause(\$L))\n" +
".hasData(wrapper)",
ClassNames.SQLITE, tableClassName, modelBlock)
".where(getPrimaryConditionClause(\$L))\n" +
".hasData(wrapper)",
ClassNames.SQLITE, tableClassName, modelBlock)
}
add(";\n")
}
Expand All @@ -128,11 +134,18 @@ class ContentValuesCombiner(combiner: Combiner)
if (subWrapperAccessor != null) {
subWrapperFieldAccess = subWrapperAccessor.get(storedFieldAccess)
}
statement("values.put(\$S, \$L != null ? \$L : \$L)",
QueryBuilder.quote(columnRepresentation), storedFieldAccess, subWrapperFieldAccess, defaultValue)
if (storedFieldAccess.toString() != subWrapperFieldAccess.toString()
|| defaultValue.toString() != "null") {
statement("values.put(\$S, \$L != null ? \$L : \$L)",
QueryBuilder.quote(columnRepresentation), storedFieldAccess, subWrapperFieldAccess, defaultValue)
} else {
// if same default value is null and object reference is same as subwrapper.
statement("values.put(\$S, \$L)",
QueryBuilder.quote(columnRepresentation), storedFieldAccess)
}
} else {
statement("values.put(\$S, \$L)",
QueryBuilder.quote(columnRepresentation), fieldAccess)
QueryBuilder.quote(columnRepresentation), fieldAccess)
}
}
}
Expand All @@ -150,7 +163,7 @@ class SqliteStatementAccessCombiner(combiner: Combiner)
modelBlock: CodeBlock, defineProperty: Boolean) {
combiner.apply {
val fieldAccess: CodeBlock = getFieldAccessBlock(this@addCode, modelBlock,
defineProperty = defineProperty)
defineProperty = defineProperty)
val wrapperMethod = SQLiteHelper.getWrapperMethod(wrapperFieldTypeName ?: fieldTypeName)
val statementMethod = SQLiteHelper[fieldTypeName].sqLiteStatementMethod

Expand Down Expand Up @@ -205,30 +218,30 @@ class LoadFromCursorAccessCombiner(combiner: Combiner,
if (!orderedCursorLookup) {
indexName = CodeBlock.of(nameAllocator.newName("index_$columnRepresentation", columnRepresentation))
statement("\$T \$L = cursor.getColumnIndex(\$S)", Int::class.java, indexName,
columnRepresentation)
columnRepresentation)
beginControlFlow("if (\$1L != -1 && !cursor.isNull(\$1L))", indexName)
} else {
beginControlFlow("if (!cursor.isNull(\$1L))", index)
}
val cursorAccess = CodeBlock.of("cursor.\$L(\$L)",
SQLiteHelper.getMethod(wrapperFieldTypeName ?: fieldTypeName), indexName)
SQLiteHelper.getMethod(wrapperFieldTypeName ?: fieldTypeName), indexName)
// special case where we need to append try catch hack
val isEnum = wrapperLevelAccessor is EnumColumnAccessor
if (isEnum) {
beginControlFlow("try")
}
if (subWrapperAccessor != null) {
statement(fieldLevelAccessor.set(
wrapperLevelAccessor.set(subWrapperAccessor.set(cursorAccess)), modelBlock))
wrapperLevelAccessor.set(subWrapperAccessor.set(cursorAccess)), modelBlock))
} else {
statement(fieldLevelAccessor.set(
wrapperLevelAccessor.set(cursorAccess), modelBlock))
wrapperLevelAccessor.set(cursorAccess), modelBlock))
}
if (isEnum) {
catch(IllegalArgumentException::class) {
if (assignDefaultValuesFromCursor) {
statement(fieldLevelAccessor.set(wrapperLevelAccessor.set(defaultValue,
isDefault = true), modelBlock))
isDefault = true), modelBlock))
} else {
statement(fieldLevelAccessor.set(defaultValue, modelBlock))
}
Expand All @@ -237,7 +250,7 @@ class LoadFromCursorAccessCombiner(combiner: Combiner,
if (assignDefaultValuesFromCursor) {
nextControlFlow("else")
statement(fieldLevelAccessor.set(wrapperLevelAccessor.set(defaultValue,
isDefault = true), modelBlock))
isDefault = true), modelBlock))
}
endControlFlow()
} else {
Expand All @@ -249,7 +262,7 @@ class LoadFromCursorAccessCombiner(combiner: Combiner,
hasDefault = true // force a null on it.
}
val cursorAccess = CodeBlock.of("cursor.\$LOrDefault(\$L${if (hasDefault) ", $defaultValueBlock" else ""})",
SQLiteHelper.getMethod(wrapperFieldTypeName ?: fieldTypeName), indexName)
SQLiteHelper.getMethod(wrapperFieldTypeName ?: fieldTypeName), indexName)
statement(fieldLevelAccessor.set(cursorAccess, modelBlock))
}
}
Expand All @@ -263,13 +276,13 @@ class PrimaryReferenceAccessCombiner(combiner: Combiner)
modelBlock: CodeBlock, defineProperty: Boolean) {
val wrapperLevelAccessor = this@PrimaryReferenceAccessCombiner.combiner.wrapperLevelAccessor
statement("clause.and(\$L.\$Leq(\$L))", columnRepresentation,
if (!wrapperLevelAccessor.isPrimitiveTarget()) "invertProperty()." else "",
getFieldAccessBlock(this, modelBlock, wrapperLevelAccessor !is BooleanColumnAccessor))
if (!wrapperLevelAccessor.isPrimitiveTarget()) "invertProperty()." else "",
getFieldAccessBlock(this, modelBlock, wrapperLevelAccessor !is BooleanColumnAccessor))
}

override fun addNull(code: CodeBlock.Builder, columnRepresentation: String, index: Int) {
code.addStatement("clause.and(\$L.eq((\$T) \$L))", columnRepresentation,
ClassNames.ICONDITIONAL, "null")
ClassNames.ICONDITIONAL, "null")
}
}

Expand Down Expand Up @@ -311,7 +324,7 @@ class SaveModelAccessCombiner(combiner: Combiner,
statement("$access.save(${wrapperIfBaseModel(extendsBaseModel)})")
} else {
statement("\$T.getModelAdapter(\$T.class).save($access, ${ModelUtils.wrapper})",
ClassNames.FLOW_MANAGER, fieldTypeName)
ClassNames.FLOW_MANAGER, fieldTypeName)
}
}.end()
}
Expand All @@ -332,7 +345,7 @@ class DeleteModelAccessCombiner(combiner: Combiner,
statement("$access.delete(${wrapperIfBaseModel(extendsBaseModel)})")
} else {
statement("\$T.getModelAdapter(\$T.class).delete($access, ${ModelUtils.wrapper})",
ClassNames.FLOW_MANAGER, fieldTypeName)
ClassNames.FLOW_MANAGER, fieldTypeName)
}
}.end()
}
Expand Down
Loading

0 comments on commit 38fe8f0

Please sign in to comment.