org.greenrobot.greendao.database.Database.beginTransaction()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.greenrobot.greendao.database.Database.beginTransaction()方法的一些代码示例,展示了Database.beginTransaction()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Database.beginTransaction()方法的具体详情如下:
包路径:org.greenrobot.greendao.database.Database
类名称:Database
方法名:beginTransaction

Database.beginTransaction介绍

暂无

代码示例

代码示例来源:origin: greenrobot/greenDAO

  1. /**
  2. * Run the given Runnable inside a database transaction. If you except a result, consider callInTx.
  3. */
  4. public void runInTx(Runnable runnable) {
  5. db.beginTransaction();
  6. try {
  7. runnable.run();
  8. db.setTransactionSuccessful();
  9. } finally {
  10. db.endTransaction();
  11. }
  12. }

代码示例来源:origin: greenrobot/greenDAO

  1. /**
  2. * Calls the given Callable inside a database transaction and returns the result of the Callable. If you don't
  3. * except a result, consider runInTx.
  4. */
  5. public <V> V callInTx(Callable<V> callable) throws Exception {
  6. db.beginTransaction();
  7. try {
  8. V result = callable.call();
  9. db.setTransactionSuccessful();
  10. return result;
  11. } finally {
  12. db.endTransaction();
  13. }
  14. }

代码示例来源:origin: greenrobot/greenDAO

  1. @SuppressWarnings("unchecked")
  2. private void executeTransactionCallable(AsyncOperation operation) throws Exception {
  3. Database db = operation.getDatabase();
  4. db.beginTransaction();
  5. try {
  6. operation.result = ((Callable<Object>) operation.parameter).call();
  7. db.setTransactionSuccessful();
  8. } finally {
  9. db.endTransaction();
  10. }
  11. }

代码示例来源:origin: greenrobot/greenDAO

  1. private void executeTransactionRunnable(AsyncOperation operation) {
  2. Database db = operation.getDatabase();
  3. db.beginTransaction();
  4. try {
  5. ((Runnable) operation.parameter).run();
  6. db.setTransactionSuccessful();
  7. } finally {
  8. db.endTransaction();
  9. }
  10. }

代码示例来源:origin: greenrobot/greenDAO

  1. /**
  2. * Like {@link #callInTx(Callable)} but does not require Exception handling (rethrows an Exception as a runtime
  3. * DaoException).
  4. */
  5. public <V> V callInTxNoException(Callable<V> callable) {
  6. db.beginTransaction();
  7. try {
  8. V result;
  9. try {
  10. result = callable.call();
  11. } catch (Exception e) {
  12. throw new DaoException("Callable failed", e);
  13. }
  14. db.setTransactionSuccessful();
  15. return result;
  16. } finally {
  17. db.endTransaction();
  18. }
  19. }

代码示例来源:origin: greenrobot/greenDAO

  1. public static int executeSqlStatementsInTx(Database db, String[] statements) {
  2. db.beginTransaction();
  3. try {
  4. int count = executeSqlStatements(db, statements);
  5. db.setTransactionSuccessful();
  6. return count;
  7. } finally {
  8. db.endTransaction();
  9. }
  10. }

代码示例来源:origin: greenrobot/greenDAO

  1. db.beginTransaction();
  2. boolean success = false;
  3. try {

代码示例来源:origin: greenrobot/greenDAO

  1. db.beginTransaction();
  2. try {
  3. updateInTx(toUpdate);

代码示例来源:origin: greenrobot/greenDAO

  1. private long executeInsert(T entity, DatabaseStatement stmt, boolean setKeyAndAttach) {
  2. long rowId;
  3. if (db.isDbLockedByCurrentThread()) {
  4. rowId = insertInsideTx(entity, stmt);
  5. } else {
  6. // Do TX to acquire a connection before locking the stmt to avoid deadlocks
  7. db.beginTransaction();
  8. try {
  9. rowId = insertInsideTx(entity, stmt);
  10. db.setTransactionSuccessful();
  11. } finally {
  12. db.endTransaction();
  13. }
  14. }
  15. if (setKeyAndAttach) {
  16. updateKeyAfterInsertAndAttach(entity, rowId, true);
  17. }
  18. return rowId;
  19. }

代码示例来源:origin: greenrobot/greenDAO

  1. DatabaseStatement stmt = statements.getDeleteStatement();
  2. List<K> keysToRemoveFromIdentityScope = null;
  3. db.beginTransaction();
  4. try {
  5. synchronized (stmt) {

代码示例来源:origin: greenrobot/greenDAO

  1. /** Deletes an entity with the given PK from the database. Currently, only single value PK entities are supported. */
  2. public void deleteByKey(K key) {
  3. assertSinglePk();
  4. DatabaseStatement stmt = statements.getDeleteStatement();
  5. if (db.isDbLockedByCurrentThread()) {
  6. synchronized (stmt) {
  7. deleteByKeyInsideSynchronized(key, stmt);
  8. }
  9. } else {
  10. // Do TX to acquire a connection before locking the stmt to avoid deadlocks
  11. db.beginTransaction();
  12. try {
  13. synchronized (stmt) {
  14. deleteByKeyInsideSynchronized(key, stmt);
  15. }
  16. db.setTransactionSuccessful();
  17. } finally {
  18. db.endTransaction();
  19. }
  20. }
  21. if (identityScope != null) {
  22. identityScope.remove(key);
  23. }
  24. }

代码示例来源:origin: greenrobot/greenDAO

  1. public void update(T entity) {
  2. assertSinglePk();
  3. DatabaseStatement stmt = statements.getUpdateStatement();
  4. if (db.isDbLockedByCurrentThread()) {
  5. synchronized (stmt) {
  6. if (isStandardSQLite) {
  7. updateInsideSynchronized(entity, (SQLiteStatement) stmt.getRawStatement(), true);
  8. } else {
  9. updateInsideSynchronized(entity, stmt, true);
  10. }
  11. }
  12. } else {
  13. // Do TX to acquire a connection before locking the stmt to avoid deadlocks
  14. db.beginTransaction();
  15. try {
  16. synchronized (stmt) {
  17. updateInsideSynchronized(entity, stmt, true);
  18. }
  19. db.setTransactionSuccessful();
  20. } finally {
  21. db.endTransaction();
  22. }
  23. }
  24. }

代码示例来源:origin: greenrobot/greenDAO

  1. /**
  2. * Deletes all matching entities without detaching them from the identity scope (aka session/cache). Note that this
  3. * method may lead to stale entity objects in the session cache. Stale entities may be returned when loaded by
  4. * their
  5. * primary key, but not using queries.
  6. */
  7. public void executeDeleteWithoutDetachingEntities() {
  8. checkThread();
  9. Database db = dao.getDatabase();
  10. if (db.isDbLockedByCurrentThread()) {
  11. dao.getDatabase().execSQL(sql, parameters);
  12. } else {
  13. // Do TX to acquire a connection before locking this to avoid deadlocks
  14. // Locking order as described in AbstractDao
  15. db.beginTransaction();
  16. try {
  17. dao.getDatabase().execSQL(sql, parameters);
  18. db.setTransactionSuccessful();
  19. } finally {
  20. db.endTransaction();
  21. }
  22. }
  23. }

代码示例来源:origin: greenrobot/greenDAO

  1. db.beginTransaction();

代码示例来源:origin: greenrobot/greenDAO

  1. private void executeInsertInTx(DatabaseStatement stmt, Iterable<T> entities, boolean setPrimaryKey) {
  2. db.beginTransaction();
  3. try {
  4. synchronized (stmt) {

代码示例来源:origin: org.greenrobot/greendao

  1. /**
  2. * Run the given Runnable inside a database transaction. If you except a result, consider callInTx.
  3. */
  4. public void runInTx(Runnable runnable) {
  5. db.beginTransaction();
  6. try {
  7. runnable.run();
  8. db.setTransactionSuccessful();
  9. } finally {
  10. db.endTransaction();
  11. }
  12. }

代码示例来源:origin: org.greenrobot/greendao

  1. /**
  2. * Calls the given Callable inside a database transaction and returns the result of the Callable. If you don't
  3. * except a result, consider runInTx.
  4. */
  5. public <V> V callInTx(Callable<V> callable) throws Exception {
  6. db.beginTransaction();
  7. try {
  8. V result = callable.call();
  9. db.setTransactionSuccessful();
  10. return result;
  11. } finally {
  12. db.endTransaction();
  13. }
  14. }

代码示例来源:origin: org.greenrobot/greendao

  1. private void executeTransactionRunnable(AsyncOperation operation) {
  2. Database db = operation.getDatabase();
  3. db.beginTransaction();
  4. try {
  5. ((Runnable) operation.parameter).run();
  6. db.setTransactionSuccessful();
  7. } finally {
  8. db.endTransaction();
  9. }
  10. }

代码示例来源:origin: org.greenrobot/greendao

  1. @SuppressWarnings("unchecked")
  2. private void executeTransactionCallable(AsyncOperation operation) throws Exception {
  3. Database db = operation.getDatabase();
  4. db.beginTransaction();
  5. try {
  6. operation.result = ((Callable<Object>) operation.parameter).call();
  7. db.setTransactionSuccessful();
  8. } finally {
  9. db.endTransaction();
  10. }
  11. }

代码示例来源:origin: org.greenrobot/greendao

  1. public static int executeSqlStatementsInTx(Database db, String[] statements) {
  2. db.beginTransaction();
  3. try {
  4. int count = executeSqlStatements(db, statements);
  5. db.setTransactionSuccessful();
  6. return count;
  7. } finally {
  8. db.endTransaction();
  9. }
  10. }

相关文章