本文整理汇总了Java中com.raizlabs.android.dbflow.structure.database.transaction.ITransaction类的典型用法代码示例。如果您正苦于以下问题:Java ITransaction类的具体用法?Java ITransaction怎么用?Java ITransaction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITransaction类属于com.raizlabs.android.dbflow.structure.database.transaction包,在下文中一共展示了ITransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: save
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的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();
}
开发者ID:FZZFVII,项目名称:pipe,代码行数:24,代码来源:DbHelper.java
示例2: delete
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的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();
}
开发者ID:FZZFVII,项目名称:pipe,代码行数:24,代码来源:DbHelper.java
示例3: updateGroup
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的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();
}
开发者ID:FZZFVII,项目名称:pipe,代码行数:31,代码来源:DbHelper.java
示例4: upDataBySynchronous
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的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);
}
});
}
开发者ID:lueans,项目名称:LueansRead,代码行数:12,代码来源:SoDao.java
示例5: onAdded
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
@Override
public void onAdded() {
ITransaction it = new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
// List all model tables here to delete.
Delete.tables(Note.class);
}
};
FlowManager.getDatabase(NoteDB.class).executeTransaction(it);
}
开发者ID:clrvynt,项目名称:android-offline,代码行数:12,代码来源:NoteServiceImpl.java
示例6: saveAllItems
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
protected static void saveAllItems(final List<Model> models) {
DatabaseDefinition databaseDefinition =
FlowManager.getDatabase(AppDatabase.class); // execute transaction
databaseDefinition.executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
for (Model model : models) {
model.insert();
}
}
});
}
开发者ID:EyeSeeTea,项目名称:malariapp,代码行数:13,代码来源:PopulateDB.java
示例7: saveBatch
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
public static void saveBatch(final List<Model> insertModels) {
//Save questions in batch
DatabaseDefinition databaseDefinition =
FlowManager.getDatabase(AppDatabase.class);
databaseDefinition.executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
for (Model model : insertModels) {
model.insert();
}
}
});
}
开发者ID:EyeSeeTea,项目名称:malariapp,代码行数:15,代码来源:SdkQueries.java
示例8: backupDB
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
/**
* Saves the database as a backup on the {@link DefaultTransactionQueue}.
* This will create a THIRD database to use as a backup to the backup in case somehow the overwrite fails.
*/
public void backupDB() {
if (!getDatabaseDefinition().backupEnabled() || !getDatabaseDefinition().areConsistencyChecksEnabled()) {
throw new IllegalStateException("Backups are not enabled for : " + getDatabaseDefinition().getDatabaseName() + ". Please consider adding " +
"both backupEnabled and consistency checks enabled to the Database annotation");
}
getDatabaseDefinition().beginTransactionAsync(new ITransaction() {
@SuppressWarnings("ResultOfMethodCallIgnored")
@Override
public void execute(DatabaseWrapper databaseWrapper) {
Context context = FlowManager.getContext();
File backup = context.getDatabasePath(getTempDbFileName());
File temp = context.getDatabasePath(TEMP_DB_NAME + "-2-" + getDatabaseDefinition().getDatabaseFileName());
// if exists we want to delete it before rename
if (temp.exists()) {
temp.delete();
}
backup.renameTo(temp);
if (backup.exists()) {
backup.delete();
}
File existing = context.getDatabasePath(getDatabaseDefinition().getDatabaseFileName());
try {
backup.getParentFile().mkdirs();
writeDB(backup, new FileInputStream(existing));
temp.delete();
} catch (Exception e) {
FlowLog.logError(e);
}
}
}).build().execute();
}
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:43,代码来源:DatabaseHelperDelegate.java
示例9: bulkInsert
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
@Override
public int bulkInsert(@NonNull final Uri uri, @NonNull final ContentValues[] values) {
final int[] count = {0};
getDatabase().executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
for (ContentValues contentValues : values) {
count[0] += bulkInsert(uri, contentValues);
}
}
});
//noinspection ConstantConditions
getContext().getContentResolver().notifyChange(uri, null);
return count[0];
}
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:16,代码来源:BaseContentProvider.java
示例10: executeTransaction
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
protected void executeTransaction(@NonNull ITransaction transaction) {
cancel();
currentTransaction = databaseDefinition
.beginTransactionAsync(transaction)
.error(error)
.success(success)
.build();
currentTransaction.execute();
}
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:10,代码来源:BaseAsyncObject.java
示例11: executeTransaction
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
public void executeTransaction(@NonNull ITransaction transaction) {
DatabaseWrapper database = getWritableDatabase();
try {
database.beginTransaction();
transaction.execute(database);
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
}
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:11,代码来源:DatabaseDefinition.java
示例12: writeWholeData
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
@Override
public long writeWholeData() throws SQLException
{
final List<User> users = new LinkedList<User>();
for(int i = 0; i < NUM_USER_INSERTS; i++)
{
User newUser = new User();
newUser.lastName = (getRandomString(10));
newUser.firstName = (getRandomString(10));
users.add(newUser);
}
final List<Message> messages = new LinkedList<Message>();
for (int i = 0; i < NUM_MESSAGE_INSERTS; i++) {
Message newMessage = new Message();
newMessage.commandId = i;
newMessage.sortedBy = System.nanoTime();
newMessage.content = Util.getRandomString(100);
newMessage.clientId = System.currentTimeMillis();
newMessage
.senderId = (Math.round(Math.random() * NUM_USER_INSERTS));
newMessage
.channelId = (Math.round(Math.random() * NUM_USER_INSERTS));
newMessage.createdAt = ((int) (System.currentTimeMillis() / 1000L));
messages.add(newMessage);
}
long start = System.nanoTime();
FlowManager.getDatabase(DatabaseModule.NAME).executeTransaction(new ITransaction() {
@Override
public void execute(DatabaseWrapper databaseWrapper) {
for (User user : users) {
user.save();
}
Log.d(TAG, "Done, wrote " + NUM_USER_INSERTS + " users");
for (Message message : messages) {
message.save();
}
Log.d(TAG, "Done, wrote " + NUM_MESSAGE_INSERTS + " messages");
}
});
return System.nanoTime() - start;
}
开发者ID:touchlab,项目名称:android-orm-benchmark-updated,代码行数:49,代码来源:DBFlowExecutor.java
示例13: insertTransaction
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
@NonNull
private <TModel extends Model> ITransaction insertTransaction(Collection entities, Class<TModel> clazz) {
ModelAdapter<? extends Model> modelAdapter = FlowManager.getModelAdapter(clazz);
return FastStoreModelTransaction.insertBuilder(modelAdapter).addAll(entities).build();
}
开发者ID:greenrobot,项目名称:android-database-performance,代码行数:6,代码来源:PerfTestDbFlow.java
示例14: updateTransaction
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
@NonNull
private <TModel extends Model> ITransaction updateTransaction(Collection entities, Class<TModel> clazz) {
ModelAdapter<? extends Model> modelAdapter = FlowManager.getModelAdapter(clazz);
return FastStoreModelTransaction.updateBuilder(modelAdapter).addAll(entities).build();
}
开发者ID:greenrobot,项目名称:android-database-performance,代码行数:6,代码来源:PerfTestDbFlow.java
示例15: beginTransactionAsync
import com.raizlabs.android.dbflow.structure.database.transaction.ITransaction; //导入依赖的package包/类
@NonNull
public Transaction.Builder beginTransactionAsync(@NonNull ITransaction transaction) {
return new Transaction.Builder(transaction, this);
}
开发者ID:Raizlabs,项目名称:DBFlow,代码行数:5,代码来源:DatabaseDefinition.java
注:本文中的com.raizlabs.android.dbflow.structure.database.transaction.ITransaction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论