Skip to content

Commit

Permalink
Merge pull request #1416 from Raizlabs/develop
Browse files Browse the repository at this point in the history
4.1.0
  • Loading branch information
agrosner authored Aug 27, 2017
2 parents 38fe8f0 + d1be504 commit bc1cf60
Show file tree
Hide file tree
Showing 125 changed files with 2,161 additions and 957 deletions.
14 changes: 7 additions & 7 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.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)
[![JitPack.io](https://img.shields.io/badge/JitPack.io-4.1.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)

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

Expand Down Expand Up @@ -41,14 +41,18 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl

```groovy
def dbflow_version = "4.0.5"
apply plugin: 'kotlin-kapt' // required for kotlin.
def dbflow_version = "4.1.0"
// 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)
dependencies {
// if Java use this. If using Kotlin do NOT use this.
annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
// use kapt for kotlin apt if you're a Kotlin user
// Use if Kotlin user.
kapt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
Expand All @@ -75,10 +79,6 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl
}
// if you're building with Kotlin
kapt {
generateStubs = true
}
```

# Pull Requests
Expand Down
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
buildscript {
ext.kotlin_version = '1.1.3-2'
ext.kotlin_version = '1.1.4-2'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
jcenter()
google()
maven { url "https://www.jitpack.io" }
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.raizlabs.android.dbflow.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Description: Maps an arbitrary object and its corresponding fields into a set of columns. It is similar
* to {@link ForeignKey} except it's not represented in the DB hierarchy.
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface ColumnMap {

/**
* Defines explicit references for a composite {@link ColumnMap} definition.
*
* @return override explicit usage of all fields and provide custom references.
*/
ColumnMapReference[] references() default {};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.raizlabs.android.dbflow.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Description: Allows a {@link ColumnMap} to specify a reference override for its fields. Anything not
* defined here will not be used.
*/
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.FIELD)
public @interface ColumnMapReference {

/**
* @return The local column name that will be referenced in the DB
*/
String columnName();

/**
* @return The column name in the referenced table
*/
String columnMapFieldName();

/**
* @return Specify the {@link NotNull} annotation here and it will get pasted into the reference definition.
*/
NotNull notNull() default @NotNull(onNullConflict = ConflictAction.NONE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@
int version();

/**
* @return The name of the DB. Optional as it will default to the class name.
* @deprecated use DatabaseConfig.databaseName() to change the name.
*/
@Deprecated
String name() default "";

/**
* @return Specify the extension of the file name : {fileName}.{extension}. Default is ".db"
* @deprecated use DatabaseConfig.extension() to change the extension.
*/
@Deprecated
String databaseExtension() default "";

/**
* @deprecated use DatabaseConfig.inMemoryBuilder() instead.
*/
@Deprecated
boolean inMemory() default false;

/**
* @return If true, SQLite will throw exceptions when {@link ForeignKey} constraints are not respected.
* Default is false and will not throw exceptions.
Expand All @@ -52,11 +60,6 @@
*/
boolean backupEnabled() default false;

/**
* @return true if you want it to be in-memory, false if not.
*/
boolean inMemory() default false;

/**
* @return Global default insert conflict that can be applied to any table when it leaves
* its {@link ConflictAction} as NONE.
Expand All @@ -72,6 +75,8 @@
/**
* @return Marks all generated classes within this database with this character. For example
* "TestTable" becomes "TestTable$Table" for a "$" separator.
* @deprecated Generated class files will become '_' only in next major release.
*/
@Deprecated
String generatedClassSeparator() default "_";
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
*/
String foreignKeyColumnName();

/**
* @return Specify the {@link NotNull} annotation here and it will get pasted into the reference definition.
*/
NotNull notNull() default @NotNull(onNullConflict = ConflictAction.NONE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ enum Method {
/**
* @return If true, the underlying variable that we use is private, requiring us to provide
* a setter for it.
* @deprecated has no effect on the visibility of the call since we now autodetect visibility.
*/
@Deprecated
boolean isVariablePrivate() default false;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
*/
boolean assignDefaultValuesFromCursor() default true;

/**
* @return When false, this table gets generated and associated with database, however it will not immediately
* get created upon startup. This is useful for keeping around legacy tables for migrations.
*/
boolean createWithDatabase() default true;

/**
* @return The cache size for this Table.
*/
Expand Down
9 changes: 3 additions & 6 deletions dbflow-kotlinextensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

compile project("${dbflow_project_prefix}dbflow-core")
compile project("${dbflow_project_prefix}dbflow")
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
api project("${dbflow_project_prefix}dbflow-core")
api project("${dbflow_project_prefix}dbflow")
}

apply from: '../kotlin-artifacts.gradle'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.raizlabs.android.dbflow.kotlinextensions

import com.raizlabs.android.dbflow.sql.queriable.ModelQueriable
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty


fun <T : Any> oneToMany(query: () -> ModelQueriable<T>) = OneToMany(query)

/**
* Description: Wraps a [OneToMany] annotation getter into a concise property setter.
*/
class OneToMany<T : Any>(private val query: () -> ModelQueriable<T>) : ReadWriteProperty<Any, List<T>?> {

private var list: List<T>? = null

override fun getValue(thisRef: Any, property: KProperty<*>): List<T>? {
if (list?.isEmpty() ?: true) {
list = query().list
}
return list
}

override fun setValue(thisRef: Any, property: KProperty<*>, value: List<T>?) {
list = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import com.raizlabs.android.dbflow.sql.language.property.Property
* Description: Provides property methods in via infix functions.
*/

infix fun <T : Any> Property<T>.eq(value: T) = this.eq(value)
infix fun <T : Any> Property<T>.eq(value: T?) = this.eq(value)

infix fun <T : Any> Property<T>.`is`(value: T) = this.`is`(value)
infix fun <T : Any> Property<T>.`is`(value: T?) = this.`is`(value)

infix fun <T : Any> Property<T>.isNot(value: T) = this.isNot(value)
infix fun <T : Any> Property<T>.isNot(value: T?) = this.isNot(value)

infix fun <T : Any> Property<T>.notEq(value: T) = this.notEq(value)
infix fun <T : Any> Property<T>.notEq(value: T?) = this.notEq(value)

infix fun <T : Any> Property<T>.like(value: String) = this.like(value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,26 @@ package com.raizlabs.android.dbflow.kotlinextensions

import com.raizlabs.android.dbflow.annotation.Collate
import com.raizlabs.android.dbflow.sql.Query
import com.raizlabs.android.dbflow.sql.language.*
import com.raizlabs.android.dbflow.sql.language.BaseModelQueriable
import com.raizlabs.android.dbflow.sql.language.Case
import com.raizlabs.android.dbflow.sql.language.CaseCondition
import com.raizlabs.android.dbflow.sql.language.CompletedTrigger
import com.raizlabs.android.dbflow.sql.language.CursorResult
import com.raizlabs.android.dbflow.sql.language.From
import com.raizlabs.android.dbflow.sql.language.Index
import com.raizlabs.android.dbflow.sql.language.Insert
import com.raizlabs.android.dbflow.sql.language.Join
import com.raizlabs.android.dbflow.sql.language.NameAlias
import com.raizlabs.android.dbflow.sql.language.OrderBy
import com.raizlabs.android.dbflow.sql.language.SQLOperator
import com.raizlabs.android.dbflow.sql.language.SQLite
import com.raizlabs.android.dbflow.sql.language.Select
import com.raizlabs.android.dbflow.sql.language.Set
import com.raizlabs.android.dbflow.sql.language.Transformable
import com.raizlabs.android.dbflow.sql.language.Trigger
import com.raizlabs.android.dbflow.sql.language.TriggerMethod
import com.raizlabs.android.dbflow.sql.language.Update
import com.raizlabs.android.dbflow.sql.language.Where
import com.raizlabs.android.dbflow.sql.language.property.IProperty
import com.raizlabs.android.dbflow.sql.queriable.AsyncQuery
import com.raizlabs.android.dbflow.sql.queriable.ModelQueriable
Expand Down Expand Up @@ -85,6 +103,12 @@ inline val <T : Any> ModelQueriable<T>.result
inline val <T : Any> ModelQueriable<T>.cursorResult
get() = queryResults()

inline val <T : Any> ModelQueriable<T>.flowQueryList
get() = flowQueryList()

inline val <T : Any> ModelQueriable<T>.cursorList
get() = cursorList()

// cursor result extensions
inline fun <reified T : Any> CursorResult<*>.toCustomList() = toCustomList(T::class.java)

Expand All @@ -100,16 +124,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 +187,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
13 changes: 7 additions & 6 deletions dbflow-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_1_8

dependencies {
compile project("${dbflow_project_prefix}dbflow-core")
compile 'com.squareup:javapoet:1.8.0'
compile 'com.github.agrosner:KPoet:1.0.0'
compile 'com.google.auto.service:auto-service:1.0-rc2'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
implementation project("${dbflow_project_prefix}dbflow-core")
implementation 'com.squareup:javapoet:1.9.0'
implementation 'com.github.agrosner:KPoet:1.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"

testCompile 'junit:junit:4.12'
compileOnly 'org.glassfish:javax.annotation:10.0-b28'

testImplementation 'junit:junit:4.12'

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object ClassNames {

val TYPE_CONVERTER = ClassName.get(CONVERTER, "TypeConverter")
val TYPE_CONVERTER_GETTER: ClassName = ClassName.get(PROPERTY_PACKAGE,
"TypeConvertedProperty.TypeConverterGetter")
"TypeConvertedProperty.TypeConverterGetter")

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

Expand Down Expand Up @@ -87,9 +87,13 @@ object ClassNames {
val SQLITE = ClassName.get(LANGUAGE, "SQLite")

val CACHEABLE_LIST_MODEL_SAVER = ClassName.get(SAVEABLE, "CacheableListModelSaver")
val SINGLE_MODEL_SAVER = ClassName.get(SAVEABLE, "ModelSaver")
val AUTOINCREMENT_MODEL_SAVER = ClassName.get(SAVEABLE, "AutoIncrementModelSaver")

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

val NON_NULL = ClassName.get("android.support.annotation", "NonNull")

val GENERATED = ClassName.get("javax.annotation", "Generated")
}
Loading

0 comments on commit bc1cf60

Please sign in to comment.