Skip to content

Commit eb5ed84

Browse files
authored
Merge pull request #1498 from Raizlabs/develop
4.2.3
2 parents d4bd71b + 1175f66 commit eb5ed84

File tree

8 files changed

+40
-31
lines changed

8 files changed

+40
-31
lines changed

ISSUE_TEMPLATE.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
21
DBFlow Version:
3-
Issue Kind (Bug, Question, Feature):
42

5-
Please note if you are using Instant Run, there may be bugs where generated classes are not created. Ensure you are using
6-
the [apt](https://bitbucket.org/hvisser/android-apt) or [kapt](http://blog.jetbrains.com/kotlin/2015/06/better-annotation-processing-supporting-stubs-in-kapt/) plugins and that incremental compilation is off.
3+
Bug or Feature Request:
74

8-
Description:
5+
Description:

README.md

Lines changed: 2 additions & 2 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.2.2-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.2.3-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

@@ -43,7 +43,7 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl
4343
4444
apply plugin: 'kotlin-kapt' // required for kotlin.
4545
46-
def dbflow_version = "4.2.2"
46+
def dbflow_version = "4.2.3"
4747
// or dbflow_version = "develop-SNAPSHOT" for grabbing latest dependency in your project on the develop branch
4848
// or 10-digit short-hash of a specific commit. (Useful for bugs fixed in develop, but not in a release yet)
4949

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
}
77
dependencies {
88
classpath 'com.android.tools.build:gradle:3.0.1'
9-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
9+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1010
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212
}

dbflow/src/main/java/com/raizlabs/android/dbflow/sql/language/Operator.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,13 @@ public Operator<T> concatenate(@Nullable Object value) {
551551
value = typeConverter.getDBValue(value);
552552
}
553553
if (value instanceof String || value instanceof IOperator
554-
|| value instanceof Character) {
554+
|| value instanceof Character) {
555555
operation = String.format("%1s %1s ", operation, Operation.CONCATENATE);
556556
} else if (value instanceof Number) {
557557
operation = String.format("%1s %1s ", operation, Operation.PLUS);
558558
} else {
559559
throw new IllegalArgumentException(
560-
String.format("Cannot concatenate the %1s", value != null ? value.getClass() : "null"));
560+
String.format("Cannot concatenate the %1s", value != null ? value.getClass() : "null"));
561561
}
562562
this.value = value;
563563
isValueSet = true;
@@ -617,7 +617,8 @@ public String convertObjectToString(Object object, boolean appendInnerParenthesi
617617
converted = convertToDB ? typeConverter.getDBValue(object) : object;
618618
} catch (ClassCastException c) {
619619
// if object type is not valid converted type, just use type as is here.
620-
FlowLog.log(FlowLog.Level.W, c);
620+
FlowLog.log(FlowLog.Level.I, "Value passed to operation is not valid type for TypeConverter in the column. " +
621+
"Preserving value " + object + " to be used as is.");
621622
}
622623
return BaseOperator.convertValueToString(converted, appendInnerParenthesis, false);
623624
} else {
@@ -792,10 +793,10 @@ public T secondValue() {
792793
@Override
793794
public void appendConditionToQuery(@NonNull QueryBuilder queryBuilder) {
794795
queryBuilder.append(columnName()).append(operation())
795-
.append(convertObjectToString(value(), true))
796-
.appendSpaceSeparated(Operation.AND)
797-
.append(convertObjectToString(secondValue(), true))
798-
.appendSpace().appendOptional(postArgument());
796+
.append(convertObjectToString(value(), true))
797+
.appendSpaceSeparated(Operation.AND)
798+
.append(convertObjectToString(secondValue(), true))
799+
.appendSpace().appendOptional(postArgument());
799800
}
800801

801802
@Override
@@ -852,7 +853,7 @@ public In<T> and(@Nullable T argument) {
852853
@Override
853854
public void appendConditionToQuery(@NonNull QueryBuilder queryBuilder) {
854855
queryBuilder.append(columnName()).append(operation())
855-
.append("(").append(OperatorGroup.joinArguments(",", inArguments, this)).append(")");
856+
.append("(").append(OperatorGroup.joinArguments(",", inArguments, this)).append(")");
856857
}
857858

858859
@Override

dbflow/src/main/java/com/raizlabs/android/dbflow/sql/saveable/ModelSaver.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,26 @@ public void setModelAdapter(@NonNull ModelAdapter<TModel> modelAdapter) {
2727

2828
public synchronized boolean save(@NonNull TModel model) {
2929
return save(model, getWritableDatabase(), modelAdapter.getInsertStatement(),
30-
modelAdapter.getUpdateStatement());
30+
modelAdapter.getUpdateStatement());
3131
}
3232

33-
public synchronized boolean save(@NonNull TModel model,
34-
@NonNull DatabaseWrapper wrapper) {
35-
return save(model, wrapper, modelAdapter.getInsertStatement(wrapper),
36-
modelAdapter.getUpdateStatement(wrapper));
33+
public synchronized boolean save(@NonNull TModel model, @NonNull DatabaseWrapper wrapper) {
34+
boolean exists = getModelAdapter().exists(model, wrapper);
35+
36+
if (exists) {
37+
exists = update(model, wrapper);
38+
}
39+
40+
if (!exists) {
41+
exists = insert(model, wrapper) > INSERT_FAILED;
42+
}
43+
44+
if (exists) {
45+
NotifyDistributor.get().notifyModelChanged(model, getModelAdapter(), BaseModel.Action.SAVE);
46+
}
47+
48+
// return successful store into db.
49+
return exists;
3750
}
3851

3952
@SuppressWarnings("unchecked")
@@ -201,8 +214,8 @@ public synchronized boolean update(@NonNull TModel model,
201214
modelAdapter.saveForeignKeys(model, wrapper);
202215
modelAdapter.bindToContentValues(contentValues, model);
203216
boolean successful = wrapper.updateWithOnConflict(modelAdapter.getTableName(), contentValues,
204-
modelAdapter.getPrimaryConditionClause(model).getQuery(), null,
205-
ConflictAction.getSQLiteDatabaseAlgorithmInt(modelAdapter.getUpdateOnConflictAction())) != 0;
217+
modelAdapter.getPrimaryConditionClause(model).getQuery(), null,
218+
ConflictAction.getSQLiteDatabaseAlgorithmInt(modelAdapter.getUpdateOnConflictAction())) != 0;
206219
if (successful) {
207220
NotifyDistributor.get().notifyModelChanged(model, modelAdapter, BaseModel.Action.UPDATE);
208221
}

dbflow/src/main/java/com/raizlabs/android/dbflow/structure/InternalAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.database.sqlite.SQLiteStatement;
55
import android.support.annotation.IntRange;
66
import android.support.annotation.NonNull;
7+
import android.support.annotation.Nullable;
78

89
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
910
import com.raizlabs.android.dbflow.structure.database.DatabaseStatement;
@@ -211,7 +212,7 @@ void bindToInsertStatement(@NonNull DatabaseStatement sqLiteStatement, @NonNull
211212
* @return The value for the {@link PrimaryKey#autoincrement()}
212213
* if it has the field. This method is overridden when its specified for the {@link TModel}
213214
*/
214-
@NonNull
215+
@Nullable
215216
Number getAutoIncrementingId(@NonNull TModel model);
216217

217218
/**

dbflow/src/main/java/com/raizlabs/android/dbflow/structure/ModelAdapter.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.ContentValues;
44
import android.database.sqlite.SQLiteStatement;
55
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
67

78
import com.raizlabs.android.dbflow.annotation.ConflictAction;
89
import com.raizlabs.android.dbflow.annotation.ForeignKey;
@@ -291,7 +292,7 @@ public void updateAutoIncrement(@NonNull TModel model, @NonNull Number id) {
291292
* @return The value for the {@link PrimaryKey#autoincrement()}
292293
* if it has the field. This method is overridden when its specified for the {@link TModel}
293294
*/
294-
@NonNull
295+
@Nullable
295296
@Override
296297
public Number getAutoIncrementingId(@NonNull TModel model) {
297298
throw new InvalidDBConfiguration(
@@ -314,11 +315,7 @@ public String getAutoIncrementingColumnName() {
314315

315316
public boolean hasAutoIncrement(TModel model) {
316317
Number id = getAutoIncrementingId(model);
317-
//noinspection ConstantConditions
318-
if (id == null) {
319-
throw new IllegalStateException("An autoincrementing column field cannot be null.");
320-
}
321-
return id.longValue() > 0;
318+
return id != null && id.longValue() > 0;
322319
}
323320

324321
/**

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=4.2.2
1+
version=4.2.3
22
version_code=1
33
group=com.raizlabs.android
44
bt_siteUrl=https://github.com/Raizlabs/DBFlow

0 commit comments

Comments
 (0)