-
Notifications
You must be signed in to change notification settings - Fork 600
Loaders and cursors for DBFlow #1091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hilljh82
wants to merge
56
commits into
agrosner:develop
Choose a base branch
from
onehilltech:loaders
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
91326fb
First pass at external foreign key references
hilljh82 50382fc
Added missing files
hilljh82 a1ff768
Merge from Raizlabs
hilljh82 35567d3
Foreign key on primary key failed if column was a model and not a mod…
hilljh82 a92a9d1
Removed debug code
hilljh82 de30375
Overrided getSupportedOptions() to handle processor warnings
hilljh82 bf4b415
Foreign key definition failed with model container
hilljh82 50e409b
Reverted change
hilljh82 6dfd5d6
Removed test files
hilljh82 f3935e1
Merge from raizlabs/develop
hilljh82 0947f8c
Added missing code for checkNeedsReferences()
hilljh82 118204a
Removed faulty line of code
hilljh82 2a450a2
Added missing check for external foreign key
hilljh82 36b7fa7
Overrided the newInstance() method
hilljh82 f98ebc2
Merge from Raizlabs/master
hilljh82 9431b13
Fixed error preventing Jitpack from working
hilljh82 e483520
Merge from master
hilljh82 1e05a47
Fixed build errors
hilljh82 ccdb83b
Fixed build error
hilljh82 49d3993
Fixed compilation errors
hilljh82 25403c8
Merge branch 'master' into develop
hilljh82 e3b8ecb
Switch to AsyncTaskLoader in Android support library
hilljh82 536a5bb
Added missing dependency
hilljh82 36b144d
Fixed build issues with API version
hilljh82 cff3e40
Merge from Raizlabs/develop
hilljh82 09f1be7
Merge from Raizlabs/master
hilljh82 956fc1b
Merge branch 'master' into develop
hilljh82 63fe220
Fixed issues in implementation
hilljh82 008dc04
Loaders for single model queries
hilljh82 a7105b4
Relocated file
hilljh82 1508e00
Added support for Travis CI
hilljh82 464ba50
Moved Travis-CI config to different branch
hilljh82 f5a5b13
Moved ExternalForeignKey annotation to its own branch
hilljh82 d983e5f
Added documentation; fixed spacing issues
hilljh82 9632cd8
Fixed format
hilljh82 7d79b78
Fixed format
hilljh82 aa85b79
Removed unused variables; fixed formatting
hilljh82 f0ab254
Fixed merge: Updated sdk version numbers to be compatible with depend…
hilljh82 344a9a5
Fixed build error
hilljh82 dea07b7
Merge from Raizlabs/develop
hilljh82 a1b9485
Fixed build errors related to updates to raizlabs/develop
hilljh82 56392ad
Fixed merge conflicts
hilljh82 34acd05
Fixed merge conflicts
hilljh82 0212982
Fixed merge conflicts
hilljh82 d1a52cb
Fixed merge conflicts
hilljh82 fd72253
Removed obsolete file
hilljh82 0554ec4
Fixed formatting issues
hilljh82 8d72965
For some reason, lintOptions was added to the build config
hilljh82 d019191
PropertyExtensions was changed during the merge; this file should not…
hilljh82 aff9722
Removed obsolete file
hilljh82 a613727
Fixed naming convention on class variables
hilljh82 d7d188e
Fixed naming convention on class variables
hilljh82 c97f1b3
Fixed refactoring error
hilljh82 83ac02d
Fixed refactoring error
hilljh82 4cd5e39
Fixed naming conventions errors
hilljh82 0067c1e
Fixed naming conventions errors
hilljh82 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loaders for single model queries
- Loading branch information
commit 008dc04073bc5e8318d80e2c02f9ef8701073179
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
dbflow/src/main/java/com/raizlabs/android/dbflow/single/FlowModelLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.raizlabs.android.dbflow.single; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
|
||
import com.raizlabs.android.dbflow.config.FlowManager; | ||
import com.raizlabs.android.dbflow.sql.queriable.Queriable; | ||
import com.raizlabs.android.dbflow.structure.Model; | ||
|
||
/** | ||
* Load a single model from the database. | ||
* | ||
* @param <TModel> | ||
*/ | ||
@TargetApi(11) | ||
public class FlowModelLoader <TModel extends Model> | ||
extends FlowSingleModelLoader<TModel, TModel> | ||
{ | ||
public FlowModelLoader (Context context, Class<TModel> model, Queriable queriable) | ||
{ | ||
super (context, model, FlowManager.getModelAdapter (model), queriable); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
dbflow/src/main/java/com/raizlabs/android/dbflow/single/FlowModelViewLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.raizlabs.android.dbflow.single; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
|
||
import com.raizlabs.android.dbflow.config.FlowManager; | ||
import com.raizlabs.android.dbflow.sql.queriable.Queriable; | ||
import com.raizlabs.android.dbflow.structure.BaseModelView; | ||
import com.raizlabs.android.dbflow.structure.InstanceAdapter; | ||
import com.raizlabs.android.dbflow.structure.Model; | ||
|
||
/** | ||
* Utility class to be added to DBFlow. | ||
* | ||
* @param <TModel> | ||
*/ | ||
@TargetApi(11) | ||
public class FlowModelViewLoader <TModel extends Model, TModelView extends BaseModelView<TModel>> | ||
extends FlowSingleModelLoader<TModel, TModelView> | ||
{ | ||
public FlowModelViewLoader (Context context, | ||
Class <TModel> model, | ||
Class <TModelView> modelView, | ||
Queriable queriable) | ||
{ | ||
super (context, model, (InstanceAdapter<TModel, TModelView>) FlowManager.getModelViewAdapter (modelView), queriable); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
dbflow/src/main/java/com/raizlabs/android/dbflow/single/FlowQueryModelLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.raizlabs.android.dbflow.single; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
|
||
import com.raizlabs.android.dbflow.config.FlowManager; | ||
import com.raizlabs.android.dbflow.sql.queriable.Queriable; | ||
import com.raizlabs.android.dbflow.structure.BaseQueryModel; | ||
|
||
/** | ||
* Utility class to be added to DBFlow. | ||
* | ||
* @param <TQueryModel> | ||
*/ | ||
@TargetApi(11) | ||
public class FlowQueryModelLoader <TQueryModel extends BaseQueryModel> | ||
extends FlowSingleModelLoader<TQueryModel, TQueryModel> | ||
{ | ||
public FlowQueryModelLoader (Context context, | ||
Class <TQueryModel> model, | ||
Queriable queriable) | ||
{ | ||
super (context, model, FlowManager.getQueryModelAdapter (model), queriable); | ||
this.setObserveModel (false); | ||
} | ||
} |
167 changes: 167 additions & 0 deletions
167
dbflow/src/main/java/com/raizlabs/android/dbflow/single/FlowSingleModelLoader.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
package com.raizlabs.android.dbflow.single; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.net.Uri; | ||
import android.support.v4.content.AsyncTaskLoader; | ||
|
||
import com.raizlabs.android.dbflow.runtime.FlowContentObserver; | ||
import com.raizlabs.android.dbflow.sql.queriable.Queriable; | ||
import com.raizlabs.android.dbflow.structure.InstanceAdapter; | ||
import com.raizlabs.android.dbflow.structure.Model; | ||
|
||
import java.util.HashSet; | ||
|
||
/** | ||
* Utility class to be added to DBFlow. | ||
* | ||
* @param <TModel> | ||
*/ | ||
@TargetApi(11) | ||
public abstract class FlowSingleModelLoader <TModel extends Model, TTable extends Model> | ||
extends AsyncTaskLoader<TModel> | ||
{ | ||
/// Models to be observed for changes. | ||
private final Class<TModel> mModel; | ||
private final InstanceAdapter<TModel, TTable> mAdapter; | ||
|
||
/// Queriable operation that the loader executes. | ||
private Queriable mQueriable; | ||
|
||
/// Cursor for the loader. | ||
private TModel mResult; | ||
|
||
private boolean mObserveModel = true; | ||
|
||
private static final String TAG = "FlowSingleModelLoader"; | ||
|
||
protected HashSet<? extends Model> mModels = new HashSet<> (); | ||
|
||
private class ForceLoadContentObserver extends FlowContentObserver | ||
{ | ||
@Override | ||
public boolean deliverSelfNotifications () | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onChange (boolean selfChange) | ||
{ | ||
super.onChange (selfChange); | ||
|
||
onContentChanged (); | ||
} | ||
|
||
@Override | ||
public void onChange (boolean selfChange, Uri uri) | ||
{ | ||
super.onChange (selfChange, uri); | ||
|
||
onContentChanged (); | ||
} | ||
} | ||
|
||
protected final FlowContentObserver mObserver = new ForceLoadContentObserver (); | ||
|
||
protected FlowSingleModelLoader (Context context, | ||
Class<TModel> model, | ||
InstanceAdapter<TModel, TTable> adapter, | ||
Queriable queriable) | ||
{ | ||
super (context); | ||
|
||
this.mQueriable = queriable; | ||
this.mModel = model; | ||
this.mAdapter = adapter; | ||
} | ||
|
||
/* Runs on a worker thread */ | ||
@Override | ||
public TModel loadInBackground () | ||
{ | ||
Cursor cursor = this.mQueriable.query (); | ||
|
||
if (cursor == null || !cursor.moveToFirst ()) | ||
return null; | ||
|
||
TModel model = this.mAdapter.newInstance (); | ||
this.mAdapter.loadFromCursor (cursor, model); | ||
|
||
return model; | ||
} | ||
|
||
/* Runs on the UI thread */ | ||
@Override | ||
public void deliverResult (TModel result) | ||
{ | ||
this.mResult = result; | ||
|
||
if (this.isStarted ()) | ||
super.deliverResult (result); | ||
} | ||
|
||
/** | ||
* Starts an asynchronous load of the contacts list data. When the result is ready the callbacks | ||
* will be called on the UI thread. If a previous load has been completed and is still valid the | ||
* result may be passed to the callbacks immediately. | ||
* <p> | ||
* Must be called from the UI thread | ||
*/ | ||
@Override | ||
protected void onStartLoading () | ||
{ | ||
if (mResult != null) | ||
this.deliverResult (mResult); | ||
|
||
// Start watching for changes to the model. | ||
if (this.mObserveModel) | ||
this.registerForContentChanges (this.mModel); | ||
|
||
if (this.takeContentChanged () || this.mResult == null) | ||
this.forceLoad (); | ||
} | ||
|
||
/** | ||
* Must be called from the UI thread | ||
*/ | ||
@Override | ||
protected void onStopLoading () | ||
{ | ||
this.cancelLoad (); | ||
} | ||
|
||
@Override | ||
protected void onReset () | ||
{ | ||
super.onReset (); | ||
|
||
// Ensure the loader is stopped | ||
this.onStopLoading (); | ||
|
||
if (this.mResult != null) | ||
this.mResult = null; | ||
|
||
// Unregister the loader for content changes. | ||
this.mObserver.unregisterForContentChanges (this.getContext ()); | ||
} | ||
|
||
public Class<TModel> getModel () | ||
{ | ||
return this.mModel; | ||
} | ||
|
||
public void setObserveModel (boolean observeModel) | ||
{ | ||
this.mObserveModel = observeModel; | ||
} | ||
|
||
public void registerForContentChanges (Class<? extends Model> model) | ||
{ | ||
if (this.mModels.contains (model)) | ||
return; | ||
|
||
this.mObserver.registerForContentChanges (this.getContext (), model); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#req no model restriction anywhere please.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#? How do you ensure the class is only parameterized by DBFlow
Model
-like classes? Is this no longer a concern with 4.x.x? Also, doing so will mean removing restrictions on certain methods that should only be called with class that derive fromModel
, such asregisterForContentChanges
. This would be an introduction of an accidental complicity in the design.