mirror of
https://github.com/corda/corda.git
synced 2025-04-29 07:20:13 +00:00
ENT-5278 - add missed checks for empty lists (#6261)
* add missed checks for empty lists * adding missing brackets * adding missing timeout
This commit is contained in:
parent
36a11e868a
commit
938d038c97
@ -761,8 +761,14 @@ class HibernateQueryCriteriaParser(val contractStateType: Class<out ContractStat
|
|||||||
val existingParticipants = ((((commonPredicates[predicateID]) as CompoundPredicate).expressions[0]) as InPredicate<*>)
|
val existingParticipants = ((((commonPredicates[predicateID]) as CompoundPredicate).expressions[0]) as InPredicate<*>)
|
||||||
.values.map { participant -> (participant as LiteralExpression<*>).literal }
|
.values.map { participant -> (participant as LiteralExpression<*>).literal }
|
||||||
log.warn("Adding new participants: $participants to existing participants: $existingParticipants")
|
log.warn("Adding new participants: $participants to existing participants: $existingParticipants")
|
||||||
commonPredicates.replace(predicateID, criteriaBuilder.and(
|
commonPredicates.replace(
|
||||||
getPersistentPartyRoot().get<VaultSchemaV1.PersistentParty>("x500Name").`in`(existingParticipants + participants)))
|
predicateID,
|
||||||
|
checkIfListIsEmpty(
|
||||||
|
args = existingParticipants + participants,
|
||||||
|
criteriaBuilder = criteriaBuilder,
|
||||||
|
predicate = criteriaBuilder.and(getPersistentPartyRoot().get<VaultSchemaV1.PersistentParty>("x500Name").`in`(existingParticipants + participants))
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Get the persistent party entity.
|
// Get the persistent party entity.
|
||||||
@ -791,12 +797,18 @@ class HibernateQueryCriteriaParser(val contractStateType: Class<out ContractStat
|
|||||||
val subQueryNotExists = criteriaQuery.subquery(Tuple::class.java)
|
val subQueryNotExists = criteriaQuery.subquery(Tuple::class.java)
|
||||||
val subRoot = subQueryNotExists.from(VaultSchemaV1.PersistentParty::class.java)
|
val subRoot = subQueryNotExists.from(VaultSchemaV1.PersistentParty::class.java)
|
||||||
subQueryNotExists.select(subRoot.get("x500Name"))
|
subQueryNotExists.select(subRoot.get("x500Name"))
|
||||||
subQueryNotExists.where(criteriaBuilder.and(
|
|
||||||
criteriaBuilder.equal(vaultStates.get<VaultSchemaV1.VaultStates>("stateRef"),
|
//if the list of exact participants is empty, we return nothing with 1=0
|
||||||
subRoot.get<VaultSchemaV1.PersistentParty>("compositeKey").get<PersistentStateRef>("stateRef"))),
|
if (exactParticipants.isEmpty()) {
|
||||||
criteriaBuilder.not(subRoot.get<VaultSchemaV1.PersistentParty>("x500Name").`in`(exactParticipants)))
|
constraintPredicates.add(criteriaBuilder.and(criteriaBuilder.equal(criteriaBuilder.literal(1), 0)))
|
||||||
val subQueryNotExistsPredicate = criteriaBuilder.and(criteriaBuilder.not(criteriaBuilder.exists(subQueryNotExists)))
|
} else {
|
||||||
constraintPredicates.add(subQueryNotExistsPredicate)
|
subQueryNotExists.where(criteriaBuilder.and(
|
||||||
|
criteriaBuilder.equal(vaultStates.get<VaultSchemaV1.VaultStates>("stateRef"),
|
||||||
|
subRoot.get<VaultSchemaV1.PersistentParty>("compositeKey").get<PersistentStateRef>("stateRef"))),
|
||||||
|
criteriaBuilder.not(subRoot.get<VaultSchemaV1.PersistentParty>("x500Name").`in`(exactParticipants)))
|
||||||
|
val subQueryNotExistsPredicate = criteriaBuilder.and(criteriaBuilder.not(criteriaBuilder.exists(subQueryNotExists)))
|
||||||
|
constraintPredicates.add(subQueryNotExistsPredicate)
|
||||||
|
}
|
||||||
|
|
||||||
// join with transactions for each matching participant (only required where more than one)
|
// join with transactions for each matching participant (only required where more than one)
|
||||||
if (exactParticipants.size > 1)
|
if (exactParticipants.size > 1)
|
||||||
|
@ -249,6 +249,27 @@ abstract class VaultQueryTestsBase : VaultQueryParties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout=300_000)
|
||||||
|
fun `returns zero states when exact participants list is empty`() {
|
||||||
|
database.transaction {
|
||||||
|
identitySvc.verifyAndRegisterIdentity(BIG_CORP_IDENTITY)
|
||||||
|
vaultFiller.fillWithDummyState(participants = listOf(MEGA_CORP))
|
||||||
|
vaultFiller.fillWithDummyState(participants = listOf(MEGA_CORP, BIG_CORP))
|
||||||
|
|
||||||
|
val criteria = VaultQueryCriteria(exactParticipants = emptyList())
|
||||||
|
val results = vaultService.queryBy<ContractState>(criteria)
|
||||||
|
assertThat(results.states).hasSize(0)
|
||||||
|
|
||||||
|
val criteriaWithOneExactParticipant = VaultQueryCriteria(exactParticipants = listOf(MEGA_CORP))
|
||||||
|
val resultsWithOneExactParticipant = vaultService.queryBy<ContractState>(criteriaWithOneExactParticipant)
|
||||||
|
assertThat(resultsWithOneExactParticipant.states).hasSize(1)
|
||||||
|
|
||||||
|
val criteriaWithMoreExactParticipants = VaultQueryCriteria(exactParticipants = listOf(MEGA_CORP, BIG_CORP))
|
||||||
|
val resultsWithMoreExactParticipants = vaultService.queryBy<ContractState>(criteriaWithMoreExactParticipants)
|
||||||
|
assertThat(resultsWithMoreExactParticipants.states).hasSize(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(timeout=300_000)
|
@Test(timeout=300_000)
|
||||||
fun `unconsumed base contract states for two participants`() {
|
fun `unconsumed base contract states for two participants`() {
|
||||||
database.transaction {
|
database.transaction {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user