本文整理匯總了Java中com.raizlabs.android.dbflow.structure.BaseModel類的典型用法代碼示例。如果您正苦於以下問題:Java BaseModel類的具體用法?Java BaseModel怎麽用?Java BaseModel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BaseModel類屬於com.raizlabs.android.dbflow.structure包,在下文中一共展示了BaseModel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: save
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
/**
* 新增或者修改數據庫的統一方法
* @param tClass 傳遞一個class信息
* @param models 這個class對應的實例的數組
* @param <Model> 這個實例的泛型 限定條件是BaseModel
*/
public static<Model extends BaseModel> void save(final Class<Model> tClass, final Model... models) {
if (models==null||models.length==0) return;
// 當前數據庫的一個管理者
DatabaseDefinition definition = FlowManager.getDatabase(AppDatabase.class);
// 提交一個事務
definition.beginTransactionAsync(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// 執行
ModelAdapter<Model> adapter = FlowManager.getModelAdapter(tClass);
// 保存
adapter.saveAll(Arrays.asList(models));
// 喚起通知
instance.notifySave(tClass,models);
}
}).build().execute();
}
示例2: delete
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
/**
* 刪除數據庫的的統一方法
* @param tClass 傳遞一個class信息
* @param models 這個class對應的實例的數組
* @param <Model> 這個實例的泛型 限定條件是BaseModel
*/
public static<Model extends BaseModel> void delete(final Class<Model> tClass, final Model... models) {
if (models==null||models.length==0) return;
// 當前數據庫的一個管理者
DatabaseDefinition definition = FlowManager.getDatabase(AppDatabase.class);
// 提交一個事務
definition.beginTransactionAsync(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// 執行
ModelAdapter<Model> adapter = FlowManager.getModelAdapter(tClass);
// 刪除
adapter.deleteAll(Arrays.asList(models));
// 喚起通知
instance.notifyDelete(tClass,models);
}
}).build().execute();
}
示例3: notifySave
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
/**
* 進行通知調用
*
* @param tClass 通知的類型
* @param models 通知的model數組
* @param <Model>這個實例的泛型 限定條件是BaseModel
*/
private final <Model extends BaseModel> void notifySave(final Class<Model> tClass, final Model... models) {
// 找監聽器
final Set<ChangedListener> listeners = getListeners(tClass);
if (listeners != null && listeners.size() > 0) {
// 通用的通知
for (ChangedListener<Model> listener : listeners) {
listener.onDataSave(models);
}
}
// 列外情況
if (GroupMember.class.equals(tClass)) {
// 群成員變更,需要通知對應群信息更新
updateGroup((GroupMember[]) models);
} else if (Message.class.equals(tClass)) {
// 消息變化,應該通知會話列表更新
updateSession((Message[]) models);
}
}
示例4: notifyDelete
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
/**
* 進行通知調用
*
* @param tClass 通知的類型
* @param models 通知的model數組
* @param <Model>這個實例的泛型 限定條件是BaseModel
*/
private final <Model extends BaseModel> void notifyDelete(final Class<Model> tClass, final Model... models) {
// 找監聽器
final Set<ChangedListener> listeners = getListeners(tClass);
if (listeners != null && listeners.size() > 0) {
// 通用的通知
for (ChangedListener<Model> listener : listeners) {
listener.onDataDelete(models);
}
}
// 列外情況
if (GroupMember.class.equals(tClass)) {
// 群成員變更,需要通知對應群信息更新
updateGroup((GroupMember[]) models);
} else if (Message.class.equals(tClass)) {
// 消息變化,應該通知會話列表更新
updateSession((Message[]) models);
}
}
示例5: onNext
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
@Override
public void onNext(T o) {
mActual.onNext(o);
for (int i = 0; i < mSubscribedClasses.size(); i++) {
mFlowContentObserver.registerForContentChanges(FlowManager.getContext(), mSubscribedClasses.get(i));
}
mFlowContentObserver.addOnTableChangedListener(
new FlowContentObserver.OnTableChangedListener() {
@Override
public void onTableChanged(@Nullable Class<?> tableChanged, BaseModel.Action action) {
if(isDisposed()){
return;
}
if (!mIsInTransaction) {
mActual.onNext(mRestartAction.run());
} else {
mHasPendingChange = true;
}
}
});
}
示例6: onComplete
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
@Override
public void onComplete() {
if(mQuery.toLowerCase().contains("delete ")){
SqlUtils.notifyModelChanged(mModelClazz, BaseModel.Action.DELETE, null);
} else if(mQuery.toLowerCase().contains("update ")){
SqlUtils.notifyModelChanged(mModelClazz, BaseModel.Action.UPDATE, null);
}
mActual.onComplete();
}
示例7: call
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
@Override
public Subscriber<? super Void> call(final Subscriber<? super Void> subscriber) {
return new Subscriber<Void>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(Void tModels) {
subscriber.onNext(tModels);
if(mBaseQueriable.getQuery().toLowerCase().contains("delete")){
SqlUtils.notifyModelChanged(mModelClazz, BaseModel.Action.DELETE, null);
} else if(mBaseQueriable.getQuery().toLowerCase().contains("update")){
SqlUtils.notifyModelChanged(mModelClazz, BaseModel.Action.UPDATE, null);
}
}
};
}
示例8: deleteAndInsertEntities
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
@CheckResult
@NonNull
@Override
public Single<List<D>> deleteAndInsertEntities(@Nullable List<D> entitiesToInsert,
@NonNull SQLOperator... conditionsToDelete) {
return Single
.fromCallable(() -> {
FlowManager.getDatabase(getAppDataBaseClass())
.executeTransaction(databaseWrapper -> {
SQLite.delete(getModelClass())
.where(conditionsToDelete)
.execute();
Stream.ofNullable(entitiesToInsert)
.forEach(BaseModel::save);
});
return entitiesToInsert;
})
.subscribeOn(Schedulers.io());
}
示例9: preloadTabItems
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
public static List preloadTabItems(Tab tab, String module){
List<? extends BaseModel> items;
if (tab.isCompositeScore())
items = CompositeScore.listByProgram(Session.getSurveyByModule(module).getProgram());
else{
items=Session.getTabsCache().get(tab.getId_tab());
if (items == null) {
items = convertTabToArrayCustom(tab);
}
Session.getTabsCache().put(tab.getId_tab(), items);
}
return compressTabItems(items);
}
示例10: preloadTabItems
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
public static List preloadTabItems(Tab tab, String module) {
List<? extends BaseModel> items;
if (tab.isCompositeScore()) {
items = CompositeScore.listByProgram(Session.getSurveyByModule(module).getProgram());
} else {
items = Session.getTabsCache().get(tab.getId_tab());
if (items == null) {
items = convertTabToArrayCustom(tab);
}
Session.getTabsCache().put(tab.getId_tab(), items);
}
return compressTabItems(items);
}
示例11: save
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
public synchronized boolean save(@NonNull TModel model, @NonNull DatabaseWrapper wrapper) {
boolean exists = getModelAdapter().exists(model, wrapper);
if (exists) {
exists = update(model, wrapper);
}
if (!exists) {
exists = insert(model, wrapper) > INSERT_FAILED;
}
if (exists) {
NotifyDistributor.get().notifyModelChanged(model, getModelAdapter(), BaseModel.Action.SAVE);
}
// return successful store into db.
return exists;
}
示例12: update
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
/**
* @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;
}
示例13: insert
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
@Override
public synchronized long insert(@NonNull TModel model, @NonNull DatabaseWrapper wrapper) {
final boolean hasAutoIncrement = getModelAdapter().hasAutoIncrement(model);
DatabaseStatement insertStatement = hasAutoIncrement
? getModelAdapter().getCompiledStatement(wrapper)
: getModelAdapter().getInsertStatement(wrapper);
long id;
try {
getModelAdapter().saveForeignKeys(model, wrapper);
if (hasAutoIncrement) {
getModelAdapter().bindToStatement(insertStatement, model);
} else {
getModelAdapter().bindToInsertStatement(insertStatement, model);
}
id = insertStatement.executeInsert();
if (id > INSERT_FAILED) {
getModelAdapter().updateAutoIncrement(model, id);
NotifyDistributor.get().notifyModelChanged(model, getModelAdapter(), BaseModel.Action.INSERT);
}
} finally {
// since we generate an insert every time, we can safely close the statement here.
insertStatement.close();
}
return id;
}
示例14: addChangedListener
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
/**
* 添加一個監聽
*
* @param tClass 對某個表關注
* @param listener 監聽者
* @param <Model> 表的範型
*
*/
public static <Model extends BaseModel> void addChangedListener(final Class<Model> tClass,
ChangedListener<Model> listener) {
java.util.Set<ChangedListener> changedListeners = instance.getListeners(tClass);
if (changedListeners == null) {
// 初始化某一類型的容器
changedListeners = new HashSet<>();
// 添加到中的Map
instance.changedListeners.put(tClass, changedListeners);
}
changedListeners.add(listener);
}
示例15: removeChangedListener
import com.raizlabs.android.dbflow.structure.BaseModel; //導入依賴的package包/類
/**
* 刪除某一個表的某一個監聽器
*
* @param tClass 表
* @param listener 監聽器
* @param <Model> 表的範型
*/
public static <Model extends BaseModel> void removeChangedListener(final Class<Model> tClass,
ChangedListener<Model> listener) {
java.util.Set<ChangedListener> changedListeners = instance.getListeners(tClass);
if (changedListeners == null) {
// 容器本身為null,代表根本就沒有
return;
}
// 從容器中刪除你這個監聽者
changedListeners.remove(listener);
}