mirror of
https://github.com/corda/corda.git
synced 2025-02-20 17:33:15 +00:00
Adding an option to override the default isolation level on per transaction basis (#1886)
This commit is contained in:
parent
2a68e23e69
commit
83b9080502
@ -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.
|
||||
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 {
|
||||
@ -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.")
|
||||
}
|
||||
|
||||
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
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user