本文整理匯總了Java中io.realm.Realm.cancelTransaction方法的典型用法代碼示例。如果您正苦於以下問題:Java Realm.cancelTransaction方法的具體用法?Java Realm.cancelTransaction怎麽用?Java Realm.cancelTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.realm.Realm
的用法示例。
在下文中一共展示了Realm.cancelTransaction方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insert
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public boolean insert(TodoList todoList) {
Realm realm = Realm.getInstance(configuration);
final TodoListDAO dao = RealmConverter.convert(todoList);
realm.beginTransaction();
try {
realm.copyToRealm(dao);
realm.commitTransaction();
} catch (Throwable throwable) {
realm.cancelTransaction();
realm.close();
return false;
}
realm.close();
return true;
}
示例2: insert
import io.realm.Realm; //導入方法依賴的package包/類
@Override
public boolean insert(Note note) {
Realm realm = Realm.getInstance(configuration);
final NoteDAO dao = RealmConverter.convert(note);
realm.beginTransaction();
try {
realm.copyToRealm(dao);
realm.commitTransaction();
} catch (Throwable throwable) {
realm.cancelTransaction();
realm.close();
return false;
}
realm.close();
return true;
}
示例3: executeTransaction
import io.realm.Realm; //導入方法依賴的package包/類
public static <T> T executeTransaction(@NonNull Realm realm,
@NonNull RealmTransactionWithReturn<T> transaction) {
T retValue;
realm.beginTransaction();
try {
retValue = transaction.execute(realm);
realm.commitTransaction();
} catch (Throwable e) {
if (realm.isInTransaction()) {
realm.cancelTransaction();
} else {
Log.w(TAG, "Could not cancel transaction, not currently in a transaction.");
}
throw e;
}
return retValue;
}