本文整理了Java中org.greenrobot.greendao.database.Database.beginTransaction()
方法的一些代码示例,展示了Database.beginTransaction()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Database.beginTransaction()
方法的具体详情如下:
包路径:org.greenrobot.greendao.database.Database
类名称:Database
方法名:beginTransaction
暂无
代码示例来源:origin: greenrobot/greenDAO
/**
* Run the given Runnable inside a database transaction. If you except a result, consider callInTx.
*/
public void runInTx(Runnable runnable) {
db.beginTransaction();
try {
runnable.run();
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
代码示例来源:origin: greenrobot/greenDAO
/**
* Calls the given Callable inside a database transaction and returns the result of the Callable. If you don't
* except a result, consider runInTx.
*/
public <V> V callInTx(Callable<V> callable) throws Exception {
db.beginTransaction();
try {
V result = callable.call();
db.setTransactionSuccessful();
return result;
} finally {
db.endTransaction();
}
}
代码示例来源:origin: greenrobot/greenDAO
@SuppressWarnings("unchecked")
private void executeTransactionCallable(AsyncOperation operation) throws Exception {
Database db = operation.getDatabase();
db.beginTransaction();
try {
operation.result = ((Callable<Object>) operation.parameter).call();
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
代码示例来源:origin: greenrobot/greenDAO
private void executeTransactionRunnable(AsyncOperation operation) {
Database db = operation.getDatabase();
db.beginTransaction();
try {
((Runnable) operation.parameter).run();
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
代码示例来源:origin: greenrobot/greenDAO
/**
* Like {@link #callInTx(Callable)} but does not require Exception handling (rethrows an Exception as a runtime
* DaoException).
*/
public <V> V callInTxNoException(Callable<V> callable) {
db.beginTransaction();
try {
V result;
try {
result = callable.call();
} catch (Exception e) {
throw new DaoException("Callable failed", e);
}
db.setTransactionSuccessful();
return result;
} finally {
db.endTransaction();
}
}
代码示例来源:origin: greenrobot/greenDAO
public static int executeSqlStatementsInTx(Database db, String[] statements) {
db.beginTransaction();
try {
int count = executeSqlStatements(db, statements);
db.setTransactionSuccessful();
return count;
} finally {
db.endTransaction();
}
}
代码示例来源:origin: greenrobot/greenDAO
db.beginTransaction();
boolean success = false;
try {
代码示例来源:origin: greenrobot/greenDAO
db.beginTransaction();
try {
updateInTx(toUpdate);
代码示例来源:origin: greenrobot/greenDAO
private long executeInsert(T entity, DatabaseStatement stmt, boolean setKeyAndAttach) {
long rowId;
if (db.isDbLockedByCurrentThread()) {
rowId = insertInsideTx(entity, stmt);
} else {
// Do TX to acquire a connection before locking the stmt to avoid deadlocks
db.beginTransaction();
try {
rowId = insertInsideTx(entity, stmt);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (setKeyAndAttach) {
updateKeyAfterInsertAndAttach(entity, rowId, true);
}
return rowId;
}
代码示例来源:origin: greenrobot/greenDAO
DatabaseStatement stmt = statements.getDeleteStatement();
List<K> keysToRemoveFromIdentityScope = null;
db.beginTransaction();
try {
synchronized (stmt) {
代码示例来源:origin: greenrobot/greenDAO
/** Deletes an entity with the given PK from the database. Currently, only single value PK entities are supported. */
public void deleteByKey(K key) {
assertSinglePk();
DatabaseStatement stmt = statements.getDeleteStatement();
if (db.isDbLockedByCurrentThread()) {
synchronized (stmt) {
deleteByKeyInsideSynchronized(key, stmt);
}
} else {
// Do TX to acquire a connection before locking the stmt to avoid deadlocks
db.beginTransaction();
try {
synchronized (stmt) {
deleteByKeyInsideSynchronized(key, stmt);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (identityScope != null) {
identityScope.remove(key);
}
}
代码示例来源:origin: greenrobot/greenDAO
public void update(T entity) {
assertSinglePk();
DatabaseStatement stmt = statements.getUpdateStatement();
if (db.isDbLockedByCurrentThread()) {
synchronized (stmt) {
if (isStandardSQLite) {
updateInsideSynchronized(entity, (SQLiteStatement) stmt.getRawStatement(), true);
} else {
updateInsideSynchronized(entity, stmt, true);
}
}
} else {
// Do TX to acquire a connection before locking the stmt to avoid deadlocks
db.beginTransaction();
try {
synchronized (stmt) {
updateInsideSynchronized(entity, stmt, true);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
}
代码示例来源:origin: greenrobot/greenDAO
/**
* Deletes all matching entities without detaching them from the identity scope (aka session/cache). Note that this
* method may lead to stale entity objects in the session cache. Stale entities may be returned when loaded by
* their
* primary key, but not using queries.
*/
public void executeDeleteWithoutDetachingEntities() {
checkThread();
Database db = dao.getDatabase();
if (db.isDbLockedByCurrentThread()) {
dao.getDatabase().execSQL(sql, parameters);
} else {
// Do TX to acquire a connection before locking this to avoid deadlocks
// Locking order as described in AbstractDao
db.beginTransaction();
try {
dao.getDatabase().execSQL(sql, parameters);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
}
代码示例来源:origin: greenrobot/greenDAO
db.beginTransaction();
代码示例来源:origin: greenrobot/greenDAO
private void executeInsertInTx(DatabaseStatement stmt, Iterable<T> entities, boolean setPrimaryKey) {
db.beginTransaction();
try {
synchronized (stmt) {
代码示例来源:origin: org.greenrobot/greendao
/**
* Run the given Runnable inside a database transaction. If you except a result, consider callInTx.
*/
public void runInTx(Runnable runnable) {
db.beginTransaction();
try {
runnable.run();
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
代码示例来源:origin: org.greenrobot/greendao
/**
* Calls the given Callable inside a database transaction and returns the result of the Callable. If you don't
* except a result, consider runInTx.
*/
public <V> V callInTx(Callable<V> callable) throws Exception {
db.beginTransaction();
try {
V result = callable.call();
db.setTransactionSuccessful();
return result;
} finally {
db.endTransaction();
}
}
代码示例来源:origin: org.greenrobot/greendao
private void executeTransactionRunnable(AsyncOperation operation) {
Database db = operation.getDatabase();
db.beginTransaction();
try {
((Runnable) operation.parameter).run();
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
代码示例来源:origin: org.greenrobot/greendao
@SuppressWarnings("unchecked")
private void executeTransactionCallable(AsyncOperation operation) throws Exception {
Database db = operation.getDatabase();
db.beginTransaction();
try {
operation.result = ((Callable<Object>) operation.parameter).call();
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
代码示例来源:origin: org.greenrobot/greendao
public static int executeSqlStatementsInTx(Database db, String[] statements) {
db.beginTransaction();
try {
int count = executeSqlStatements(db, statements);
db.setTransactionSuccessful();
return count;
} finally {
db.endTransaction();
}
}
内容来源于网络,如有侵权,请联系作者删除!