本文整理了Java中org.greenrobot.greendao.database.Database.isDbLockedByCurrentThread()
方法的一些代码示例,展示了Database.isDbLockedByCurrentThread()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Database.isDbLockedByCurrentThread()
方法的具体详情如下:
包路径:org.greenrobot.greendao.database.Database
类名称:Database
方法名:isDbLockedByCurrentThread
暂无
代码示例来源: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
/** 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
/**
* 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
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: org.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: org.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: org.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: org.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();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!