Skip to content

Commit 660fc6f

Browse files
authored
Merge pull request #1068 from Raizlabs/develop
4.0.0-beta2
2 parents 530cd6c + a59c527 commit 660fc6f

File tree

57 files changed

+590
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+590
-254
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ DBFlow is built from a collection of the best features of many database librarie
2020

2121
# Changelog
2222

23-
Starting with 3.0.0-beta1+, Changes exist in the [releases tab](https://github.com/Raizlabs/DBFlow/releases).
24-
25-
For pre-3.0 changes, check out [here](https://github.com/Raizlabs/DBFlow/wiki)
23+
Changes exist in the [releases tab](https://github.com/Raizlabs/DBFlow/releases).
2624

2725
# Usage Docs
2826
For more detailed usage, check out it out [here](/usage2/Intro.md)
@@ -57,7 +55,7 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl
5755
5856
apply plugin: 'com.neenbedankt.android-apt'
5957
60-
def dbflow_version = "4.0.0-beta1"
58+
def dbflow_version = "4.0.0-beta2"
6159
// or dbflow_version = "develop-SNAPSHOT" for grabbing latest dependency in your project on the develop branch
6260
// or 10-digit short-hash of a specific commit. (Useful for bugs fixed in develop, but not in a release yet)
6361

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
jcenter()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:2.1.3'
6+
classpath 'com.android.tools.build:gradle:2.2.2'
77
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
88
}
99
}

dbflow-core/src/main/java/com/raizlabs/android/dbflow/annotation/Database.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
String name() default "";
3232

3333
/**
34-
* In order to use Foreign keys, set this to true.
35-
*
36-
* @return if key constraints are enabled.
34+
* @return If true, SQLite will throw exceptions when {@link ForeignKey} constraints are not respected.
35+
* Default is false and will not throw exceptions.
3736
*/
38-
boolean foreignKeysSupported() default false;
37+
boolean foreignKeyConstraintsEnforced() default false;
3938

4039
/**
4140
* @return Checks for consistency in the DB, if true it will recopy over the prepackage database.

dbflow-core/src/main/java/com/raizlabs/android/dbflow/annotation/OneToMany.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Description: Describes a 1-many relationship. It applies to some method that returns a {@link List} of Model objects.
1111
* This annotation can handle loading, deleting, and saving when the current data changes. By default it will call the
12-
* associated method when the
12+
* associated method when the containing class operates.
1313
*/
1414
@Target(ElementType.METHOD)
1515
@Retention(RetentionPolicy.SOURCE)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.raizlabs.android.dbflow.converter;
2+
3+
import java.math.BigDecimal;
4+
5+
/**
6+
* Description: Defines how we store and retrieve a {@link java.math.BigDecimal}
7+
*/
8+
public class BigDecimalConverter extends TypeConverter<String, BigDecimal> {
9+
@Override
10+
public String getDBValue(BigDecimal model) {
11+
return model == null ? null : model.toString();
12+
}
13+
14+
@Override
15+
public BigDecimal getModelValue(String data) {
16+
return data == null ? null : new BigDecimal(data);
17+
}
18+
}

dbflow-kotlinextensions/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ repositories {
99
}
1010

1111
android {
12-
compileSdkVersion 24
12+
compileSdkVersion 25
1313
buildToolsVersion dbflow_build_tools_version
1414

1515
defaultConfig {
1616
minSdkVersion 7
17-
targetSdkVersion 24
17+
targetSdkVersion 25
1818
}
1919
buildTypes {
2020
debug {

dbflow-processor/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sourceCompatibility = JavaVersion.VERSION_1_7
88

99
dependencies {
1010
compile project("${dbflow_project_prefix}dbflow-core")
11-
compile 'com.squareup:javapoet:1.7.0'
11+
compile 'com.squareup:javapoet:1.8.0'
1212
compile 'com.google.auto.service:auto-service:1.0-rc2'
1313
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
1414

dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/ClassNames.kt

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@ object ClassNames {
1515
val CONVERTER = BASE_PACKAGE + ".converter"
1616
val STRUCTURE = BASE_PACKAGE + ".structure"
1717
val DATABASE = STRUCTURE + ".database"
18-
val CONTAINER = STRUCTURE + ".container"
1918
val SQL = BASE_PACKAGE + ".sql"
2019
val LANGUAGE = SQL + ".language"
2120
val QUERIABLE = SQL + ".queriable"
2221
val PROPERTY_PACKAGE = LANGUAGE + ".property"
2322
val CONFIG = BASE_PACKAGE + ".config"
24-
val BUILDER = SQL + ".builder"
2523
val MIGRATION_PACKAGE = SQL + ".migration"
2624
val LISTENER = STRUCTURE + ".listener"
2725
val RUNTIME = BASE_PACKAGE + ".runtime"
2826
val TRANSACTION = RUNTIME + ".transaction"
29-
val DATABASE_TRANSACTION = DATABASE + ".transaction"
30-
val PROCESS = TRANSACTION + ".process"
3127
val SAVEABLE = SQL + ".saveable"
3228

3329
val DATABASE_HOLDER = ClassName.get(CONFIG, "DatabaseHolder")
@@ -47,20 +43,13 @@ object ClassNames {
4743
val MODEL_VIEW_ADAPTER = ClassName.get(STRUCTURE, "ModelViewAdapter")
4844
val MODEL_VIEW = ClassName.get(STRUCTURE, "BaseModelView")
4945

50-
val FLOW_SQLITE_OPEN_HELPER = ClassName.get(DATABASE, "FlowSQLiteOpenHelper")
5146
val DATABASE_STATEMENT = ClassName.get(DATABASE, "DatabaseStatement")
52-
val OPEN_HELPER = ClassName.get(DATABASE, "OpenHelper")
5347

54-
val CONDITION_QUERY_BUILDER = ClassName.get(BUILDER, "ConditionQueryBuilder")
55-
val CONDITION = ClassName.get(BUILDER, "Condition")
56-
57-
val SQL_UTILS = ClassName.get(SQL, "SqlUtils")
5848
val QUERY = ClassName.get(SQL, "Query")
5949

6050
val TYPE_CONVERTER = ClassName.get(CONVERTER, "TypeConverter")
61-
val PROCESS_MODEL_INFO = ClassName.get(PROCESS, "ProcessModelInfo")
62-
63-
val FLOW_MANAGER_STATIC_INTERFACE = ClassName.get(FLOW_MANAGER_PACKAGE, "DatabaseHolder")
51+
val TYPE_CONVERTER_GETTER: ClassName = ClassName.get(PROPERTY_PACKAGE,
52+
"TypeConvertedProperty.TypeConverterGetter")
6453

6554
val MIGRATION = ClassName.get(MIGRATION_PACKAGE, "Migration")
6655

@@ -71,30 +60,19 @@ object ClassNames {
7160
val SQLITE_STATEMENT_LISTENER = ClassName.get(LISTENER, "SQLiteStatementListener")
7261

7362

74-
val DELETE_MODEL_LIST_TRANSACTION = ClassName.get(PROCESS, "DeleteModelListTransaction")
75-
val SAVE_MODEL_LIST_TRANSACTION = ClassName.get(PROCESS, "SaveModelTransaction")
76-
val UPDATE_MODEL_LIST_TRANSACTION = ClassName.get(PROCESS, "UpdateModelListTransaction")
77-
val INSERT_MODEL_LIST_TRANSACTION = ClassName.get(PROCESS, "InsertModelTransaction")
78-
7963
val PROPERTY = ClassName.get(PROPERTY_PACKAGE, "Property")
8064
val TYPE_CONVERTED_PROPERTY = ClassName.get(PROPERTY_PACKAGE, "TypeConvertedProperty")
65+
val WRAPPER_PROPERTY = ClassName.get(PROPERTY_PACKAGE, "WrapperProperty")
8166

8267
val IPROPERTY = ClassName.get(PROPERTY_PACKAGE, "IProperty")
8368
val BASE_PROPERTY = ClassName.get(PROPERTY_PACKAGE, "BaseProperty")
8469
val INDEX_PROPERTY = ClassName.get(PROPERTY_PACKAGE, "IndexProperty")
8570
val CONDITION_GROUP = ClassName.get(LANGUAGE, "ConditionGroup")
86-
val SELECT = ClassName.get(LANGUAGE, "Select")
87-
val UPDATE = ClassName.get(LANGUAGE, "Update")
88-
val DELETE = ClassName.get(LANGUAGE, "Delete")
89-
val METHOD = ClassName.get(LANGUAGE, "Method")
9071

9172
val ICONDITIONAL = ClassName.get(LANGUAGE, "IConditional")
9273

9374
val BASE_CONTENT_PROVIDER = ClassName.get(RUNTIME, "BaseContentProvider")
94-
val PROPERTY_CONVERTER = ClassName.get(RUNTIME + ".BaseContentProvider", "PropertyConverter")
9575

96-
val MODEL_CONTAINER_UTILS = ClassName.get(CONTAINER, "ModelContainerUtils")
97-
val MODEL_CONTAINER_ADAPTER = ClassName.get(CONTAINER, "ModelContainerAdapter")
9876
val BASE_MODEL = ClassName.get(STRUCTURE, "BaseModel")
9977
val MODEL_CACHE = ClassName.get(STRUCTURE + ".cache", "ModelCache")
10078
val MULTI_KEY_CACHE_CONVERTER = ClassName.get(STRUCTURE + ".cache", "IMultiKeyCacheConverter")
@@ -106,11 +84,8 @@ object ClassNames {
10684

10785
val DATABASE_WRAPPER = ClassName.get(DATABASE, "DatabaseWrapper")
10886

109-
val ORDER_BY = ClassName.get(LANGUAGE, "OrderBy")
11087
val SQLITE = ClassName.get(LANGUAGE, "SQLite")
11188

112-
val UNSAFE_STRING_CONDITION = ClassName.get(LANGUAGE, "UnSafeStringCondition")
113-
11489
val CACHEABLE_LIST_MODEL_SAVER = ClassName.get(SAVEABLE, "CacheableListModelSaver")
11590

11691
val SINGLE_KEY_CACHEABLE_MODEL_LOADER = ClassName.get(QUERIABLE, "SingleKeyCacheableModelLoader")

dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/Handlers.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class TypeConverterHandler : BaseContainerHandler<TypeConverter>() {
158158
companion object {
159159
private val VALIDATOR = TypeConverterValidator()
160160
private val DEFAULT_TYPE_CONVERTERS = arrayOf<Class<*>>(CalendarConverter::class.java,
161+
BigDecimalConverter::class.java,
161162
DateConverter::class.java, SqlDateConverter::class.java,
162163
BooleanConverter::class.java, UUIDConverter::class.java)
163164
}

dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/ProcessorManager.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ class ProcessorManager internal constructor(val processingEnvironment: Processin
245245
try {
246246

247247
if (databaseHolderDefinition.databaseDefinition == null) {
248-
manager.logError("Found null db with: %1s tables, %1s modelviews. " + "Attempt to rebuild project should fix this intermittant issue.",
249-
databaseHolderDefinition.tableNameMap.values.size,
250-
databaseHolderDefinition.modelViewDefinitionMap.values.size)
248+
manager.logError("Found null db with: ${databaseHolderDefinition.tableNameMap.values.size} tables," +
249+
" ${databaseHolderDefinition.modelViewDefinitionMap.values.size} modelviews. " +
250+
"Attempt to rebuild project should fix this intermittant issue.")
251251
manager.logError("Found tables: " + databaseHolderDefinition.tableNameMap.values)
252252
continue
253253
}
@@ -266,12 +266,14 @@ class ProcessorManager internal constructor(val processingEnvironment: Processin
266266
continue
267267
}
268268

269-
val validator = ContentProviderValidator()
270-
val contentProviderDefinitions = databaseHolderDefinition.providerMap.values
271-
contentProviderDefinitions.forEach { contentProviderDefinition ->
272-
contentProviderDefinition.prepareForWrite()
273-
if (validator.validate(processorManager, contentProviderDefinition)) {
274-
WriterUtils.writeBaseDefinition(contentProviderDefinition, processorManager)
269+
if (roundEnvironment.processingOver()) {
270+
val validator = ContentProviderValidator()
271+
val contentProviderDefinitions = databaseHolderDefinition.providerMap.values
272+
contentProviderDefinitions.forEach { contentProviderDefinition ->
273+
contentProviderDefinition.prepareForWrite()
274+
if (validator.validate(processorManager, contentProviderDefinition)) {
275+
WriterUtils.writeBaseDefinition(contentProviderDefinition, processorManager)
276+
}
275277
}
276278
}
277279

dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/ContentProvider.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import com.raizlabs.android.dbflow.processor.ClassNames
99
import com.raizlabs.android.dbflow.processor.ProcessorManager
1010
import com.raizlabs.android.dbflow.processor.TableEndpointValidator
1111
import com.raizlabs.android.dbflow.processor.utils.controlFlow
12-
import com.raizlabs.android.dbflow.processor.utils.isNullOrEmpty
1312
import com.squareup.javapoet.*
1413
import javax.lang.model.element.*
1514
import javax.lang.model.type.MirroredTypeException
@@ -388,9 +387,6 @@ class ContentProviderDefinition(typeElement: Element, processorManager: Processo
388387

389388
override fun onWriteDefinition(typeBuilder: TypeSpec.Builder) {
390389

391-
typeBuilder.addField(FieldSpec.builder(ClassName.get(String::class.java), AUTHORITY,
392-
Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL).initializer("\$S", authority).build())
393-
394390
var code = 0
395391
for (endpointDefinition in endpointDefinitions) {
396392
endpointDefinition.contentUriDefinitions.forEach {
@@ -402,10 +398,20 @@ class ContentProviderDefinition(typeElement: Element, processorManager: Processo
402398
}
403399

404400
val uriField = FieldSpec.builder(ClassNames.URI_MATCHER, URI_MATCHER,
405-
Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
401+
Modifier.PRIVATE, Modifier.FINAL)
402+
.initializer("new \$T(\$T.NO_MATCH)", ClassNames.URI_MATCHER, ClassNames.URI_MATCHER)
406403

407-
val initializer = CodeBlock.builder().addStatement("new \$T(\$T.NO_MATCH)", ClassNames.URI_MATCHER,
408-
ClassNames.URI_MATCHER).add("static {\n")
404+
typeBuilder.addField(uriField.build())
405+
406+
val onCreate = MethodSpec.methodBuilder("onCreate")
407+
.addAnnotation(Override::class.java)
408+
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
409+
.returns(TypeName.BOOLEAN)
410+
.addStatement("final \$T $AUTHORITY = \$L", String::class.java,
411+
if (authority.contains("R.string."))
412+
"getContext().getString($authority)"
413+
else
414+
"\"$authority\"")
409415

410416
for (endpointDefinition in endpointDefinitions) {
411417
endpointDefinition.contentUriDefinitions.forEach {
@@ -416,12 +422,12 @@ class ContentProviderDefinition(typeElement: Element, processorManager: Processo
416422
path = CodeBlock.builder().add("\$L.\$L.getPath()", it.elementClassName,
417423
it.name).build().toString()
418424
}
419-
initializer.addStatement("\$L.addURI(\$L, \$L, \$L)", URI_MATCHER, AUTHORITY,
420-
path, it.name)
425+
onCreate.addStatement("\$L.addURI(\$L, \$L, \$L)", URI_MATCHER, AUTHORITY, path, it.name)
421426
}
422427
}
423-
initializer.add("}\n")
424-
typeBuilder.addField(uriField.initializer(initializer.build()).build())
428+
429+
onCreate.addStatement("return super.onCreate()")
430+
typeBuilder.addMethod(onCreate.build())
425431

426432
typeBuilder.addMethod(MethodSpec.methodBuilder("getDatabaseName")
427433
.addAnnotation(Override::class.java)

dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/DatabaseDefinition.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class DatabaseDefinition(manager: ProcessorManager, element: Element) : BaseDefi
6060
setOutputClassName(databaseName + classSeparator + "Database")
6161

6262
databaseVersion = database.version
63-
foreignKeysSupported = database.foreignKeysSupported
63+
foreignKeysSupported = database.foreignKeyConstraintsEnforced
6464

6565
insertConflict = database.insertConflict
6666
updateConflict = database.updateConflict

dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/ModelViewDefinition.kt

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.squareup.javapoet.*
1212
import javax.lang.model.element.Element
1313
import javax.lang.model.element.Modifier
1414
import javax.lang.model.element.TypeElement
15-
import javax.lang.model.type.DeclaredType
1615
import javax.lang.model.type.MirroredTypeException
1716

1817
/**
@@ -28,8 +27,6 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab
2827

2928
private var name: String? = null
3029

31-
private var modelReferenceClass: ClassName? = null
32-
3330
private val methods: Array<MethodDefinition>
3431

3532
var allFields: Boolean = false
@@ -55,24 +52,6 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab
5552
this.priority = modelView.priority
5653
}
5754

58-
var typeAdapterInterface: DeclaredType? = null
59-
val modelViewType = manager.typeUtils.getDeclaredType(
60-
manager.elements.getTypeElement(ClassNames.MODEL_VIEW.toString()),
61-
manager.typeUtils.getWildcardType(manager.elements.getTypeElement(ClassName.OBJECT.toString()).asType(), null))
62-
63-
64-
for (superType in manager.typeUtils.directSupertypes(element.asType())) {
65-
if (manager.typeUtils.isAssignable(superType, modelViewType)) {
66-
typeAdapterInterface = superType as DeclaredType
67-
break
68-
}
69-
}
70-
71-
if (typeAdapterInterface != null) {
72-
val typeArguments = typeAdapterInterface.typeArguments
73-
modelReferenceClass = ClassName.get(manager.elements.getTypeElement(typeArguments[0].toString()))
74-
}
75-
7655
if (element is TypeElement) {
7756
implementsLoadFromCursorListener = ProcessorUtils.implementsClass(manager.processingEnvironment,
7857
ClassNames.LOAD_FROM_CURSOR_LISTENER.toString(), element)
@@ -164,7 +143,7 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab
164143
get() = outputClassName
165144

166145
override val extendsClass: TypeName?
167-
get() = ParameterizedTypeName.get(ClassNames.MODEL_VIEW_ADAPTER, modelReferenceClass, elementClassName)
146+
get() = ParameterizedTypeName.get(ClassNames.MODEL_VIEW_ADAPTER, elementClassName)
168147

169148
override fun onWriteDefinition(typeBuilder: TypeSpec.Builder) {
170149

dbflow-processor/src/main/java/com/raizlabs/android/dbflow/processor/definition/column/ColumnAccessCombiner.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ class ExistenceAccessCombiner(combiner: Combiner,
7474
defaultValue: CodeBlock?, index: Int, modelBlock: CodeBlock) {
7575

7676
combiner.apply {
77-
val access = getFieldAccessBlock(code, modelBlock)
7877
if (autoRowId) {
78+
val access = getFieldAccessBlock(code, modelBlock)
79+
7980
code.add("return ")
8081

8182
if (!fieldTypeName.isPrimitive) {
@@ -215,13 +216,28 @@ class LoadFromCursorAccessCombiner(combiner: Combiner,
215216
val cursorAccess = CodeBlock.of("cursor.\$L(\$L)",
216217
SQLiteHelper.getMethod(wrapperFieldTypeName ?: fieldTypeName), indexName)
217218
if (wrapperLevelAccessor != null) {
219+
// special case where we need to append try catch hack
220+
val isEnum = wrapperLevelAccessor is EnumColumnAccessor
221+
if (isEnum) {
222+
code.beginControlFlow("try")
223+
}
218224
if (subWrapperAccessor != null) {
219225
code.addStatement(fieldLevelAccessor.set(
220226
wrapperLevelAccessor.set(subWrapperAccessor.set(cursorAccess)), modelBlock))
221227
} else {
222228
code.addStatement(fieldLevelAccessor.set(
223229
wrapperLevelAccessor.set(cursorAccess), modelBlock))
224230
}
231+
if (isEnum) {
232+
code.nextControlFlow("catch (\$T i)", IllegalArgumentException::class.java)
233+
if (assignDefaultValuesFromCursor) {
234+
code.addStatement(fieldLevelAccessor.set(wrapperLevelAccessor.set(defaultValue,
235+
isDefault = true), modelBlock))
236+
} else {
237+
code.addStatement(fieldLevelAccessor.set(defaultValue, modelBlock))
238+
}
239+
code.endControlFlow()
240+
}
225241
} else {
226242
code.addStatement(fieldLevelAccessor.set(cursorAccess, modelBlock))
227243
}
@@ -247,7 +263,7 @@ class PrimaryReferenceAccessCombiner(combiner: Combiner)
247263
modelBlock: CodeBlock) {
248264
val wrapperLevelAccessor = this.combiner.wrapperLevelAccessor
249265
code.addStatement("clause.and(\$L.\$Leq(\$L))", columnRepresentation,
250-
if (!wrapperLevelAccessor.isPrimitiveTarget()) "databaseProperty()." else "",
266+
if (!wrapperLevelAccessor.isPrimitiveTarget()) "invertProperty()." else "",
251267
getFieldAccessBlock(code, modelBlock, wrapperLevelAccessor !is BooleanColumnAccessor))
252268
}
253269

0 commit comments

Comments
 (0)