Skip to content

Commit bc1cf60

Browse files
authored
Merge pull request #1416 from Raizlabs/develop
4.1.0
2 parents 38fe8f0 + d1be504 commit bc1cf60

File tree

125 files changed

+2161
-957
lines changed

Some content is hidden

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

125 files changed

+2161
-957
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Image](https://github.com/agrosner/DBFlow/blob/develop/dbflow_banner.png?raw=true)
22

3-
[![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)
3+
[![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)
44

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

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

4242
```groovy
4343
44-
def dbflow_version = "4.0.5"
44+
apply plugin: 'kotlin-kapt' // required for kotlin.
45+
46+
def dbflow_version = "4.1.0"
4547
// or dbflow_version = "develop-SNAPSHOT" for grabbing latest dependency in your project on the develop branch
4648
// or 10-digit short-hash of a specific commit. (Useful for bugs fixed in develop, but not in a release yet)
4749
4850
dependencies {
51+
52+
// if Java use this. If using Kotlin do NOT use this.
4953
annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
5054
51-
// use kapt for kotlin apt if you're a Kotlin user
55+
// Use if Kotlin user.
5256
kapt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
5357
5458
compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
@@ -75,10 +79,6 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl
7579
7680
}
7781
78-
// if you're building with Kotlin
79-
kapt {
80-
generateStubs = true
81-
}
8282
```
8383

8484
# Pull Requests

build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
buildscript {
2-
ext.kotlin_version = '1.1.3-2'
2+
ext.kotlin_version = '1.1.4-2'
33
repositories {
44
jcenter()
5+
google()
56
}
67
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.3.3'
8+
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
89
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
9-
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
10+
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3'
1011
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1112
}
1213
}
1314

1415
allprojects {
1516
repositories {
1617
jcenter()
18+
google()
1719
maven { url "https://www.jitpack.io" }
1820
}
1921
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.raizlabs.android.dbflow.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Description: Maps an arbitrary object and its corresponding fields into a set of columns. It is similar
10+
* to {@link ForeignKey} except it's not represented in the DB hierarchy.
11+
*/
12+
@Retention(RetentionPolicy.CLASS)
13+
@Target(ElementType.FIELD)
14+
public @interface ColumnMap {
15+
16+
/**
17+
* Defines explicit references for a composite {@link ColumnMap} definition.
18+
*
19+
* @return override explicit usage of all fields and provide custom references.
20+
*/
21+
ColumnMapReference[] references() default {};
22+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.raizlabs.android.dbflow.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Description: Allows a {@link ColumnMap} to specify a reference override for its fields. Anything not
10+
* defined here will not be used.
11+
*/
12+
@Retention(RetentionPolicy.CLASS)
13+
@Target(ElementType.FIELD)
14+
public @interface ColumnMapReference {
15+
16+
/**
17+
* @return The local column name that will be referenced in the DB
18+
*/
19+
String columnName();
20+
21+
/**
22+
* @return The column name in the referenced table
23+
*/
24+
String columnMapFieldName();
25+
26+
/**
27+
* @return Specify the {@link NotNull} annotation here and it will get pasted into the reference definition.
28+
*/
29+
NotNull notNull() default @NotNull(onNullConflict = ConflictAction.NONE);
30+
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,23 @@
2626
int version();
2727

2828
/**
29-
* @return The name of the DB. Optional as it will default to the class name.
29+
* @deprecated use DatabaseConfig.databaseName() to change the name.
3030
*/
31+
@Deprecated
3132
String name() default "";
3233

3334
/**
34-
* @return Specify the extension of the file name : {fileName}.{extension}. Default is ".db"
35+
* @deprecated use DatabaseConfig.extension() to change the extension.
3536
*/
37+
@Deprecated
3638
String databaseExtension() default "";
3739

40+
/**
41+
* @deprecated use DatabaseConfig.inMemoryBuilder() instead.
42+
*/
43+
@Deprecated
44+
boolean inMemory() default false;
45+
3846
/**
3947
* @return If true, SQLite will throw exceptions when {@link ForeignKey} constraints are not respected.
4048
* Default is false and will not throw exceptions.
@@ -52,11 +60,6 @@
5260
*/
5361
boolean backupEnabled() default false;
5462

55-
/**
56-
* @return true if you want it to be in-memory, false if not.
57-
*/
58-
boolean inMemory() default false;
59-
6063
/**
6164
* @return Global default insert conflict that can be applied to any table when it leaves
6265
* its {@link ConflictAction} as NONE.
@@ -72,6 +75,8 @@
7275
/**
7376
* @return Marks all generated classes within this database with this character. For example
7477
* "TestTable" becomes "TestTable$Table" for a "$" separator.
78+
* @deprecated Generated class files will become '_' only in next major release.
7579
*/
80+
@Deprecated
7681
String generatedClassSeparator() default "_";
7782
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@
2424
*/
2525
String foreignKeyColumnName();
2626

27+
/**
28+
* @return Specify the {@link NotNull} annotation here and it will get pasted into the reference definition.
29+
*/
30+
NotNull notNull() default @NotNull(onNullConflict = ConflictAction.NONE);
2731
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ enum Method {
5555
/**
5656
* @return If true, the underlying variable that we use is private, requiring us to provide
5757
* a setter for it.
58+
* @deprecated has no effect on the visibility of the call since we now autodetect visibility.
5859
*/
60+
@Deprecated
5961
boolean isVariablePrivate() default false;
6062

6163
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373
*/
7474
boolean assignDefaultValuesFromCursor() default true;
7575

76+
/**
77+
* @return When false, this table gets generated and associated with database, however it will not immediately
78+
* get created upon startup. This is useful for keeping around legacy tables for migrations.
79+
*/
80+
boolean createWithDatabase() default true;
81+
7682
/**
7783
* @return The cache size for this Table.
7884
*/

dbflow-kotlinextensions/build.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ android {
2626
}
2727

2828
dependencies {
29-
compile fileTree(dir: 'libs', include: ['*.jar'])
30-
testCompile 'junit:junit:4.12'
31-
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
32-
33-
compile project("${dbflow_project_prefix}dbflow-core")
34-
compile project("${dbflow_project_prefix}dbflow")
29+
api "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30+
api project("${dbflow_project_prefix}dbflow-core")
31+
api project("${dbflow_project_prefix}dbflow")
3532
}
3633

3734
apply from: '../kotlin-artifacts.gradle'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.raizlabs.android.dbflow.kotlinextensions
2+
3+
import com.raizlabs.android.dbflow.sql.queriable.ModelQueriable
4+
import kotlin.properties.ReadWriteProperty
5+
import kotlin.reflect.KProperty
6+
7+
8+
fun <T : Any> oneToMany(query: () -> ModelQueriable<T>) = OneToMany(query)
9+
10+
/**
11+
* Description: Wraps a [OneToMany] annotation getter into a concise property setter.
12+
*/
13+
class OneToMany<T : Any>(private val query: () -> ModelQueriable<T>) : ReadWriteProperty<Any, List<T>?> {
14+
15+
private var list: List<T>? = null
16+
17+
override fun getValue(thisRef: Any, property: KProperty<*>): List<T>? {
18+
if (list?.isEmpty() ?: true) {
19+
list = query().list
20+
}
21+
return list
22+
}
23+
24+
override fun setValue(thisRef: Any, property: KProperty<*>, value: List<T>?) {
25+
list = value
26+
}
27+
}

dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/PropertyMethodExtensions.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import com.raizlabs.android.dbflow.sql.language.property.Property
1010
* Description: Provides property methods in via infix functions.
1111
*/
1212

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

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

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

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

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

dbflow-kotlinextensions/src/main/java/com/raizlabs/android/dbflow/kotlinextensions/QueryExtensions.kt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,26 @@ package com.raizlabs.android.dbflow.kotlinextensions
22

33
import com.raizlabs.android.dbflow.annotation.Collate
44
import com.raizlabs.android.dbflow.sql.Query
5-
import com.raizlabs.android.dbflow.sql.language.*
5+
import com.raizlabs.android.dbflow.sql.language.BaseModelQueriable
6+
import com.raizlabs.android.dbflow.sql.language.Case
7+
import com.raizlabs.android.dbflow.sql.language.CaseCondition
8+
import com.raizlabs.android.dbflow.sql.language.CompletedTrigger
9+
import com.raizlabs.android.dbflow.sql.language.CursorResult
10+
import com.raizlabs.android.dbflow.sql.language.From
11+
import com.raizlabs.android.dbflow.sql.language.Index
12+
import com.raizlabs.android.dbflow.sql.language.Insert
13+
import com.raizlabs.android.dbflow.sql.language.Join
14+
import com.raizlabs.android.dbflow.sql.language.NameAlias
15+
import com.raizlabs.android.dbflow.sql.language.OrderBy
16+
import com.raizlabs.android.dbflow.sql.language.SQLOperator
17+
import com.raizlabs.android.dbflow.sql.language.SQLite
18+
import com.raizlabs.android.dbflow.sql.language.Select
619
import com.raizlabs.android.dbflow.sql.language.Set
20+
import com.raizlabs.android.dbflow.sql.language.Transformable
21+
import com.raizlabs.android.dbflow.sql.language.Trigger
22+
import com.raizlabs.android.dbflow.sql.language.TriggerMethod
23+
import com.raizlabs.android.dbflow.sql.language.Update
24+
import com.raizlabs.android.dbflow.sql.language.Where
725
import com.raizlabs.android.dbflow.sql.language.property.IProperty
826
import com.raizlabs.android.dbflow.sql.queriable.AsyncQuery
927
import com.raizlabs.android.dbflow.sql.queriable.ModelQueriable
@@ -85,6 +103,12 @@ inline val <T : Any> ModelQueriable<T>.result
85103
inline val <T : Any> ModelQueriable<T>.cursorResult
86104
get() = queryResults()
87105

106+
inline val <T : Any> ModelQueriable<T>.flowQueryList
107+
get() = flowQueryList()
108+
109+
inline val <T : Any> ModelQueriable<T>.cursorList
110+
get() = cursorList()
111+
88112
// cursor result extensions
89113
inline fun <reified T : Any> CursorResult<*>.toCustomList() = toCustomList(T::class.java)
90114

@@ -100,16 +124,16 @@ inline val <T : Any> ModelQueriable<T>.async
100124
get() = async()
101125

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

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

110134
infix inline fun <T : Any> AsyncQuery<T>.cursorResult(crossinline callback: (QueryTransaction<*>, CursorResult<T>) -> Unit)
111-
= queryResultCallback { queryTransaction, cursorResult -> callback(queryTransaction, cursorResult) }
112-
.execute()
135+
= queryResultCallback { queryTransaction, cursorResult -> callback(queryTransaction, cursorResult) }
136+
.execute()
113137

114138
inline val Model.async
115139
get() = async()
@@ -163,7 +187,7 @@ infix fun <T : Any> Update<T>.set(sqlOperator: SQLOperator) = set(sqlOperator)
163187
inline fun <reified T : Any> delete() = SQLite.delete(T::class.java)
164188

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

168192
// insert methods
169193

dbflow-processor/build.gradle

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ targetCompatibility = JavaVersion.VERSION_1_8
77
sourceCompatibility = JavaVersion.VERSION_1_8
88

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

16-
testCompile 'junit:junit:4.12'
15+
compileOnly 'org.glassfish:javax.annotation:10.0-b28'
16+
17+
testImplementation 'junit:junit:4.12'
1718

1819
}
1920

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object ClassNames {
5050

5151
val TYPE_CONVERTER = ClassName.get(CONVERTER, "TypeConverter")
5252
val TYPE_CONVERTER_GETTER: ClassName = ClassName.get(PROPERTY_PACKAGE,
53-
"TypeConvertedProperty.TypeConverterGetter")
53+
"TypeConvertedProperty.TypeConverterGetter")
5454

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

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

8989
val CACHEABLE_LIST_MODEL_SAVER = ClassName.get(SAVEABLE, "CacheableListModelSaver")
90+
val SINGLE_MODEL_SAVER = ClassName.get(SAVEABLE, "ModelSaver")
91+
val AUTOINCREMENT_MODEL_SAVER = ClassName.get(SAVEABLE, "AutoIncrementModelSaver")
9092

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

9496
val NON_NULL = ClassName.get("android.support.annotation", "NonNull")
97+
98+
val GENERATED = ClassName.get("javax.annotation", "Generated")
9599
}

0 commit comments

Comments
 (0)