Skip to content

Commit

Permalink
Merge pull request #1068 from Raizlabs/develop
Browse files Browse the repository at this point in the history
4.0.0-beta2
  • Loading branch information
agrosner authored Nov 13, 2016
2 parents 530cd6c + a59c527 commit 660fc6f
Show file tree
Hide file tree
Showing 57 changed files with 590 additions and 254 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ DBFlow is built from a collection of the best features of many database librarie

# Changelog

Starting with 3.0.0-beta1+, Changes exist in the [releases tab](https://github.com/Raizlabs/DBFlow/releases).

For pre-3.0 changes, check out [here](https://github.com/Raizlabs/DBFlow/wiki)
Changes exist in the [releases tab](https://github.com/Raizlabs/DBFlow/releases).

# Usage Docs
For more detailed usage, check out it out [here](/usage2/Intro.md)
Expand Down Expand Up @@ -57,7 +55,7 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl
apply plugin: 'com.neenbedankt.android-apt'
def dbflow_version = "4.0.0-beta1"
def dbflow_version = "4.0.0-beta2"
// 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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
String name() default "";

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

/**
* @return Checks for consistency in the DB, if true it will recopy over the prepackage database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Description: Describes a 1-many relationship. It applies to some method that returns a {@link List} of Model objects.
* This annotation can handle loading, deleting, and saving when the current data changes. By default it will call the
* associated method when the
* associated method when the containing class operates.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.raizlabs.android.dbflow.converter;

import java.math.BigDecimal;

/**
* Description: Defines how we store and retrieve a {@link java.math.BigDecimal}
*/
public class BigDecimalConverter extends TypeConverter<String, BigDecimal> {
@Override
public String getDBValue(BigDecimal model) {
return model == null ? null : model.toString();
}

@Override
public BigDecimal getModelValue(String data) {
return data == null ? null : new BigDecimal(data);
}
}
4 changes: 2 additions & 2 deletions dbflow-kotlinextensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ repositories {
}

android {
compileSdkVersion 24
compileSdkVersion 25
buildToolsVersion dbflow_build_tools_version

defaultConfig {
minSdkVersion 7
targetSdkVersion 24
targetSdkVersion 25
}
buildTypes {
debug {
Expand Down
2 changes: 1 addition & 1 deletion dbflow-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sourceCompatibility = JavaVersion.VERSION_1_7

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@ object ClassNames {
val CONVERTER = BASE_PACKAGE + ".converter"
val STRUCTURE = BASE_PACKAGE + ".structure"
val DATABASE = STRUCTURE + ".database"
val CONTAINER = STRUCTURE + ".container"
val SQL = BASE_PACKAGE + ".sql"
val LANGUAGE = SQL + ".language"
val QUERIABLE = SQL + ".queriable"
val PROPERTY_PACKAGE = LANGUAGE + ".property"
val CONFIG = BASE_PACKAGE + ".config"
val BUILDER = SQL + ".builder"
val MIGRATION_PACKAGE = SQL + ".migration"
val LISTENER = STRUCTURE + ".listener"
val RUNTIME = BASE_PACKAGE + ".runtime"
val TRANSACTION = RUNTIME + ".transaction"
val DATABASE_TRANSACTION = DATABASE + ".transaction"
val PROCESS = TRANSACTION + ".process"
val SAVEABLE = SQL + ".saveable"

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

val FLOW_SQLITE_OPEN_HELPER = ClassName.get(DATABASE, "FlowSQLiteOpenHelper")
val DATABASE_STATEMENT = ClassName.get(DATABASE, "DatabaseStatement")
val OPEN_HELPER = ClassName.get(DATABASE, "OpenHelper")

val CONDITION_QUERY_BUILDER = ClassName.get(BUILDER, "ConditionQueryBuilder")
val CONDITION = ClassName.get(BUILDER, "Condition")

val SQL_UTILS = ClassName.get(SQL, "SqlUtils")
val QUERY = ClassName.get(SQL, "Query")

val TYPE_CONVERTER = ClassName.get(CONVERTER, "TypeConverter")
val PROCESS_MODEL_INFO = ClassName.get(PROCESS, "ProcessModelInfo")

val FLOW_MANAGER_STATIC_INTERFACE = ClassName.get(FLOW_MANAGER_PACKAGE, "DatabaseHolder")
val TYPE_CONVERTER_GETTER: ClassName = ClassName.get(PROPERTY_PACKAGE,
"TypeConvertedProperty.TypeConverterGetter")

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

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


val DELETE_MODEL_LIST_TRANSACTION = ClassName.get(PROCESS, "DeleteModelListTransaction")
val SAVE_MODEL_LIST_TRANSACTION = ClassName.get(PROCESS, "SaveModelTransaction")
val UPDATE_MODEL_LIST_TRANSACTION = ClassName.get(PROCESS, "UpdateModelListTransaction")
val INSERT_MODEL_LIST_TRANSACTION = ClassName.get(PROCESS, "InsertModelTransaction")

val PROPERTY = ClassName.get(PROPERTY_PACKAGE, "Property")
val TYPE_CONVERTED_PROPERTY = ClassName.get(PROPERTY_PACKAGE, "TypeConvertedProperty")
val WRAPPER_PROPERTY = ClassName.get(PROPERTY_PACKAGE, "WrapperProperty")

val IPROPERTY = ClassName.get(PROPERTY_PACKAGE, "IProperty")
val BASE_PROPERTY = ClassName.get(PROPERTY_PACKAGE, "BaseProperty")
val INDEX_PROPERTY = ClassName.get(PROPERTY_PACKAGE, "IndexProperty")
val CONDITION_GROUP = ClassName.get(LANGUAGE, "ConditionGroup")
val SELECT = ClassName.get(LANGUAGE, "Select")
val UPDATE = ClassName.get(LANGUAGE, "Update")
val DELETE = ClassName.get(LANGUAGE, "Delete")
val METHOD = ClassName.get(LANGUAGE, "Method")

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

val BASE_CONTENT_PROVIDER = ClassName.get(RUNTIME, "BaseContentProvider")
val PROPERTY_CONVERTER = ClassName.get(RUNTIME + ".BaseContentProvider", "PropertyConverter")

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

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

val ORDER_BY = ClassName.get(LANGUAGE, "OrderBy")
val SQLITE = ClassName.get(LANGUAGE, "SQLite")

val UNSAFE_STRING_CONDITION = ClassName.get(LANGUAGE, "UnSafeStringCondition")

val CACHEABLE_LIST_MODEL_SAVER = ClassName.get(SAVEABLE, "CacheableListModelSaver")

val SINGLE_KEY_CACHEABLE_MODEL_LOADER = ClassName.get(QUERIABLE, "SingleKeyCacheableModelLoader")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class TypeConverterHandler : BaseContainerHandler<TypeConverter>() {
companion object {
private val VALIDATOR = TypeConverterValidator()
private val DEFAULT_TYPE_CONVERTERS = arrayOf<Class<*>>(CalendarConverter::class.java,
BigDecimalConverter::class.java,
DateConverter::class.java, SqlDateConverter::class.java,
BooleanConverter::class.java, UUIDConverter::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ class ProcessorManager internal constructor(val processingEnvironment: Processin
try {

if (databaseHolderDefinition.databaseDefinition == null) {
manager.logError("Found null db with: %1s tables, %1s modelviews. " + "Attempt to rebuild project should fix this intermittant issue.",
databaseHolderDefinition.tableNameMap.values.size,
databaseHolderDefinition.modelViewDefinitionMap.values.size)
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 tables: " + databaseHolderDefinition.tableNameMap.values)
continue
}
Expand All @@ -266,12 +266,14 @@ class ProcessorManager internal constructor(val processingEnvironment: Processin
continue
}

val validator = ContentProviderValidator()
val contentProviderDefinitions = databaseHolderDefinition.providerMap.values
contentProviderDefinitions.forEach { contentProviderDefinition ->
contentProviderDefinition.prepareForWrite()
if (validator.validate(processorManager, contentProviderDefinition)) {
WriterUtils.writeBaseDefinition(contentProviderDefinition, processorManager)
if (roundEnvironment.processingOver()) {
val validator = ContentProviderValidator()
val contentProviderDefinitions = databaseHolderDefinition.providerMap.values
contentProviderDefinitions.forEach { contentProviderDefinition ->
contentProviderDefinition.prepareForWrite()
if (validator.validate(processorManager, contentProviderDefinition)) {
WriterUtils.writeBaseDefinition(contentProviderDefinition, processorManager)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.raizlabs.android.dbflow.processor.ClassNames
import com.raizlabs.android.dbflow.processor.ProcessorManager
import com.raizlabs.android.dbflow.processor.TableEndpointValidator
import com.raizlabs.android.dbflow.processor.utils.controlFlow
import com.raizlabs.android.dbflow.processor.utils.isNullOrEmpty
import com.squareup.javapoet.*
import javax.lang.model.element.*
import javax.lang.model.type.MirroredTypeException
Expand Down Expand Up @@ -388,9 +387,6 @@ class ContentProviderDefinition(typeElement: Element, processorManager: Processo

override fun onWriteDefinition(typeBuilder: TypeSpec.Builder) {

typeBuilder.addField(FieldSpec.builder(ClassName.get(String::class.java), AUTHORITY,
Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL).initializer("\$S", authority).build())

var code = 0
for (endpointDefinition in endpointDefinitions) {
endpointDefinition.contentUriDefinitions.forEach {
Expand All @@ -402,10 +398,20 @@ class ContentProviderDefinition(typeElement: Element, processorManager: Processo
}

val uriField = FieldSpec.builder(ClassNames.URI_MATCHER, URI_MATCHER,
Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
Modifier.PRIVATE, Modifier.FINAL)
.initializer("new \$T(\$T.NO_MATCH)", ClassNames.URI_MATCHER, ClassNames.URI_MATCHER)

val initializer = CodeBlock.builder().addStatement("new \$T(\$T.NO_MATCH)", ClassNames.URI_MATCHER,
ClassNames.URI_MATCHER).add("static {\n")
typeBuilder.addField(uriField.build())

val onCreate = MethodSpec.methodBuilder("onCreate")
.addAnnotation(Override::class.java)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.returns(TypeName.BOOLEAN)
.addStatement("final \$T $AUTHORITY = \$L", String::class.java,
if (authority.contains("R.string."))
"getContext().getString($authority)"
else
"\"$authority\"")

for (endpointDefinition in endpointDefinitions) {
endpointDefinition.contentUriDefinitions.forEach {
Expand All @@ -416,12 +422,12 @@ class ContentProviderDefinition(typeElement: Element, processorManager: Processo
path = CodeBlock.builder().add("\$L.\$L.getPath()", it.elementClassName,
it.name).build().toString()
}
initializer.addStatement("\$L.addURI(\$L, \$L, \$L)", URI_MATCHER, AUTHORITY,
path, it.name)
onCreate.addStatement("\$L.addURI(\$L, \$L, \$L)", URI_MATCHER, AUTHORITY, path, it.name)
}
}
initializer.add("}\n")
typeBuilder.addField(uriField.initializer(initializer.build()).build())

onCreate.addStatement("return super.onCreate()")
typeBuilder.addMethod(onCreate.build())

typeBuilder.addMethod(MethodSpec.methodBuilder("getDatabaseName")
.addAnnotation(Override::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class DatabaseDefinition(manager: ProcessorManager, element: Element) : BaseDefi
setOutputClassName(databaseName + classSeparator + "Database")

databaseVersion = database.version
foreignKeysSupported = database.foreignKeysSupported
foreignKeysSupported = database.foreignKeyConstraintsEnforced

insertConflict = database.insertConflict
updateConflict = database.updateConflict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.squareup.javapoet.*
import javax.lang.model.element.Element
import javax.lang.model.element.Modifier
import javax.lang.model.element.TypeElement
import javax.lang.model.type.DeclaredType
import javax.lang.model.type.MirroredTypeException

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

private var name: String? = null

private var modelReferenceClass: ClassName? = null

private val methods: Array<MethodDefinition>

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

var typeAdapterInterface: DeclaredType? = null
val modelViewType = manager.typeUtils.getDeclaredType(
manager.elements.getTypeElement(ClassNames.MODEL_VIEW.toString()),
manager.typeUtils.getWildcardType(manager.elements.getTypeElement(ClassName.OBJECT.toString()).asType(), null))


for (superType in manager.typeUtils.directSupertypes(element.asType())) {
if (manager.typeUtils.isAssignable(superType, modelViewType)) {
typeAdapterInterface = superType as DeclaredType
break
}
}

if (typeAdapterInterface != null) {
val typeArguments = typeAdapterInterface.typeArguments
modelReferenceClass = ClassName.get(manager.elements.getTypeElement(typeArguments[0].toString()))
}

if (element is TypeElement) {
implementsLoadFromCursorListener = ProcessorUtils.implementsClass(manager.processingEnvironment,
ClassNames.LOAD_FROM_CURSOR_LISTENER.toString(), element)
Expand Down Expand Up @@ -164,7 +143,7 @@ class ModelViewDefinition(manager: ProcessorManager, element: Element) : BaseTab
get() = outputClassName

override val extendsClass: TypeName?
get() = ParameterizedTypeName.get(ClassNames.MODEL_VIEW_ADAPTER, modelReferenceClass, elementClassName)
get() = ParameterizedTypeName.get(ClassNames.MODEL_VIEW_ADAPTER, elementClassName)

override fun onWriteDefinition(typeBuilder: TypeSpec.Builder) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class ExistenceAccessCombiner(combiner: Combiner,
defaultValue: CodeBlock?, index: Int, modelBlock: CodeBlock) {

combiner.apply {
val access = getFieldAccessBlock(code, modelBlock)
if (autoRowId) {
val access = getFieldAccessBlock(code, modelBlock)

code.add("return ")

if (!fieldTypeName.isPrimitive) {
Expand Down Expand Up @@ -215,13 +216,28 @@ class LoadFromCursorAccessCombiner(combiner: Combiner,
val cursorAccess = CodeBlock.of("cursor.\$L(\$L)",
SQLiteHelper.getMethod(wrapperFieldTypeName ?: fieldTypeName), indexName)
if (wrapperLevelAccessor != null) {
// special case where we need to append try catch hack
val isEnum = wrapperLevelAccessor is EnumColumnAccessor
if (isEnum) {
code.beginControlFlow("try")
}
if (subWrapperAccessor != null) {
code.addStatement(fieldLevelAccessor.set(
wrapperLevelAccessor.set(subWrapperAccessor.set(cursorAccess)), modelBlock))
} else {
code.addStatement(fieldLevelAccessor.set(
wrapperLevelAccessor.set(cursorAccess), modelBlock))
}
if (isEnum) {
code.nextControlFlow("catch (\$T i)", IllegalArgumentException::class.java)
if (assignDefaultValuesFromCursor) {
code.addStatement(fieldLevelAccessor.set(wrapperLevelAccessor.set(defaultValue,
isDefault = true), modelBlock))
} else {
code.addStatement(fieldLevelAccessor.set(defaultValue, modelBlock))
}
code.endControlFlow()
}
} else {
code.addStatement(fieldLevelAccessor.set(cursorAccess, modelBlock))
}
Expand All @@ -247,7 +263,7 @@ class PrimaryReferenceAccessCombiner(combiner: Combiner)
modelBlock: CodeBlock) {
val wrapperLevelAccessor = this.combiner.wrapperLevelAccessor
code.addStatement("clause.and(\$L.\$Leq(\$L))", columnRepresentation,
if (!wrapperLevelAccessor.isPrimitiveTarget()) "databaseProperty()." else "",
if (!wrapperLevelAccessor.isPrimitiveTarget()) "invertProperty()." else "",
getFieldAccessBlock(code, modelBlock, wrapperLevelAccessor !is BooleanColumnAccessor))
}

Expand Down
Loading

0 comments on commit 660fc6f

Please sign in to comment.