Skip to content

Commit

Permalink
Optimize the logic related to table structure upgrade.(#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dora4 committed Nov 8, 2024
1 parent 700d886 commit 22453f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dcache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ afterEvaluate {
from(components["release"])
groupId = "com.github.dora4"
artifactId = "dcache-android"
version = "2.5.13"
version = "2.5.14"
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions dcache/src/main/java/dora/db/Transaction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object Transaction {
* [execute] function.
* 简体中文:[android.database.sqlite.SQLiteDatabase]对象,可以在[execute]函数中直接使用。
*/
val db: SQLiteDatabase
get() = Orm.getDB()
val db: SQLiteDatabase?
get() = if (Orm.isPrepared()) Orm.getDB() else null

/**
* Execute a general transaction block.
Expand Down Expand Up @@ -53,19 +53,19 @@ object Transaction {
try {
// Begin the transaction.
// 简体中文:开始事务
db.beginTransaction()
db?.beginTransaction()
// Execute the transaction operation.
// 简体中文:执行事务操作
block()
// Set the flag indicating that all operations were executed successfully.
// 简体中文:设置所有操作执行成功的标志位
db.setTransactionSuccessful()
db?.setTransactionSuccessful()
} catch (e: SQLiteException) {
e.printStackTrace()
} finally {
// End the transaction.
// 简体中文:结束事务
db.endTransaction()
db?.endTransaction()
}
}

Expand Down Expand Up @@ -105,19 +105,19 @@ object Transaction {
try {
// Begin the transaction.
// 简体中文:开始事务
db.beginTransaction()
db?.beginTransaction()
// Execute the transaction operation.
// 简体中文:执行事务操作
block(dao)
// Set the flag indicating that all operations were executed successfully.
// 简体中文:设置所有操作执行成功的标志位
db.setTransactionSuccessful()
db?.setTransactionSuccessful()
} catch (e: SQLiteException) {
e.printStackTrace()
} finally {
// End the transaction.
// 简体中文:结束事务
db.endTransaction()
db?.endTransaction()
}
}
}

0 comments on commit 22453f8

Please sign in to comment.