diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/CordaPersistence.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/CordaPersistence.kt index c8cc4cfc35..5289bdf302 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/CordaPersistence.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/CordaPersistence.kt @@ -35,7 +35,8 @@ enum class TransactionIsolationLevel { /** * The JDBC constant value of the same name but prefixed with TRANSACTION_ defined in [java.sql.Connection]. */ - val jdbcValue: Int = java.sql.Connection::class.java.getField("TRANSACTION_$name").get(null) as Int + val jdbcString = "TRANSACTION_$name" + val jdbcValue: Int = java.sql.Connection::class.java.getField(jdbcString).get(null) as Int } class CordaPersistence( diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/DatabaseTransaction.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/DatabaseTransaction.kt index 626a5433b4..4bb1bbd42e 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/DatabaseTransaction.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/persistence/DatabaseTransaction.kt @@ -20,8 +20,10 @@ class DatabaseTransaction( cordaPersistence.dataSource.connection .apply { _connectionCreated = true - autoCommit = false - transactionIsolation = isolation + // only set the transaction isolation level if it's actually changed - setting isn't free. + if (transactionIsolation != isolation) { + transactionIsolation = isolation + } } } diff --git a/node/src/main/kotlin/net/corda/node/services/config/NodeConfiguration.kt b/node/src/main/kotlin/net/corda/node/services/config/NodeConfiguration.kt index d843193f5c..9e7017eb0a 100644 --- a/node/src/main/kotlin/net/corda/node/services/config/NodeConfiguration.kt +++ b/node/src/main/kotlin/net/corda/node/services/config/NodeConfiguration.kt @@ -135,6 +135,13 @@ data class NodeConfigurationImpl( require(security == null || rpcUsers.isEmpty()) { "Cannot specify both 'rpcUsers' and 'security' in configuration" } + + // ensure our datasource configuration is sane + require(dataSourceProperties.get("autoCommit") != true) { "Datbase auto commit cannot be enabled, Corda requires transactional behaviour" } + dataSourceProperties.set("autoCommit", false) + if (dataSourceProperties.get("transactionIsolation") == null) { + dataSourceProperties["transactionIsolation"] = database.transactionIsolationLevel.jdbcString + } } }