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

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

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

Database.isDbLockedByCurrentThread介绍

暂无

代码示例

代码示例来源: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. /** 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. /**
  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. 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: org.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: org.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: org.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: org.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. }

相关文章