本文整理汇总了Java中com.raizlabs.android.dbflow.structure.database.DatabaseWrapper类的典型用法代码示例。如果您正苦于以下问题:Java DatabaseWrapper类的具体用法?Java DatabaseWrapper怎么用?Java DatabaseWrapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabaseWrapper类属于com.raizlabs.android.dbflow.structure.database包,在下文中一共展示了DatabaseWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的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.database.DatabaseWrapper; //导入依赖的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: updateGroup
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
/**
* 从成员中找出成员对应的群,并对群进行更新
*
* @param members 群成员列表
*/
private void updateGroup(GroupMember... members) {
// 不重复集合
final Set<String> groupIds = new HashSet<>();
for (GroupMember member : members) {
// 添加群Id
groupIds.add(member.getGroup().getId());
}
// 异步的数据库查询,并异步的发起二次通知
DatabaseDefinition definition = FlowManager.getDatabase(AppDatabase.class);
definition.beginTransactionAsync(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// 找到需要通知的群
List<Group> groups = SQLite.select()
.from(Group.class)
.where(Group_Table.id.in(groupIds))
.queryList();
// 调用直接进行一次通知分发
instance.notifySave(Group.class, groups.toArray(new Group[0]));
}
}).build().execute();
}
示例4: migrate
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
@Override
public void migrate(DatabaseWrapper database) {
//The column name can't be renamed in sqlite. It is needed create a temporal table with the new column name.
ModelAdapter myAdapter = FlowManager.getModelAdapter(Survey.class);
//Create temporal table
String sql=myAdapter.getCreationQuery();
Log.d("DBMIGRATION", "old table " + sql);
sql=sql.replace("Survey", "Survey_temp");
Log.d("DBMIGRATION", "create temp table " + sql);
database.execSQL(sql);
//Insert the data in temporal table
String sqlCopy="INSERT INTO Survey_temp(id_survey, id_tab_group, id_org_unit, id_user, creationDate, completionDate, uploadedDate, scheduledDate, status, eventuid) SELECT id_survey, id_tab_group, id_org_unit, id_user, creationDate, completionDate, eventDate, scheduledDate, status, eventuid FROM Survey";
database.execSQL(sqlCopy);
//Replace old table by new table with the new column name.
database.execSQL("DROP TABLE IF EXISTS Survey");
database.execSQL("ALTER TABLE Survey_temp RENAME TO Survey");
}
示例5: migrateSurveyTable
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
private void migrateSurveyTable(DatabaseWrapper database) {
ModelAdapter myAdapter = FlowManager.getModelAdapter(Survey.class);
//Create temporal table
String sql=myAdapter.getCreationQuery();
Log.d("DBMIGRATION", "old table " + sql);
sql=sql.replace("Survey", "Survey_temp");
Log.d("DBMIGRATION", "create temp table " + sql);
database.execSQL(sql);
//Insert the data in temporal table
String sqlCopy="INSERT INTO Survey_temp(id_survey, id_program, id_org_unit, id_user, creation_date, completion_date, upload_date, scheduled_date, status, eventuid) SELECT id_survey, id_tab_group, id_org_unit, id_user, creationDate, completionDate, uploadedDate, scheduledDate, status, eventuid FROM Survey";
database.execSQL(sqlCopy);
//Replace old table by new table with the new column name.
database.execSQL("DROP TABLE IF EXISTS Survey");
database.execSQL("ALTER TABLE Survey_temp RENAME TO Survey");
}
示例6: migrate
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
@Override
public void migrate(DatabaseWrapper database) {
String sqlOptionTemp =
"CREATE TABLE OptionTemp(id_option INTEGER PRIMARY KEY, code TEXT, name TEXT, "
+ "factor REAL, id_answer_fk INTEGER, id_option_attribute_fk INTEGER)";
database.execSQL(sqlOptionTemp);
String sqlCopyOption =
"INSERT INTO OptionTemp(id_option, code, name, factor, id_answer_fk, "
+ "id_option_attribute_fk) "
+ "SELECT id_option, name, code, factor, id_answer_fk, "
+ "id_option_attribute_fk "
+ "FROM Option;";
database.execSQL(sqlCopyOption);
String sqlDeleteOption = "DROP TABLE Option";
database.execSQL(sqlDeleteOption);
String sqlRenameOptionTemp = "ALTER TABLE OptionTemp RENAME TO Option";
database.execSQL(sqlRenameOptionTemp);
}
示例7: executeUpdateDelete
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
@Override
public long executeUpdateDelete(@NonNull DatabaseWrapper databaseWrapper) {
final DatabaseStatement statement = databaseWrapper.compileStatement(getQuery());
long affected;
try {
affected = statement.executeUpdateDelete();
// only notify for affected.
if (affected > 0) {
NotifyDistributor.get().notifyTableChanged(getTable(), getPrimaryAction());
}
} finally {
statement.close();
}
return affected;
}
示例8: save
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的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;
}
示例9: updateAll
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
@Override
public synchronized void updateAll(@NonNull Collection<TModel> tableCollection,
@NonNull DatabaseWrapper wrapper) {
// skip if empty.
if (tableCollection.isEmpty()) {
return;
}
ModelSaver<TModel> modelSaver = getModelSaver();
ModelAdapter<TModel> modelAdapter = modelSaver.getModelAdapter();
DatabaseStatement statement = modelAdapter.getUpdateStatement(wrapper);
try {
for (TModel model : tableCollection) {
if (modelSaver.update(model, wrapper, statement)) {
modelAdapter.storeModelInCache(model);
}
}
} finally {
statement.close();
}
}
示例10: insert
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的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;
}
示例11: saveAll
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
public synchronized void saveAll(@NonNull Collection<TModel> tableCollection,
@NonNull DatabaseWrapper wrapper) {
// skip if empty.
if (tableCollection.isEmpty()) {
return;
}
DatabaseStatement statement = modelSaver.getModelAdapter().getInsertStatement(wrapper);
DatabaseStatement updateStatement = modelSaver.getModelAdapter().getUpdateStatement(wrapper);
try {
for (TModel model : tableCollection) {
modelSaver.save(model, wrapper, statement, updateStatement);
}
} finally {
statement.close();
updateStatement.close();
}
}
示例12: updateAll
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
public synchronized void updateAll(@NonNull Collection<TModel> tableCollection,
@NonNull DatabaseWrapper wrapper) {
// skip if empty.
if (tableCollection.isEmpty()) {
return;
}
DatabaseStatement updateStatement = modelSaver.getModelAdapter().getUpdateStatement(wrapper);
try {
for (TModel model : tableCollection) {
modelSaver.update(model, wrapper, updateStatement);
}
} finally {
updateStatement.close();
}
}
示例13: upDataBySynchronous
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
public static void upDataBySynchronous(final ArrayList<SOListBean.ListBean> mListBeans, final String type){
DatabaseDefinition database = FlowManager.getDatabase(LueansDB.class);
database.executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// do something here
deleteSoDdata(type);
saveSoData(mListBeans,type);
}
});
}
示例14: exists
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
@Override
public final boolean exists(WeatherData model, DatabaseWrapper wrapper) {
return SQLite.selectCountOf()
.from(WeatherData.class)
.where(getPrimaryConditionClause(model))
.hasData(wrapper);
}
示例15: exists
import com.raizlabs.android.dbflow.structure.database.DatabaseWrapper; //导入依赖的package包/类
@Override
public final boolean exists(WeatherData.Weather model, DatabaseWrapper wrapper) {
return (model.getWId() != null && model.getWId() > 0 || model.getWId() == null)
&& SQLite.selectCountOf()
.from(WeatherData.Weather.class)
.where(getPrimaryConditionClause(model))
.hasData(wrapper);
}