mirror of
https://github.com/corda/corda.git
synced 2025-06-17 06:38:21 +00:00
Adding an option to override the default isolation level on per transaction basis (#1886)
This commit is contained in:
@ -40,10 +40,21 @@ class CordaPersistence(var dataSource: HikariDataSource, private val schemaServi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createTransaction(): DatabaseTransaction {
|
/**
|
||||||
|
* Creates an instance of [DatabaseTransaction], with the given isolation level.
|
||||||
|
* @param isolationLevel isolation level for the transaction. If not specified the default (i.e. provided at the creation time) is used.
|
||||||
|
*/
|
||||||
|
fun createTransaction(isolationLevel: Int): DatabaseTransaction {
|
||||||
// We need to set the database for the current [Thread] or [Fiber] here as some tests share threads across databases.
|
// We need to set the database for the current [Thread] or [Fiber] here as some tests share threads across databases.
|
||||||
DatabaseTransactionManager.dataSource = this
|
DatabaseTransactionManager.dataSource = this
|
||||||
return DatabaseTransactionManager.currentOrNew(transactionIsolationLevel)
|
return DatabaseTransactionManager.currentOrNew(isolationLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of [DatabaseTransaction], with the transaction isolation level specified at the creation time.
|
||||||
|
*/
|
||||||
|
fun createTransaction(): DatabaseTransaction {
|
||||||
|
return createTransaction(transactionIsolationLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSession(): Connection {
|
fun createSession(): Connection {
|
||||||
@ -53,9 +64,22 @@ class CordaPersistence(var dataSource: HikariDataSource, private val schemaServi
|
|||||||
return ctx?.connection ?: throw IllegalStateException("Was expecting to find database transaction: must wrap calling code within a transaction.")
|
return ctx?.connection ?: throw IllegalStateException("Was expecting to find database transaction: must wrap calling code within a transaction.")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> transaction(statement: DatabaseTransaction.() -> T): T {
|
/**
|
||||||
|
* Executes given statement in the scope of transaction, with the given isolation level.
|
||||||
|
* @param isolationLevel isolation level for the transaction.
|
||||||
|
* @param statement to be executed in the scope of this transaction.
|
||||||
|
*/
|
||||||
|
fun <T> transaction(isolationLevel: Int, statement: DatabaseTransaction.() -> T): T {
|
||||||
DatabaseTransactionManager.dataSource = this
|
DatabaseTransactionManager.dataSource = this
|
||||||
return transaction(transactionIsolationLevel, 3, statement)
|
return transaction(isolationLevel, 3, statement)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes given statement in the scope of transaction with the transaction level specified at the creation time.
|
||||||
|
* @param statement to be executed in the scope of this transaction.
|
||||||
|
*/
|
||||||
|
fun <T> transaction(statement: DatabaseTransaction.() -> T): T {
|
||||||
|
return transaction(transactionIsolationLevel, statement)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> transaction(transactionIsolation: Int, repetitionAttempts: Int, statement: DatabaseTransaction.() -> T): T {
|
private fun <T> transaction(transactionIsolation: Int, repetitionAttempts: Int, statement: DatabaseTransaction.() -> T): T {
|
||||||
|
Reference in New Issue
Block a user