mirror of
https://github.com/corda/corda.git
synced 2025-05-29 05:34:22 +00:00
[CORDA-2296] Improve initialization of criteriaBuilder in NodeVaultService. (#4374)
This commit is contained in:
parent
f78c464d86
commit
af1202ba79
@ -72,7 +72,7 @@ class NodeVaultService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val mutex = ThreadBox(InnerState())
|
private val mutex = ThreadBox(InnerState())
|
||||||
private lateinit var criteriaBuilder: CriteriaBuilder
|
private val criteriaBuilder: CriteriaBuilder by lazy { database.hibernateConfig.sessionFactoryForRegisteredSchemas.criteriaBuilder }
|
||||||
private val persistentStateService = PersistentStateService(schemaService)
|
private val persistentStateService = PersistentStateService(schemaService)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,7 +82,6 @@ class NodeVaultService(
|
|||||||
private val contractStateTypeMappings = mutableMapOf<String, MutableSet<String>>()
|
private val contractStateTypeMappings = mutableMapOf<String, MutableSet<String>>()
|
||||||
|
|
||||||
override fun start() {
|
override fun start() {
|
||||||
criteriaBuilder = database.hibernateConfig.sessionFactoryForRegisteredSchemas.criteriaBuilder
|
|
||||||
bootstrapContractStateTypes()
|
bootstrapContractStateTypes()
|
||||||
rawUpdates.subscribe { update ->
|
rawUpdates.subscribe { update ->
|
||||||
update.produced.forEach {
|
update.produced.forEach {
|
||||||
|
@ -5,9 +5,12 @@ import net.corda.core.flows.FlowLogic
|
|||||||
import net.corda.core.flows.StartableByService
|
import net.corda.core.flows.StartableByService
|
||||||
import net.corda.core.context.InvocationContext
|
import net.corda.core.context.InvocationContext
|
||||||
import net.corda.core.context.InvocationOrigin
|
import net.corda.core.context.InvocationOrigin
|
||||||
|
import net.corda.core.contracts.ContractState
|
||||||
import net.corda.core.node.AppServiceHub
|
import net.corda.core.node.AppServiceHub
|
||||||
import net.corda.core.node.ServiceHub
|
import net.corda.core.node.ServiceHub
|
||||||
import net.corda.core.node.services.CordaService
|
import net.corda.core.node.services.CordaService
|
||||||
|
import net.corda.core.node.services.Vault
|
||||||
|
import net.corda.core.node.services.vault.QueryCriteria
|
||||||
import net.corda.core.serialization.SingletonSerializeAsToken
|
import net.corda.core.serialization.SingletonSerializeAsToken
|
||||||
import net.corda.core.utilities.OpaqueBytes
|
import net.corda.core.utilities.OpaqueBytes
|
||||||
import net.corda.core.utilities.ProgressTracker
|
import net.corda.core.utilities.ProgressTracker
|
||||||
@ -59,7 +62,6 @@ class TestCordaService(val appServiceHub: AppServiceHub): SingletonSerializeAsTo
|
|||||||
assertTrue(count.get() > 1)
|
assertTrue(count.get() > 1)
|
||||||
subscriber.unsubscribe()
|
subscriber.unsubscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@CordaService
|
@CordaService
|
||||||
@ -74,6 +76,14 @@ class TestCordaService2(val appServiceHub: AppServiceHub): SingletonSerializeAsT
|
|||||||
@CordaService
|
@CordaService
|
||||||
class LegacyCordaService(@Suppress("UNUSED_PARAMETER") simpleServiceHub: ServiceHub) : SingletonSerializeAsToken()
|
class LegacyCordaService(@Suppress("UNUSED_PARAMETER") simpleServiceHub: ServiceHub) : SingletonSerializeAsToken()
|
||||||
|
|
||||||
|
@CordaService
|
||||||
|
class VaultQueryService(val serviceHub: AppServiceHub): SingletonSerializeAsToken() {
|
||||||
|
init {
|
||||||
|
val criteria = QueryCriteria.VaultQueryCriteria(Vault.StateStatus.UNCONSUMED)
|
||||||
|
serviceHub.vaultService.trackBy(ContractState::class.java, criteria)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class CordaServiceTest {
|
class CordaServiceTest {
|
||||||
private lateinit var mockNet: MockNetwork
|
private lateinit var mockNet: MockNetwork
|
||||||
private lateinit var nodeA: StartedMockNode
|
private lateinit var nodeA: StartedMockNode
|
||||||
@ -120,4 +130,13 @@ class CordaServiceTest {
|
|||||||
service.startServiceFlowAndTrack()
|
service.startServiceFlowAndTrack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reproduce CORDA-2296
|
||||||
|
* Querying the vault from a services constructor failed because the criteriaBuilder
|
||||||
|
* had not been initialized.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
fun `Can query vault service in constructor`() {
|
||||||
|
nodeA.services.cordaService(VaultQueryService::class.java)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user