mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
Vault Query API parameter rename to aid clarity (#1627)
* Vault Query API `contractType` renamed to `contractStateType` for clarity. * Vault Query API `contractType` renamed to `contractStateType` for clarity. * Vault Query Criteria attribute `CONTRACT_TYPE` renamed to `CONTRACT_STATE_TYPE` for clarity. * All references to `contractType` renamed to `contractStateType` for clarity.
This commit is contained in:
parent
39bc25e74d
commit
7b59f80bb3
@ -94,24 +94,24 @@ interface CordaRPCOps : RPCOps {
|
||||
fun <T : ContractState> vaultQueryBy(criteria: QueryCriteria,
|
||||
paging: PageSpecification,
|
||||
sorting: Sort,
|
||||
contractType: Class<out T>): Vault.Page<T>
|
||||
contractStateType: Class<out T>): Vault.Page<T>
|
||||
// DOCEND VaultQueryByAPI
|
||||
|
||||
// Note: cannot apply @JvmOverloads to interfaces nor interface implementations
|
||||
// Java Helpers
|
||||
|
||||
// DOCSTART VaultQueryAPIHelpers
|
||||
fun <T : ContractState> vaultQuery(contractType: Class<out T>): Vault.Page<T> {
|
||||
return vaultQueryBy(QueryCriteria.VaultQueryCriteria(), PageSpecification(), Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> vaultQuery(contractStateType: Class<out T>): Vault.Page<T> {
|
||||
return vaultQueryBy(QueryCriteria.VaultQueryCriteria(), PageSpecification(), Sort(emptySet()), contractStateType)
|
||||
}
|
||||
fun <T : ContractState> vaultQueryByCriteria(criteria: QueryCriteria, contractType: Class<out T>): Vault.Page<T> {
|
||||
return vaultQueryBy(criteria, PageSpecification(), Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> vaultQueryByCriteria(criteria: QueryCriteria, contractStateType: Class<out T>): Vault.Page<T> {
|
||||
return vaultQueryBy(criteria, PageSpecification(), Sort(emptySet()), contractStateType)
|
||||
}
|
||||
fun <T : ContractState> vaultQueryByWithPagingSpec(contractType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification): Vault.Page<T> {
|
||||
return vaultQueryBy(criteria, paging, Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> vaultQueryByWithPagingSpec(contractStateType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification): Vault.Page<T> {
|
||||
return vaultQueryBy(criteria, paging, Sort(emptySet()), contractStateType)
|
||||
}
|
||||
fun <T : ContractState> vaultQueryByWithSorting(contractType: Class<out T>, criteria: QueryCriteria, sorting: Sort): Vault.Page<T> {
|
||||
return vaultQueryBy(criteria, PageSpecification(), sorting, contractType)
|
||||
fun <T : ContractState> vaultQueryByWithSorting(contractStateType: Class<out T>, criteria: QueryCriteria, sorting: Sort): Vault.Page<T> {
|
||||
return vaultQueryBy(criteria, PageSpecification(), sorting, contractStateType)
|
||||
}
|
||||
// DOCEND VaultQueryAPIHelpers
|
||||
|
||||
@ -132,24 +132,24 @@ interface CordaRPCOps : RPCOps {
|
||||
fun <T : ContractState> vaultTrackBy(criteria: QueryCriteria,
|
||||
paging: PageSpecification,
|
||||
sorting: Sort,
|
||||
contractType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>>
|
||||
contractStateType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>>
|
||||
// DOCEND VaultTrackByAPI
|
||||
|
||||
// Note: cannot apply @JvmOverloads to interfaces nor interface implementations
|
||||
// Java Helpers
|
||||
|
||||
// DOCSTART VaultTrackAPIHelpers
|
||||
fun <T : ContractState> vaultTrack(contractType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return vaultTrackBy(QueryCriteria.VaultQueryCriteria(), PageSpecification(), Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> vaultTrack(contractStateType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return vaultTrackBy(QueryCriteria.VaultQueryCriteria(), PageSpecification(), Sort(emptySet()), contractStateType)
|
||||
}
|
||||
fun <T : ContractState> vaultTrackByCriteria(contractType: Class<out T>, criteria: QueryCriteria): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return vaultTrackBy(criteria, PageSpecification(), Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> vaultTrackByCriteria(contractStateType: Class<out T>, criteria: QueryCriteria): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return vaultTrackBy(criteria, PageSpecification(), Sort(emptySet()), contractStateType)
|
||||
}
|
||||
fun <T : ContractState> vaultTrackByWithPagingSpec(contractType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return vaultTrackBy(criteria, paging, Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> vaultTrackByWithPagingSpec(contractStateType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return vaultTrackBy(criteria, paging, Sort(emptySet()), contractStateType)
|
||||
}
|
||||
fun <T : ContractState> vaultTrackByWithSorting(contractType: Class<out T>, criteria: QueryCriteria, sorting: Sort): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return vaultTrackBy(criteria, PageSpecification(), sorting, contractType)
|
||||
fun <T : ContractState> vaultTrackByWithSorting(contractStateType: Class<out T>, criteria: QueryCriteria, sorting: Sort): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return vaultTrackBy(criteria, PageSpecification(), sorting, contractStateType)
|
||||
}
|
||||
// DOCEND VaultTrackAPIHelpers
|
||||
|
||||
|
@ -33,7 +33,7 @@ interface VaultQueryService {
|
||||
fun <T : ContractState> _queryBy(criteria: QueryCriteria,
|
||||
paging: PageSpecification,
|
||||
sorting: Sort,
|
||||
contractType: Class<out T>): Vault.Page<T>
|
||||
contractStateType: Class<out T>): Vault.Page<T>
|
||||
|
||||
/**
|
||||
* Generic vault query function which takes a [QueryCriteria] object to define filters,
|
||||
@ -51,49 +51,49 @@ interface VaultQueryService {
|
||||
fun <T : ContractState> _trackBy(criteria: QueryCriteria,
|
||||
paging: PageSpecification,
|
||||
sorting: Sort,
|
||||
contractType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>>
|
||||
contractStateType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>>
|
||||
// DOCEND VaultQueryAPI
|
||||
|
||||
// Note: cannot apply @JvmOverloads to interfaces nor interface implementations
|
||||
// Java Helpers
|
||||
fun <T : ContractState> queryBy(contractType: Class<out T>): Vault.Page<T> {
|
||||
return _queryBy(QueryCriteria.VaultQueryCriteria(), PageSpecification(), Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> queryBy(contractStateType: Class<out T>): Vault.Page<T> {
|
||||
return _queryBy(QueryCriteria.VaultQueryCriteria(), PageSpecification(), Sort(emptySet()), contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> queryBy(contractType: Class<out T>, criteria: QueryCriteria): Vault.Page<T> {
|
||||
return _queryBy(criteria, PageSpecification(), Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> queryBy(contractStateType: Class<out T>, criteria: QueryCriteria): Vault.Page<T> {
|
||||
return _queryBy(criteria, PageSpecification(), Sort(emptySet()), contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> queryBy(contractType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification): Vault.Page<T> {
|
||||
return _queryBy(criteria, paging, Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> queryBy(contractStateType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification): Vault.Page<T> {
|
||||
return _queryBy(criteria, paging, Sort(emptySet()), contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> queryBy(contractType: Class<out T>, criteria: QueryCriteria, sorting: Sort): Vault.Page<T> {
|
||||
return _queryBy(criteria, PageSpecification(), sorting, contractType)
|
||||
fun <T : ContractState> queryBy(contractStateType: Class<out T>, criteria: QueryCriteria, sorting: Sort): Vault.Page<T> {
|
||||
return _queryBy(criteria, PageSpecification(), sorting, contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> queryBy(contractType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification, sorting: Sort): Vault.Page<T> {
|
||||
return _queryBy(criteria, paging, sorting, contractType)
|
||||
fun <T : ContractState> queryBy(contractStateType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification, sorting: Sort): Vault.Page<T> {
|
||||
return _queryBy(criteria, paging, sorting, contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> trackBy(contractType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(QueryCriteria.VaultQueryCriteria(), PageSpecification(), Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> trackBy(contractStateType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(QueryCriteria.VaultQueryCriteria(), PageSpecification(), Sort(emptySet()), contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> trackBy(contractType: Class<out T>, criteria: QueryCriteria): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(criteria, PageSpecification(), Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> trackBy(contractStateType: Class<out T>, criteria: QueryCriteria): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(criteria, PageSpecification(), Sort(emptySet()), contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> trackBy(contractType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(criteria, paging, Sort(emptySet()), contractType)
|
||||
fun <T : ContractState> trackBy(contractStateType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(criteria, paging, Sort(emptySet()), contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> trackBy(contractType: Class<out T>, criteria: QueryCriteria, sorting: Sort): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(criteria, PageSpecification(), sorting, contractType)
|
||||
fun <T : ContractState> trackBy(contractStateType: Class<out T>, criteria: QueryCriteria, sorting: Sort): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(criteria, PageSpecification(), sorting, contractStateType)
|
||||
}
|
||||
|
||||
fun <T : ContractState> trackBy(contractType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification, sorting: Sort): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(criteria, paging, sorting, contractType)
|
||||
fun <T : ContractState> trackBy(contractStateType: Class<out T>, criteria: QueryCriteria, paging: PageSpecification, sorting: Sort): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return _trackBy(criteria, paging, sorting, contractStateType)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import net.corda.core.identity.AbstractParty
|
||||
import net.corda.core.node.services.vault.QueryCriteria
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.toFuture
|
||||
import net.corda.core.transactions.CoreTransaction
|
||||
import net.corda.core.utilities.NonEmptySet
|
||||
import rx.Observable
|
||||
import rx.subjects.PublishSubject
|
||||
@ -228,11 +227,11 @@ interface VaultService {
|
||||
* However, this is fully generic and can operate with custom [FungibleAsset] states.
|
||||
* @param lockId The [FlowLogic.runId.uuid] of the current flow used to soft lock the states.
|
||||
* @param eligibleStatesQuery A custom query object that selects down to the appropriate subset of all states of the
|
||||
* [contractType]. e.g. by selecting on account, issuer, etc. The query is internally augmented with the UNCONSUMED,
|
||||
* [contractStateType]. e.g. by selecting on account, issuer, etc. The query is internally augmented with the UNCONSUMED,
|
||||
* soft lock and contract type requirements.
|
||||
* @param amount The required amount of the asset, but with the issuer stripped off.
|
||||
* It is assumed that compatible issuer states will be filtered out by the [eligibleStatesQuery].
|
||||
* @param contractType class type of the result set.
|
||||
* @param contractStateType class type of the result set.
|
||||
* @return Returns a locked subset of the [eligibleStatesQuery] sufficient to satisfy the requested amount,
|
||||
* or else an empty list and no change in the stored lock states when their are insufficient resources available.
|
||||
*/
|
||||
@ -241,7 +240,7 @@ interface VaultService {
|
||||
fun <T : FungibleAsset<U>, U : Any> tryLockFungibleStatesForSpending(lockId: UUID,
|
||||
eligibleStatesQuery: QueryCriteria,
|
||||
amount: Amount<U>,
|
||||
contractType: Class<out T>): List<StateAndRef<T>>
|
||||
contractStateType: Class<out T>): List<StateAndRef<T>>
|
||||
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ data class Sort(val columns: Collection<SortColumn>) {
|
||||
enum class VaultStateAttribute(val attributeName: String) : Attribute {
|
||||
/** Vault States */
|
||||
NOTARY_NAME("notary"),
|
||||
CONTRACT_TYPE("contractStateClassName"),
|
||||
CONTRACT_STATE_TYPE("contractStateClassName"),
|
||||
STATE_STATUS("stateStatus"),
|
||||
RECORDED_TIME("recordedTime"),
|
||||
CONSUMED_TIME("consumedTime"),
|
||||
|
@ -375,7 +375,7 @@ Behavioural notes
|
||||
-----------------
|
||||
1. **TrackBy** updates do not take into account the full criteria specification due to different and more restrictive syntax
|
||||
in `observables <https://github.com/ReactiveX/RxJava/wiki>`_ filtering (vs full SQL-92 JDBC filtering as used in snapshot views).
|
||||
Specifically, dynamic updates are filtered by ``contractType`` and ``stateType`` (UNCONSUMED, CONSUMED, ALL) only.
|
||||
Specifically, dynamic updates are filtered by ``contractStateType`` and ``stateType`` (UNCONSUMED, CONSUMED, ALL) only.
|
||||
2. **QueryBy** and **TrackBy snapshot views** using pagination may return different result sets as each paging request is a
|
||||
separate SQL query on the underlying database, and it is entirely conceivable that state modifications are taking
|
||||
place in between and/or in parallel to paging requests.
|
||||
|
@ -54,9 +54,9 @@ class CordaRPCOpsImpl(
|
||||
override fun <T : ContractState> vaultQueryBy(criteria: QueryCriteria,
|
||||
paging: PageSpecification,
|
||||
sorting: Sort,
|
||||
contractType: Class<out T>): Vault.Page<T> {
|
||||
contractStateType: Class<out T>): Vault.Page<T> {
|
||||
return database.transaction {
|
||||
services.vaultQueryService._queryBy(criteria, paging, sorting, contractType)
|
||||
services.vaultQueryService._queryBy(criteria, paging, sorting, contractStateType)
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,9 +64,9 @@ class CordaRPCOpsImpl(
|
||||
override fun <T : ContractState> vaultTrackBy(criteria: QueryCriteria,
|
||||
paging: PageSpecification,
|
||||
sorting: Sort,
|
||||
contractType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
contractStateType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return database.transaction {
|
||||
services.vaultQueryService._trackBy(criteria, paging, sorting, contractType)
|
||||
services.vaultQueryService._trackBy(criteria, paging, sorting, contractStateType)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,8 @@ import javax.persistence.Tuple
|
||||
import javax.persistence.criteria.*
|
||||
|
||||
|
||||
class HibernateQueryCriteriaParser(val contractType: Class<out ContractState>,
|
||||
val contractTypeMappings: Map<String, Set<String>>,
|
||||
class HibernateQueryCriteriaParser(val contractStateType: Class<out ContractState>,
|
||||
val contractStateTypeMappings: Map<String, Set<String>>,
|
||||
val criteriaBuilder: CriteriaBuilder,
|
||||
val criteriaQuery: CriteriaQuery<Tuple>,
|
||||
val vaultStates: Root<VaultSchemaV1.VaultStates>) : IQueryCriteriaParser {
|
||||
@ -90,11 +90,11 @@ class HibernateQueryCriteriaParser(val contractType: Class<out ContractState>,
|
||||
return predicateSet
|
||||
}
|
||||
|
||||
private fun deriveContractTypes(contractStateTypes: Set<Class<out ContractState>>? = null): Set<String> {
|
||||
log.trace { "Contract types to be derived: primary ($contractType), additional ($contractStateTypes)" }
|
||||
val combinedContractStateTypes = contractStateTypes?.plus(contractType) ?: setOf(contractType)
|
||||
private fun deriveContractStateTypes(contractStateTypes: Set<Class<out ContractState>>? = null): Set<String> {
|
||||
log.trace { "Contract types to be derived: primary ($contractStateType), additional ($contractStateTypes)" }
|
||||
val combinedContractStateTypes = contractStateTypes?.plus(contractStateType) ?: setOf(contractStateType)
|
||||
combinedContractStateTypes.filter { it.name != ContractState::class.java.name }.let {
|
||||
val interfaces = it.flatMap { contractTypeMappings[it.name] ?: setOf(it.name) }
|
||||
val interfaces = it.flatMap { contractStateTypeMappings[it.name] ?: setOf(it.name) }
|
||||
val concrete = it.filter { !it.isInterface }.map { it.name }
|
||||
log.trace { "Derived contract types: ${interfaces.union(concrete)}" }
|
||||
return interfaces.union(concrete)
|
||||
@ -395,17 +395,17 @@ class HibernateQueryCriteriaParser(val contractType: Class<out ContractState>,
|
||||
}
|
||||
|
||||
// contract state types
|
||||
val contractTypes = deriveContractTypes(criteria.contractStateTypes)
|
||||
if (contractTypes.isNotEmpty()) {
|
||||
val contractStateTypes = deriveContractStateTypes(criteria.contractStateTypes)
|
||||
if (contractStateTypes.isNotEmpty()) {
|
||||
val predicateID = Pair(VaultSchemaV1.VaultStates::contractStateClassName.name, CollectionOperator.IN)
|
||||
if (commonPredicates.containsKey(predicateID)) {
|
||||
val existingTypes = (commonPredicates[predicateID]!!.expressions[0] as InPredicate<*>).values.map { (it as LiteralExpression).literal }.toSet()
|
||||
if (existingTypes != contractTypes) {
|
||||
log.warn("Enriching previous attribute [${VaultSchemaV1.VaultStates::contractStateClassName.name}] values [$existingTypes] with [$contractTypes]")
|
||||
commonPredicates.replace(predicateID, criteriaBuilder.and(vaultStates.get<String>(VaultSchemaV1.VaultStates::contractStateClassName.name).`in`(contractTypes.plus(existingTypes))))
|
||||
if (existingTypes != contractStateTypes) {
|
||||
log.warn("Enriching previous attribute [${VaultSchemaV1.VaultStates::contractStateClassName.name}] values [$existingTypes] with [$contractStateTypes]")
|
||||
commonPredicates.replace(predicateID, criteriaBuilder.and(vaultStates.get<String>(VaultSchemaV1.VaultStates::contractStateClassName.name).`in`(contractStateTypes.plus(existingTypes))))
|
||||
}
|
||||
} else {
|
||||
commonPredicates.put(predicateID, criteriaBuilder.and(vaultStates.get<String>(VaultSchemaV1.VaultStates::contractStateClassName.name).`in`(contractTypes)))
|
||||
commonPredicates.put(predicateID, criteriaBuilder.and(vaultStates.get<String>(VaultSchemaV1.VaultStates::contractStateClassName.name).`in`(contractStateTypes)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,18 +41,18 @@ class HibernateVaultQueryImpl(val hibernateConfig: HibernateConfiguration,
|
||||
* Maintain a list of contract state interfaces to concrete types stored in the vault
|
||||
* for usage in generic queries of type queryBy<LinearState> or queryBy<FungibleState<*>>
|
||||
*/
|
||||
private val contractTypeMappings = bootstrapContractStateTypes()
|
||||
private val contractStateTypeMappings = bootstrapContractStateTypes()
|
||||
|
||||
init {
|
||||
vault.rawUpdates.subscribe { update ->
|
||||
update.produced.forEach {
|
||||
val concreteType = it.state.data.javaClass
|
||||
log.trace { "State update of type: $concreteType" }
|
||||
val seen = contractTypeMappings.any { it.value.contains(concreteType.name) }
|
||||
val seen = contractStateTypeMappings.any { it.value.contains(concreteType.name) }
|
||||
if (!seen) {
|
||||
val contractInterfaces = deriveContractInterfaces(concreteType)
|
||||
contractInterfaces.map {
|
||||
val contractInterface = contractTypeMappings.getOrPut(it.name, { mutableSetOf() })
|
||||
val contractInterface = contractStateTypeMappings.getOrPut(it.name, { mutableSetOf() })
|
||||
contractInterface.add(concreteType.name)
|
||||
}
|
||||
}
|
||||
@ -61,8 +61,8 @@ class HibernateVaultQueryImpl(val hibernateConfig: HibernateConfiguration,
|
||||
}
|
||||
|
||||
@Throws(VaultQueryException::class)
|
||||
override fun <T : ContractState> _queryBy(criteria: QueryCriteria, paging: PageSpecification, sorting: Sort, contractType: Class<out T>): Vault.Page<T> {
|
||||
log.info("Vault Query for contract type: $contractType, criteria: $criteria, pagination: $paging, sorting: $sorting")
|
||||
override fun <T : ContractState> _queryBy(criteria: QueryCriteria, paging: PageSpecification, sorting: Sort, contractStateType: Class<out T>): Vault.Page<T> {
|
||||
log.info("Vault Query for contract type: $contractStateType, criteria: $criteria, pagination: $paging, sorting: $sorting")
|
||||
|
||||
// refresh to include any schemas registered after initial VQ service initialisation
|
||||
sessionFactory = hibernateConfig.sessionFactoryForRegisteredSchemas()
|
||||
@ -73,7 +73,7 @@ class HibernateVaultQueryImpl(val hibernateConfig: HibernateConfiguration,
|
||||
if (!paging.isDefault) {
|
||||
val count = builder { VaultSchemaV1.VaultStates::recordedTime.count() }
|
||||
val countCriteria = VaultCustomQueryCriteria(count, Vault.StateStatus.ALL)
|
||||
val results = queryBy(contractType, criteria.and(countCriteria))
|
||||
val results = queryBy(contractStateType, criteria.and(countCriteria))
|
||||
totalStates = results.otherResults[0] as Long
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ class HibernateVaultQueryImpl(val hibernateConfig: HibernateConfiguration,
|
||||
val queryRootVaultStates = criteriaQuery.from(VaultSchemaV1.VaultStates::class.java)
|
||||
|
||||
// TODO: revisit (use single instance of parser for all queries)
|
||||
val criteriaParser = HibernateQueryCriteriaParser(contractType, contractTypeMappings, criteriaBuilder, criteriaQuery, queryRootVaultStates)
|
||||
val criteriaParser = HibernateQueryCriteriaParser(contractStateType, contractStateTypeMappings, criteriaBuilder, criteriaQuery, queryRootVaultStates)
|
||||
|
||||
try {
|
||||
// parse criteria and build where predicates
|
||||
@ -150,11 +150,11 @@ class HibernateVaultQueryImpl(val hibernateConfig: HibernateConfiguration,
|
||||
private val mutex = ThreadBox({ vault.updatesPublisher })
|
||||
|
||||
@Throws(VaultQueryException::class)
|
||||
override fun <T : ContractState> _trackBy(criteria: QueryCriteria, paging: PageSpecification, sorting: Sort, contractType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
override fun <T : ContractState> _trackBy(criteria: QueryCriteria, paging: PageSpecification, sorting: Sort, contractStateType: Class<out T>): DataFeed<Vault.Page<T>, Vault.Update<T>> {
|
||||
return mutex.locked {
|
||||
val snapshotResults = _queryBy(criteria, paging, sorting, contractType)
|
||||
val snapshotResults = _queryBy(criteria, paging, sorting, contractStateType)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val updates = vault.updatesPublisher.bufferUntilSubscribed().filter { it.containsType(contractType, snapshotResults.stateTypes) } as Observable<Vault.Update<T>>
|
||||
val updates = vault.updatesPublisher.bufferUntilSubscribed().filter { it.containsType(contractStateType, snapshotResults.stateTypes) } as Observable<Vault.Update<T>>
|
||||
DataFeed(snapshotResults, updates)
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,9 @@ import net.corda.core.node.ServiceHub
|
||||
import net.corda.core.node.services.StatesNotAvailableException
|
||||
import net.corda.core.node.services.Vault
|
||||
import net.corda.core.node.services.VaultService
|
||||
import net.corda.core.node.services.vault.IQueryCriteriaParser
|
||||
import net.corda.core.node.services.vault.QueryCriteria
|
||||
import net.corda.core.node.services.vault.Sort
|
||||
import net.corda.core.node.services.vault.SortAttribute
|
||||
import net.corda.core.schemas.PersistentState
|
||||
import net.corda.core.schemas.PersistentStateRef
|
||||
import net.corda.core.serialization.SerializationDefaults.STORAGE_CONTEXT
|
||||
import net.corda.core.serialization.SingletonSerializeAsToken
|
||||
@ -34,7 +32,6 @@ import rx.subjects.PublishSubject
|
||||
import java.security.PublicKey
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
import javax.persistence.criteria.Predicate
|
||||
|
||||
/**
|
||||
* Currently, the node vault service is a very simple RDBMS backed implementation. It will change significantly when
|
||||
@ -339,7 +336,7 @@ class NodeVaultService(private val services: ServiceHub) : SingletonSerializeAsT
|
||||
override fun <T : FungibleAsset<U>, U : Any> tryLockFungibleStatesForSpending(lockId: UUID,
|
||||
eligibleStatesQuery: QueryCriteria,
|
||||
amount: Amount<U>,
|
||||
contractType: Class<out T>): List<StateAndRef<T>> {
|
||||
contractStateType: Class<out T>): List<StateAndRef<T>> {
|
||||
if (amount.quantity == 0L) {
|
||||
return emptyList()
|
||||
}
|
||||
@ -348,9 +345,9 @@ class NodeVaultService(private val services: ServiceHub) : SingletonSerializeAsT
|
||||
val sortAttribute = SortAttribute.Standard(Sort.CommonStateAttribute.STATE_REF)
|
||||
val sorter = Sort(setOf(Sort.SortColumn(sortAttribute, Sort.Direction.ASC)))
|
||||
val enrichedCriteria = QueryCriteria.VaultQueryCriteria(
|
||||
contractStateTypes = setOf(contractType),
|
||||
contractStateTypes = setOf(contractStateType),
|
||||
softLockingCondition = QueryCriteria.SoftLockingCondition(QueryCriteria.SoftLockingType.UNLOCKED_AND_SPECIFIED, listOf(lockId)))
|
||||
val results = services.vaultQueryService.queryBy(contractType, enrichedCriteria.and(eligibleStatesQuery), sorter)
|
||||
val results = services.vaultQueryService.queryBy(contractStateType, enrichedCriteria.and(eligibleStatesQuery), sorter)
|
||||
|
||||
var claimedAmount = 0L
|
||||
val claimedStates = mutableListOf<StateAndRef<T>>()
|
||||
|
@ -1091,7 +1091,7 @@ class VaultQueryTests : TestDependencyInjectionBase() {
|
||||
|
||||
database.transaction {
|
||||
|
||||
val sortCol1 = Sort.SortColumn(SortAttribute.Standard(Sort.VaultStateAttribute.CONTRACT_TYPE), Sort.Direction.DESC)
|
||||
val sortCol1 = Sort.SortColumn(SortAttribute.Standard(Sort.VaultStateAttribute.CONTRACT_STATE_TYPE), Sort.Direction.DESC)
|
||||
val sortCol2 = Sort.SortColumn(SortAttribute.Standard(Sort.VaultStateAttribute.STATE_STATUS), Sort.Direction.ASC)
|
||||
val sortCol3 = Sort.SortColumn(SortAttribute.Standard(Sort.VaultStateAttribute.CONSUMED_TIME), Sort.Direction.DESC)
|
||||
val sorting = Sort(setOf(sortCol1, sortCol2, sortCol3))
|
||||
|
Loading…
Reference in New Issue
Block a user