mirror of
https://github.com/corda/corda.git
synced 2024-12-28 00:38:55 +00:00
Fix compile errors.
This commit is contained in:
parent
bd342a690c
commit
6ddf684846
@ -2,7 +2,7 @@ package net.corda.flowhook
|
|||||||
|
|
||||||
import co.paralleluniverse.fibers.Fiber
|
import co.paralleluniverse.fibers.Fiber
|
||||||
import net.corda.node.services.statemachine.Event
|
import net.corda.node.services.statemachine.Event
|
||||||
import net.corda.nodeapi.internal.persistence.DatabaseTransactionManager
|
import net.corda.nodeapi.internal.persistence.contextTransactionOrNull
|
||||||
import java.sql.Connection
|
import java.sql.Connection
|
||||||
|
|
||||||
@Suppress("UNUSED")
|
@Suppress("UNUSED")
|
||||||
@ -156,7 +156,7 @@ object FlowHookContainer {
|
|||||||
|
|
||||||
private fun currentTransactionOrThread(): Any {
|
private fun currentTransactionOrThread(): Any {
|
||||||
return try {
|
return try {
|
||||||
DatabaseTransactionManager.currentOrNull()
|
contextTransactionOrNull
|
||||||
} catch (exception: IllegalStateException) {
|
} catch (exception: IllegalStateException) {
|
||||||
null
|
null
|
||||||
} ?: Thread.currentThread()
|
} ?: Thread.currentThread()
|
||||||
|
@ -44,7 +44,9 @@ enum class TransactionIsolationLevel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val _contextDatabase = ThreadLocal<CordaPersistence>()
|
private val _contextDatabase = ThreadLocal<CordaPersistence>()
|
||||||
val contextDatabase get() = _contextDatabase.get() ?: error("Was expecting to find CordaPersistence set on current thread: ${Strand.currentStrand()}")
|
var contextDatabase: CordaPersistence
|
||||||
|
get() = _contextDatabase.get() ?: error("Was expecting to find CordaPersistence set on current thread: ${Strand.currentStrand()}")
|
||||||
|
set(database) = _contextDatabase.set(database)
|
||||||
|
|
||||||
class CordaPersistence(
|
class CordaPersistence(
|
||||||
val dataSource: DataSource,
|
val dataSource: DataSource,
|
||||||
|
@ -15,7 +15,7 @@ val contextTransaction get() = contextTransactionOrNull ?: error("Was expecting
|
|||||||
|
|
||||||
class DatabaseTransaction(
|
class DatabaseTransaction(
|
||||||
isolation: Int,
|
isolation: Int,
|
||||||
private val outerTransaction: DatabaseTransaction?,
|
val outerTransaction: DatabaseTransaction?,
|
||||||
val database: CordaPersistence
|
val database: CordaPersistence
|
||||||
) {
|
) {
|
||||||
val id: UUID = UUID.randomUUID()
|
val id: UUID = UUID.randomUUID()
|
||||||
|
@ -5,7 +5,6 @@ import net.corda.core.serialization.SerializedBytes
|
|||||||
import net.corda.core.utilities.debug
|
import net.corda.core.utilities.debug
|
||||||
import net.corda.node.services.api.CheckpointStorage
|
import net.corda.node.services.api.CheckpointStorage
|
||||||
import net.corda.node.services.statemachine.Checkpoint
|
import net.corda.node.services.statemachine.Checkpoint
|
||||||
import net.corda.nodeapi.internal.persistence.DatabaseTransactionManager
|
|
||||||
import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX
|
import net.corda.nodeapi.internal.persistence.NODE_DATABASE_PREFIX
|
||||||
import net.corda.nodeapi.internal.persistence.currentDBSession
|
import net.corda.nodeapi.internal.persistence.currentDBSession
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@ -43,7 +42,7 @@ class DBCheckpointStorage : CheckpointStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun removeCheckpoint(id: StateMachineRunId): Boolean {
|
override fun removeCheckpoint(id: StateMachineRunId): Boolean {
|
||||||
val session = DatabaseTransactionManager.current().session
|
val session = currentDBSession()
|
||||||
val criteriaBuilder = session.criteriaBuilder
|
val criteriaBuilder = session.criteriaBuilder
|
||||||
val delete = criteriaBuilder.createCriteriaDelete(DBCheckpoint::class.java)
|
val delete = criteriaBuilder.createCriteriaDelete(DBCheckpoint::class.java)
|
||||||
val root = delete.from(DBCheckpoint::class.java)
|
val root = delete.from(DBCheckpoint::class.java)
|
||||||
|
@ -10,7 +10,9 @@ import net.corda.core.utilities.contextLogger
|
|||||||
import net.corda.core.utilities.trace
|
import net.corda.core.utilities.trace
|
||||||
import net.corda.node.services.api.CheckpointStorage
|
import net.corda.node.services.api.CheckpointStorage
|
||||||
import net.corda.node.services.api.ServiceHubInternal
|
import net.corda.node.services.api.ServiceHubInternal
|
||||||
import net.corda.nodeapi.internal.persistence.DatabaseTransactionManager
|
import net.corda.nodeapi.internal.persistence.contextDatabase
|
||||||
|
import net.corda.nodeapi.internal.persistence.contextTransaction
|
||||||
|
import net.corda.nodeapi.internal.persistence.contextTransactionOrNull
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
@ -163,24 +165,24 @@ class ActionExecutorImpl(
|
|||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
private fun executeCreateTransaction() {
|
private fun executeCreateTransaction() {
|
||||||
if (DatabaseTransactionManager.currentOrNull() != null) {
|
if (contextTransactionOrNull != null) {
|
||||||
throw IllegalStateException("Refusing to create a second transaction")
|
throw IllegalStateException("Refusing to create a second transaction")
|
||||||
}
|
}
|
||||||
DatabaseTransactionManager.newTransaction()
|
contextDatabase.newTransaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
private fun executeRollbackTransaction() {
|
private fun executeRollbackTransaction() {
|
||||||
DatabaseTransactionManager.currentOrNull()?.close()
|
contextTransactionOrNull?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suspendable
|
@Suspendable
|
||||||
private fun executeCommitTransaction() {
|
private fun executeCommitTransaction() {
|
||||||
try {
|
try {
|
||||||
DatabaseTransactionManager.current().commit()
|
contextTransaction.commit()
|
||||||
} finally {
|
} finally {
|
||||||
DatabaseTransactionManager.current().close()
|
contextTransaction.close()
|
||||||
DatabaseTransactionManager.setThreadLocalTx(null)
|
contextTransactionOrNull = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@ import net.corda.core.utilities.contextLogger
|
|||||||
import net.corda.node.services.statemachine.transitions.FlowContinuation
|
import net.corda.node.services.statemachine.transitions.FlowContinuation
|
||||||
import net.corda.node.services.statemachine.transitions.TransitionResult
|
import net.corda.node.services.statemachine.transitions.TransitionResult
|
||||||
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
||||||
import net.corda.nodeapi.internal.persistence.DatabaseTransactionManager
|
import net.corda.nodeapi.internal.persistence.contextDatabase
|
||||||
|
import net.corda.nodeapi.internal.persistence.contextTransactionOrNull
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,12 +32,12 @@ class TransitionExecutorImpl(
|
|||||||
transition: TransitionResult,
|
transition: TransitionResult,
|
||||||
actionExecutor: ActionExecutor
|
actionExecutor: ActionExecutor
|
||||||
): Pair<FlowContinuation, StateMachineState> {
|
): Pair<FlowContinuation, StateMachineState> {
|
||||||
DatabaseTransactionManager.dataSource = database
|
contextDatabase = database
|
||||||
for (action in transition.actions) {
|
for (action in transition.actions) {
|
||||||
try {
|
try {
|
||||||
actionExecutor.executeAction(fiber, action)
|
actionExecutor.executeAction(fiber, action)
|
||||||
} catch (exception: Throwable) {
|
} catch (exception: Throwable) {
|
||||||
DatabaseTransactionManager.currentOrNull()?.close()
|
contextTransactionOrNull?.close()
|
||||||
if (transition.newState.checkpoint.errorState is ErrorState.Errored) {
|
if (transition.newState.checkpoint.errorState is ErrorState.Errored) {
|
||||||
// If we errored while transitioning to an error state then we cannot record the additional
|
// If we errored while transitioning to an error state then we cannot record the additional
|
||||||
// error as that may result in an infinite loop, e.g. error propagation fails -> record error -> propagate fails again.
|
// error as that may result in an infinite loop, e.g. error propagation fails -> record error -> propagate fails again.
|
||||||
|
@ -10,7 +10,7 @@ import net.corda.core.utilities.toNonEmptySet
|
|||||||
import net.corda.core.utilities.trace
|
import net.corda.core.utilities.trace
|
||||||
import net.corda.node.services.statemachine.FlowStateMachineImpl
|
import net.corda.node.services.statemachine.FlowStateMachineImpl
|
||||||
import net.corda.node.services.statemachine.StateMachineManager
|
import net.corda.node.services.statemachine.StateMachineManager
|
||||||
import net.corda.nodeapi.internal.persistence.DatabaseTransactionManager
|
import net.corda.nodeapi.internal.persistence.contextDatabase
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class VaultSoftLockManager private constructor(private val vault: VaultService) {
|
class VaultSoftLockManager private constructor(private val vault: VaultService) {
|
||||||
@ -52,14 +52,14 @@ class VaultSoftLockManager private constructor(private val vault: VaultService)
|
|||||||
|
|
||||||
private fun registerSoftLocks(flowId: UUID, stateRefs: NonEmptySet<StateRef>) {
|
private fun registerSoftLocks(flowId: UUID, stateRefs: NonEmptySet<StateRef>) {
|
||||||
log.trace { "Reserving soft locks for flow id $flowId and states $stateRefs" }
|
log.trace { "Reserving soft locks for flow id $flowId and states $stateRefs" }
|
||||||
DatabaseTransactionManager.dataSource.transaction {
|
contextDatabase.transaction {
|
||||||
vault.softLockReserve(flowId, stateRefs)
|
vault.softLockReserve(flowId, stateRefs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unregisterSoftLocks(flowId: UUID, logic: FlowLogic<*>) {
|
private fun unregisterSoftLocks(flowId: UUID, logic: FlowLogic<*>) {
|
||||||
log.trace { "Releasing soft locks for flow ${logic.javaClass.simpleName} with flow id $flowId" }
|
log.trace { "Releasing soft locks for flow ${logic.javaClass.simpleName} with flow id $flowId" }
|
||||||
DatabaseTransactionManager.dataSource.transaction {
|
contextDatabase.transaction {
|
||||||
vault.softLockRelease(flowId)
|
vault.softLockRelease(flowId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user