Skip to content

Commit

Permalink
Merge pull request #1492 from Raizlabs/develop
Browse files Browse the repository at this point in the history
4.2.0
  • Loading branch information
agrosner committed Dec 17, 2017
2 parents fcbad3b + b442620 commit 966a9ad
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 114 deletions.
7 changes: 4 additions & 3 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.1.2-red.svg?style=flat)](https://jitpack.io/#Raizlabs/DBFlow) [![Android Weekly](http:https://img.shields.io/badge/Android%20Weekly-%23129-2CB3E5.svg?style=flat)](http:https://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.2.0-red.svg?style=flat)](https://jitpack.io/#Raizlabs/DBFlow) [![Android Weekly](http:https://img.shields.io/badge/Android%20Weekly-%23129-2CB3E5.svg?style=flat)](http:https://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 @@ -43,8 +43,9 @@ Add the library to the project-level build.gradle, using the apt plugin to enabl
apply plugin: 'kotlin-kapt' // required for kotlin.
def dbflow_version = "4.1.2"
// dbflow_version = 10-digit short-hash of a specific commit. (Useful for bugs fixed in develop, but not in a release yet)
def dbflow_version = "4.2.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 {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-rc2'
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import com.raizlabs.android.dbflow.sql.language.Delete
import com.raizlabs.android.dbflow.sql.language.SQLOperator
import com.raizlabs.android.dbflow.structure.BaseModel
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import java.util.concurrent.CountDownLatch
Expand All @@ -34,11 +33,12 @@ class ContentObserverTest : BaseInstrumentedUnitTest() {
@Test
fun testSpecificUris() {
val conditionGroup = FlowManager.getModelAdapter(User::class.java)
.getPrimaryConditionClause(user)
val uri = SqlUtils.getNotificationUri(User::class.java, BaseModel.Action.DELETE,
conditionGroup.conditions.toTypedArray())
.getPrimaryConditionClause(user)
val uri = SqlUtils.getNotificationUri(FlowManager.DEFAULT_AUTHORITY,
User::class.java, BaseModel.Action.DELETE,
conditionGroup.conditions.toTypedArray())

assertEquals(uri.authority, FlowManager.getTableName(User::class.java))
assertEquals(uri.authority, FlowManager.DEFAULT_AUTHORITY)
assertEquals(uri.fragment, BaseModel.Action.DELETE.name)
assertEquals(Uri.decode(uri.getQueryParameter(Uri.encode(id.query))), "5")
assertEquals(Uri.decode(uri.getQueryParameter(Uri.encode(name.query))), "Something")
Expand Down Expand Up @@ -69,7 +69,7 @@ class ContentObserverTest : BaseInstrumentedUnitTest() {
}

private fun assertProperConditions(action: BaseModel.Action, userFunc: (User) -> Unit) {
val contentObserver = FlowContentObserver()
val contentObserver = FlowContentObserver(FlowManager.DEFAULT_AUTHORITY)
val countDownLatch = CountDownLatch(1)
val mockOnModelStateChangedListener = MockOnModelStateChangedListener(countDownLatch)
contentObserver.addModelChangeListener(mockOnModelStateChangedListener)
Expand All @@ -79,7 +79,7 @@ class ContentObserverTest : BaseInstrumentedUnitTest() {
countDownLatch.await()

val ops = mockOnModelStateChangedListener.operators!!
assertTrue(ops.size == 2)
assertEquals(2, ops.size)
assertEquals(ops[0].columnName(), id.query)
assertEquals(ops[1].columnName(), name.query)
assertEquals(ops[1].value(), "Something")
Expand Down
4 changes: 4 additions & 0 deletions dbflow-tests/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<provider
android:name="com.raizlabs.android.dbflow.runtime.StubContentProvider"
android:authorities="com.dbflow.authority"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public ModelNotifier getModelNotifier() {
DatabaseConfig config = FlowManager.getConfig().databaseConfigMap()
.get(getAssociatedDatabaseClassFile());
if (config == null || config.modelNotifier() == null) {
modelNotifier = new ContentResolverNotifier();
modelNotifier = new ContentResolverNotifier(FlowManager.DEFAULT_AUTHORITY);
} else {
modelNotifier = config.modelNotifier();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public boolean isInitialized() {
private static final String DEFAULT_DATABASE_HOLDER_CLASSNAME =
DEFAULT_DATABASE_HOLDER_PACKAGE_NAME + "." + DEFAULT_DATABASE_HOLDER_NAME;

public static final String DEFAULT_AUTHORITY = "com.dbflow.authority";

/**
* Returns the table name for the specific model class
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* on the underlying table.
*/
public class FlowQueryList<TModel> extends FlowContentObserver
implements List<TModel>, IFlowCursorIterator<TModel> {
implements List<TModel>, IFlowCursorIterator<TModel> {

private static final Handler REFRESH_HANDLER = new Handler(Looper.myLooper());

Expand All @@ -60,16 +60,17 @@ public class FlowQueryList<TModel> extends FlowContentObserver


private FlowQueryList(Builder<TModel> builder) {
super(FlowManager.DEFAULT_AUTHORITY);
transact = builder.transact;
changeInTransaction = builder.changeInTransaction;
successCallback = builder.success;
errorCallback = builder.error;
internalCursorList = new FlowCursorList.Builder<>(builder.table)
.cursor(builder.cursor)
.cacheModels(builder.cacheModels)
.modelQueriable(builder.modelQueriable)
.modelCache(builder.modelCache)
.build();
.cursor(builder.cursor)
.cacheModels(builder.cacheModels)
.modelQueriable(builder.modelQueriable)
.modelCache(builder.modelCache)
.build();
}

/**
Expand All @@ -92,8 +93,8 @@ public void removeOnCursorRefreshListener(@NonNull OnCursorRefreshListener<TMode
@Override
public void registerForContentChanges(Context context, Class<?> table) {
throw new RuntimeException(
"This method is not to be used in the FlowQueryList. We should only ever receive" +
" notifications for one class here. Call registerForContentChanges(Context) instead");
"This method is not to be used in the FlowQueryList. We should only ever receive" +
" notifications for one class here. Call registerForContentChanges(Context) instead");
}

@Override
Expand Down Expand Up @@ -165,10 +166,10 @@ InstanceAdapter<TModel> getInstanceAdapter() {
@NonNull
public Builder<TModel> newBuilder() {
return new Builder<>(internalCursorList)
.success(successCallback)
.error(errorCallback)
.changeInTransaction(changeInTransaction)
.transact(transact);
.success(successCallback)
.error(errorCallback)
.changeInTransaction(changeInTransaction)
.transact(transact);
}

/**
Expand Down Expand Up @@ -223,10 +224,10 @@ public void add(int location, @Nullable TModel model) {
public boolean add(@Nullable TModel model) {
if (model != null) {
Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(saveModel)
.add(model).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(saveModel)
.add(model).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();

if (transact) {
transaction.execute();
Expand Down Expand Up @@ -265,10 +266,10 @@ public boolean addAll(@NonNull Collection<? extends TModel> collection) {
final Collection<TModel> tmpCollection = (Collection<TModel>) collection;

Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(saveModel)
.addAll(tmpCollection).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(saveModel)
.addAll(tmpCollection).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();

if (transact) {
transaction.execute();
Expand All @@ -284,11 +285,11 @@ public boolean addAll(@NonNull Collection<? extends TModel> collection) {
@Override
public void clear() {
Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
.beginTransactionAsync(new QueryTransaction.Builder<>(
SQLite.delete().from(internalCursorList.table())).build())
.error(internalErrorCallback)
.success(internalSuccessCallback)
.build();
.beginTransactionAsync(new QueryTransaction.Builder<>(
SQLite.delete().from(internalCursorList.table())).build())
.error(internalErrorCallback)
.success(internalSuccessCallback)
.build();

if (transact) {
transaction.execute();
Expand Down Expand Up @@ -369,7 +370,7 @@ public TModel get(int row) {
@Override
public int indexOf(Object object) {
throw new UnsupportedOperationException(
"We cannot determine which index in the table this item exists at efficiently");
"We cannot determine which index in the table this item exists at efficiently");
}

@Override
Expand All @@ -396,7 +397,7 @@ public FlowCursorIterator<TModel> iterator(int startingLocation, long limit) {
@Override
public int lastIndexOf(Object object) {
throw new UnsupportedOperationException(
"We cannot determine which index in the table this item exists at efficiently");
"We cannot determine which index in the table this item exists at efficiently");
}

/**
Expand Down Expand Up @@ -433,10 +434,10 @@ public TModel remove(int location) {
TModel model = internalCursorList.getItem(location);

Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(deleteModel)
.add(model).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(deleteModel)
.add(model).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();

if (transact) {
transaction.execute();
Expand All @@ -462,10 +463,10 @@ public boolean remove(Object object) {
if (internalCursorList.table().isAssignableFrom(object.getClass())) {
TModel model = ((TModel) object);
Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(deleteModel)
.add(model).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(deleteModel)
.add(model).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();

if (transact) {
transaction.execute();
Expand All @@ -492,10 +493,10 @@ public boolean removeAll(@NonNull Collection<?> collection) {
// if its a ModelClass
Collection<TModel> modelCollection = (Collection<TModel>) collection;
Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(deleteModel)
.addAll(modelCollection).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(deleteModel)
.addAll(modelCollection).build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();

if (transact) {
transaction.execute();
Expand All @@ -518,10 +519,10 @@ public boolean retainAll(@NonNull Collection<?> collection) {
List<TModel> tableList = internalCursorList.getAll();
tableList.removeAll(collection);
Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(tableList, deleteModel)
.build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(tableList, deleteModel)
.build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();

if (transact) {
transaction.execute();
Expand Down Expand Up @@ -552,11 +553,11 @@ public TModel set(int location, TModel object) {
*/
public TModel set(TModel object) {
Transaction transaction = FlowManager.getDatabaseForTable(internalCursorList.table())
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(updateModel)
.add(object)
.build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();
.beginTransactionAsync(new ProcessModelTransaction.Builder<>(updateModel)
.add(object)
.build())
.error(internalErrorCallback)
.success(internalSuccessCallback).build();

if (transact) {
transaction.execute();
Expand Down Expand Up @@ -598,28 +599,28 @@ public void close() {
}

private final ProcessModelTransaction.ProcessModel<TModel> saveModel =
new ProcessModelTransaction.ProcessModel<TModel>() {
@Override
public void processModel(TModel model, DatabaseWrapper wrapper) {
getModelAdapter().save(model);
}
};
new ProcessModelTransaction.ProcessModel<TModel>() {
@Override
public void processModel(TModel model, DatabaseWrapper wrapper) {
getModelAdapter().save(model);
}
};

private final ProcessModelTransaction.ProcessModel<TModel> updateModel =
new ProcessModelTransaction.ProcessModel<TModel>() {
@Override
public void processModel(TModel model, DatabaseWrapper wrapper) {
getModelAdapter().update(model);
}
};
new ProcessModelTransaction.ProcessModel<TModel>() {
@Override
public void processModel(TModel model, DatabaseWrapper wrapper) {
getModelAdapter().update(model);
}
};

private final ProcessModelTransaction.ProcessModel<TModel> deleteModel =
new ProcessModelTransaction.ProcessModel<TModel>() {
@Override
public void processModel(TModel model, DatabaseWrapper wrapper) {
getModelAdapter().delete(model);
}
};
new ProcessModelTransaction.ProcessModel<TModel>() {
@Override
public void processModel(TModel model, DatabaseWrapper wrapper) {
getModelAdapter().delete(model);
}
};

private final Transaction.Error internalErrorCallback = new Transaction.Error() {
@Override
Expand Down
Loading

0 comments on commit 966a9ad

Please sign in to comment.