DBFlow
DBFlow copied to clipboard
Loaders and cursors for DBFlow
This pull request contains the implementation of the following classes to improve Loader support for DBFlow.
-
FlowCursorAdapter
: The purpose of this class is to improve support forCursorAdapter
. In particular, we overload thegetItem (position)
method to return the actual model element at that position instead of aCursor
. -
FlowSimpleCursorAdapter
: This class allows theSimpleCursorAdapter
to easily support DBFlow. Similar toFlowCursorAdapter
, we overload thegetItem(position)
method to return a model element, instead of aCursor
. -
FlowCursorLoader
: This class integrates DBFLow with the AndroidLoader
framework. In particular, the loader must be created with aQueriable
object. TheQueriable
object is used by the loader to load models. The end result of this loader is a Cursor that can be used like the cursor returned byCursorLoader
. A key feature of this loader is the ability to leverage the model observer framework in DBFlow via the(un)registerForContentChanges()
methods. Using this methods will configure the loader to observe changes to models of interest. Any change observed will trigger the loader to automatically reload. This simplifies storing data in the database via DBFlow models, and updating corresponding views as a result of the storage updates. -
FlowSingleModelLoader
: This is the base class for the following single model classes:FlowModelLoader
,FlowModelViewLoader
,FlowModelQueryLoader
. Single model loaders are for queries that return 1 model, not a list of models or a cursor to a list of models. We treat these different from the list loaders because we need to appropriateInstanceAdapter
to create the single model, and load it from the cursor. The result of each load is a single, usable model. Similar to theFlowModelLoader
, these loaders will automatically reload if the underlying table changes. Also, you can register for updates to models that have nothing to do with the final model. This is of interest when dealing with query models since the final model may be the composition of data from many different tables.
Lastly, each loader has been tested in applications that I am currently using. It would be great if these classes can be incorporated into the next release of DBFlow.
@agrosner Is there anything blocking this PR for being merged?
This PR is a key feature for me. @hilljh82 is not alone, I'm happy when this PR is merged soon
@hilljh82 please solve the conflict to let us (who wait for this feature) know, if @agrosner ever will merge this PR. Thank you !
@hilljh82 I am trying to use FlowCursorLoader class. It works but sometimes, I get
java.lang.IllegalStateException: Cannot execute task: the task is already running. at android.support.v4.content.ModernAsyncTask.executeOnExecutor(ModernAsyncTask.java:424) at android.support.v4.content.AsyncTaskLoader.executePendingTask(AsyncTaskLoader.java:219) at android.support.v4.content.AsyncTaskLoader.dispatchOnCancelled(AsyncTaskLoader.java:232) at android.support.v4.content.AsyncTaskLoader$LoadTask.onCancelled(AsyncTaskLoader.java:88) at android.support.v4.content.ModernAsyncTask.finish(ModernAsyncTask.java:474) at android.support.v4.content.ModernAsyncTask$InternalHandler.handleMessage(ModernAsyncTask.java:493) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5438) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
Googled a lot but no success. I am probably doing something wrong. I wonder, if you ever got this issue and/or know how to fix this?
Thanks !
No, I have not. Do you mind sharing the code where you are creating the loader?
On Tue, Mar 21, 2017, 6:41 AM Zubin Mehta [email protected] wrote:
@hilljh82 https://github.com/hilljh82 I am trying to use FlowCursorLoader class. It works but sometimes, I get
java.lang.IllegalStateException: Cannot execute task: the task is already running. at android.support.v4.content.ModernAsyncTask.executeOnExecutor(ModernAsyncTask.java:424) at android.support.v4.content.AsyncTaskLoader.executePendingTask(AsyncTaskLoader.java:219) at android.support.v4.content.AsyncTaskLoader.dispatchOnCancelled(AsyncTaskLoader.java:232) at android.support.v4.content.AsyncTaskLoader$LoadTask.onCancelled(AsyncTaskLoader.java:88) at android.support.v4.content.ModernAsyncTask.finish(ModernAsyncTask.java:474) at android.support.v4.content.ModernAsyncTask$InternalHandler.handleMessage(ModernAsyncTask.java:493) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5438) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
I have been stuck at this issue, after googling a lot. I am probably doing something wrong. I wonder, if you ever got this issue and/or know how to fix this?
Thanks !
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Raizlabs/DBFlow/pull/1091#issuecomment-288039402, or mute the thread https://github.com/notifications/unsubscribe-auth/AB7C_QGHPrDHeGBWoU_rYDskdynf5yR9ks5rn6k9gaJpZM4LA5AA .
sigh I really hate to see this PR just go to waste.
@agrosner Did you make a final decision on declining this PR yet?
@Harti Yes, it is unfortunate this PR has not been integrated into master—especially since I have twice addressed merge conflicts due to master changing only for my updates to become outdated once again.
If you are interested, I have create a separate project that provides these loaders:
https://github.com/onehilltech/backbone/tree/master/backbone-dbflow
Until this PR gets merged, I have been using this project. It is also a place that I use to implement support classes for DBFlow since the experience with this PR leaves me with little confidence some cool ideas I have will ever be integrated!
In addition, I have been working on another project called backbone-data that is designed to the equivalent of ember-data for Android. It uses DBFlow and Retrofit under the hood. It's a work in progress, but its making my life a LOT easier on Android since it codifies much if the redundant code that I was creating when using DBFlow.