mirror of
https://github.com/corda/corda.git
synced 2024-12-18 20:47:57 +00:00
Ensure that ServiceHub.WithEntityManager has a database transaction available (#5413)
* tidy up withEntityManager * address rick review comment * api break
This commit is contained in:
parent
136600c91a
commit
cd0d5c7724
@ -3520,7 +3520,6 @@ public interface net.corda.core.node.ServiceHub extends net.corda.core.node.Serv
|
||||
@NotNull
|
||||
public abstract net.corda.core.contracts.StateAndRef<T> toStateAndRef(net.corda.core.contracts.StateRef)
|
||||
public abstract void withEntityManager(java.util.function.Consumer<javax.persistence.EntityManager>)
|
||||
@NotNull
|
||||
public abstract T withEntityManager(kotlin.jvm.functions.Function1<? super javax.persistence.EntityManager, ? extends T>)
|
||||
##
|
||||
@DoNotImplement
|
||||
@ -7816,7 +7815,6 @@ public class net.corda.testing.node.MockServices extends java.lang.Object implem
|
||||
@NotNull
|
||||
public net.corda.core.contracts.StateAndRef<T> toStateAndRef(net.corda.core.contracts.StateRef)
|
||||
public void withEntityManager(java.util.function.Consumer<javax.persistence.EntityManager>)
|
||||
@NotNull
|
||||
public T withEntityManager(kotlin.jvm.functions.Function1<? super javax.persistence.EntityManager, ? extends T>)
|
||||
public static final net.corda.testing.node.MockServices$Companion Companion
|
||||
##
|
||||
|
@ -376,7 +376,7 @@ interface ServiceHub : ServicesForResolution {
|
||||
*
|
||||
* @param block a lambda function with access to an [EntityManager].
|
||||
*/
|
||||
fun <T : Any> withEntityManager(block: EntityManager.() -> T): T
|
||||
fun <T : Any?> withEntityManager(block: EntityManager.() -> T): T
|
||||
|
||||
/**
|
||||
* Exposes the Java Persistence API (JPA) to flows via a restricted [EntityManager]. This method can be used to
|
||||
|
@ -409,7 +409,9 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
||||
// Shut down the SMM so no Fibers are scheduled.
|
||||
runOnStop += { smm.stop(acceptableLiveFiberCountOnStop()) }
|
||||
(smm as? StateMachineManagerInternal)?.let {
|
||||
val flowMonitor = FlowMonitor({ smm.snapshot().filter { flow -> flow !in smm.flowHospital }.toSet() }, configuration.flowMonitorPeriodMillis, configuration.flowMonitorSuspensionLoggingThresholdMillis)
|
||||
val flowMonitor = FlowMonitor({
|
||||
smm.snapshot().filter { flow -> flow !in smm.flowHospital }.toSet()
|
||||
}, configuration.flowMonitorPeriodMillis, configuration.flowMonitorSuspensionLoggingThresholdMillis)
|
||||
runOnStop += flowMonitor::stop
|
||||
flowMonitor.start()
|
||||
}
|
||||
@ -1032,12 +1034,16 @@ abstract class AbstractNode<S>(val configuration: NodeConfiguration,
|
||||
|
||||
override fun jdbcSession(): Connection = database.createSession()
|
||||
|
||||
override fun <T : Any> withEntityManager(block: EntityManager.() -> T): T {
|
||||
return block(contextTransaction.restrictedEntityManager)
|
||||
override fun <T : Any?> withEntityManager(block: EntityManager.() -> T): T {
|
||||
return database.transaction {
|
||||
block(restrictedEntityManager)
|
||||
}
|
||||
}
|
||||
|
||||
override fun withEntityManager(block: Consumer<EntityManager>) {
|
||||
block.accept(contextTransaction.restrictedEntityManager)
|
||||
withEntityManager {
|
||||
block.accept(this)
|
||||
}
|
||||
}
|
||||
|
||||
// allows services to register handlers to be informed when the node stop method is called
|
||||
|
@ -224,7 +224,7 @@ open class MockServices private constructor(
|
||||
|
||||
override fun jdbcSession(): Connection = persistence.createSession()
|
||||
|
||||
override fun <T : Any> withEntityManager(block: EntityManager.() -> T): T {
|
||||
override fun <T : Any?> withEntityManager(block: EntityManager.() -> T): T {
|
||||
return block(contextTransaction.restrictedEntityManager)
|
||||
}
|
||||
|
||||
@ -440,7 +440,7 @@ open class MockServices private constructor(
|
||||
|
||||
override fun jdbcSession(): Connection = throw UnsupportedOperationException()
|
||||
|
||||
override fun <T : Any> withEntityManager(block: EntityManager.() -> T): T {
|
||||
override fun <T : Any?> withEntityManager(block: EntityManager.() -> T): T {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user