本文整理汇总了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);
}