com.raizlabs.android.dbflow.structure.BaseModel Java Examples
The following examples show how to use
com.raizlabs.android.dbflow.structure.BaseModel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelSaver.java From Meteorite with Apache License 2.0 | 6 votes |
/** * @see #update(Object, DatabaseWrapper, DatabaseStatement) */ @Deprecated @SuppressWarnings("unchecked") public synchronized boolean update(@NonNull TModel model, @NonNull DatabaseWrapper wrapper, @NonNull ContentValues contentValues) { modelAdapter.saveForeignKeys(model, wrapper); modelAdapter.bindToContentValues(contentValues, model); boolean successful = wrapper.updateWithOnConflict(modelAdapter.getTableName(), contentValues, modelAdapter.getPrimaryConditionClause(model).getQuery(), null, ConflictAction.getSQLiteDatabaseAlgorithmInt(modelAdapter.getUpdateOnConflictAction())) != 0; if (successful) { NotifyDistributor.get().notifyModelChanged(model, modelAdapter, BaseModel.Action.UPDATE); } return successful; }
Example #2
Source File: ModelSaver.java From Meteorite with Apache License 2.0 | 6 votes |
/** * Legacy save method. Uses {@link ContentValues} vs. the faster {@link DatabaseStatement} for updates. * * @see #save(Object, DatabaseWrapper, DatabaseStatement, DatabaseStatement) */ @Deprecated @SuppressWarnings({"unchecked", "deprecation"}) public synchronized boolean save(@NonNull TModel model, @NonNull DatabaseWrapper wrapper, @NonNull DatabaseStatement insertStatement, @NonNull ContentValues contentValues) { boolean exists = modelAdapter.exists(model, wrapper); if (exists) { exists = update(model, wrapper, contentValues); } if (!exists) { exists = insert(model, insertStatement, wrapper) > INSERT_FAILED; } if (exists) { NotifyDistributor.get().notifyModelChanged(model, modelAdapter, BaseModel.Action.SAVE); } // return successful store into db. return exists; }
Example #3
Source File: ModelSaver.java From Meteorite with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public synchronized boolean save(@NonNull TModel model, @NonNull DatabaseWrapper wrapper, @NonNull DatabaseStatement insertStatement, @NonNull DatabaseStatement updateStatement) { boolean exists = modelAdapter.exists(model, wrapper); if (exists) { exists = update(model, wrapper, updateStatement); } if (!exists) { exists = insert(model, insertStatement, wrapper) > INSERT_FAILED; } if (exists) { NotifyDistributor.get().notifyModelChanged(model, modelAdapter, BaseModel.Action.SAVE); } // return successful store into db. return exists; }
Example #4
Source File: ModelSaver.java From Meteorite with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public synchronized long insert(@NonNull TModel model, @NonNull DatabaseStatement insertStatement, @NonNull DatabaseWrapper wrapper) { modelAdapter.saveForeignKeys(model, wrapper); modelAdapter.bindToInsertStatement(insertStatement, model); long id = insertStatement.executeInsert(); if (id > INSERT_FAILED) { modelAdapter.updateAutoIncrement(model, id); NotifyDistributor.get().notifyModelChanged(model, modelAdapter, BaseModel.Action.INSERT); } return id; }
Example #5
Source File: DbLoader.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 5 votes |
public TrackedTable(Class<? extends Model> trackedModel) { this(trackedModel, Arrays.asList( BaseModel.Action.INSERT, BaseModel.Action.UPDATE, BaseModel.Action.DELETE, BaseModel.Action.SAVE)); }
Example #6
Source File: ModelChangeObserver.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onModelStateChanged(Class<? extends Model> aClass, BaseModel.Action action) { Log.d(TAG, "onModelStateChanged() " + aClass.getSimpleName() + ": " + action); if (notifyLoader(action)) { mLoader.onContentChanged(); } }
Example #7
Source File: ModelChangeObserver.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean notifyLoader(BaseModel.Action action) { if (mTrackedTable.getActions().isEmpty()) { return true; } for (BaseModel.Action modelAction : mTrackedTable.getActions()) { if (modelAction.equals(action)) { return true; } } return false; }
Example #8
Source File: ModelSaver.java From Meteorite with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public synchronized boolean delete(@NonNull TModel model, @NonNull DatabaseStatement deleteStatement, @NonNull DatabaseWrapper wrapper) { modelAdapter.deleteForeignKeys(model, wrapper); modelAdapter.bindToDeleteStatement(deleteStatement, model); boolean success = deleteStatement.executeUpdateDelete() != 0; if (success) { NotifyDistributor.get().notifyModelChanged(model, modelAdapter, BaseModel.Action.DELETE); } modelAdapter.updateAutoIncrement(model, 0); return success; }
Example #9
Source File: ModelSaver.java From Meteorite with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public synchronized boolean update(@NonNull TModel model, @NonNull DatabaseWrapper wrapper, @NonNull DatabaseStatement databaseStatement) { modelAdapter.saveForeignKeys(model, wrapper); modelAdapter.bindToUpdateStatement(databaseStatement, model); boolean successful = databaseStatement.executeUpdateDelete() != 0; if (successful) { NotifyDistributor.get().notifyModelChanged(model, modelAdapter, BaseModel.Action.UPDATE); } return successful; }
Example #10
Source File: ContentResolverNotifier.java From Meteorite with Apache License 2.0 | 5 votes |
@Override public <T> void notifyTableChanged(@NonNull Class<T> table, @NonNull BaseModel.Action action) { if (FlowContentObserver.shouldNotify()) { FlowManager.getContext().getContentResolver() .notifyChange(SqlUtils.getNotificationUri(table, action, (SQLOperator[]) null), null, true); } }
Example #11
Source File: InterpretationContainerFragment.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Loader<Boolean> onCreateLoader(int i, Bundle bundle) { List<BaseModel.Action> actionsToTrack = Arrays.asList( BaseModel.Action.INSERT, BaseModel.Action.DELETE); List<DbLoader.TrackedTable> trackedTables = Arrays.asList( new DbLoader.TrackedTable(Interpretation.class, actionsToTrack)); return new DbLoader<>(getActivity().getApplicationContext(), trackedTables, new InterpretationsQuery()); }
Example #12
Source File: DirectModelNotifier.java From Meteorite with Apache License 2.0 | 5 votes |
@Override public <T> void notifyTableChanged(@NonNull Class<T> table, @NonNull BaseModel.Action action) { final Set<OnTableChangedListener> listeners = tableChangedListenerMap.get(table); if (listeners != null) { for (OnTableChangedListener listener : listeners) { if (listener != null) { listener.onTableChanged(table, action); } } } }
Example #13
Source File: DirectModelNotifier.java From Meteorite with Apache License 2.0 | 5 votes |
@Override public <T> void notifyModelChanged(@NonNull T model, @NonNull ModelAdapter<T> adapter, @NonNull BaseModel.Action action) { final Set<OnModelStateChangedListener> listeners = modelChangedListenerMap.get(adapter.getModelClass()); if (listeners != null) { for (OnModelStateChangedListener listener : listeners) { if (listener != null) { listener.onModelChanged(model, action); } } } }
Example #14
Source File: DashboardContainerFragment.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Loader<Boolean> onCreateLoader(int id, Bundle args) { List<BaseModel.Action> actionsToTrack = Arrays.asList( BaseModel.Action.INSERT, BaseModel.Action.DELETE); List<DbLoader.TrackedTable> trackedTables = Arrays.asList( new DbLoader.TrackedTable(Dashboard.class, actionsToTrack)); return new DbLoader<>(getActivity().getApplicationContext(), trackedTables, new DashboardsQuery()); }
Example #15
Source File: NotifyDistributor.java From Meteorite with Apache License 2.0 | 5 votes |
@Override public <TModel> void notifyModelChanged(@NonNull TModel model, @NonNull ModelAdapter<TModel> adapter, @NonNull BaseModel.Action action) { FlowManager.getModelNotifierForTable(adapter.getModelClass()) .notifyModelChanged(model, adapter, action); }
Example #16
Source File: ContentResolverNotifier.java From Meteorite with Apache License 2.0 | 5 votes |
@Override public <T> void notifyModelChanged(@NonNull T model, @NonNull ModelAdapter<T> adapter, @NonNull BaseModel.Action action) { if (FlowContentObserver.shouldNotify()) { FlowManager.getContext().getContentResolver() .notifyChange(SqlUtils.getNotificationUri(adapter.getModelClass(), action, adapter.getPrimaryConditionClause(model).getConditions()), null, true); } }
Example #17
Source File: InterpretationCommentsFragment.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Loader<List<InterpretationComment>> onCreateLoader(int id, Bundle args) { if (LOADER_ID == id) { List<TrackedTable> trackedTables = Arrays.asList( new TrackedTable(InterpretationComment.class, BaseModel.Action.UPDATE)); return new DbLoader<>(getActivity().getApplicationContext(), trackedTables, new CommentsQuery(args.getLong(INTERPRETATION_ID))); } return null; }
Example #18
Source File: DbOperation.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static <T extends BaseModel> DbOperation update(T model) { return new DbOperation(BaseModel.Action.UPDATE, model); }
Example #19
Source File: DbLoader.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public TrackedTable(Class<? extends Model> trackedModel, BaseModel.Action action) { this(trackedModel, Arrays.asList(action)); }
Example #20
Source File: DbLoader.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public TrackedTable(Class<? extends Model> trackedModel, List<BaseModel.Action> actions) { mTrackedModel = trackedModel; mActions = actions; }
Example #21
Source File: DbLoader.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public List<BaseModel.Action> getActions() { return mActions; }
Example #22
Source File: DbOperation.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
private DbOperation(BaseModel.Action action, BaseModel model) { mModel = isNull(model, "BaseModel object must nto be null,"); mAction = isNull(action, "BaseModel.Action object must not be null"); }
Example #23
Source File: DbOperation.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static <T extends BaseModel> DbOperation insert(T model) { return new DbOperation(BaseModel.Action.INSERT, model); }
Example #24
Source File: DbOperation.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static <T extends BaseModel> DbOperation save(T model) { return new DbOperation(BaseModel.Action.SAVE, model); }
Example #25
Source File: Where.java From Meteorite with Apache License 2.0 | 4 votes |
@NonNull @Override public BaseModel.Action getPrimaryAction() { return whereBase.getPrimaryAction(); }
Example #26
Source File: DbOperation.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public BaseModel.Action getAction() { return mAction; }
Example #27
Source File: DbOperation.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public BaseModel getModel() { return mModel; }
Example #28
Source File: DbOperation.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static <T extends BaseModel> DbOperation delete(T model) { return new DbOperation(BaseModel.Action.DELETE, model); }
Example #29
Source File: HttpKit.java From UPMiss with GNU General Public License v3.0 | 4 votes |
public static GsonBuilder getRspGsonBuilder() { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.setExclusionStrategies(new SpecificClassExclusionStrategy(null, BaseModel.class)); gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ss"); return gsonBuilder; }
Example #30
Source File: NotifyDistributor.java From Meteorite with Apache License 2.0 | 4 votes |
/** * Notifies listeners of table-level changes from the SQLite-wrapper language. */ @Override public <TModel> void notifyTableChanged(@NonNull Class<TModel> table, @NonNull BaseModel.Action action) { FlowManager.getModelNotifierForTable(table).notifyTableChanged(table, action); }