mirror of
https://github.com/corda/corda.git
synced 2025-02-21 09:51:57 +00:00
h2 cash selection query to support multiple onlyFromIssuerParties and… (#3659)
* h2 cash selection query to support multiple onlyFromIssuerParties and withIssuerRefs * Rid of the compilation warnings
This commit is contained in:
parent
b9efbaa228
commit
2a5b7371d0
@ -43,10 +43,14 @@ class CashSelectionH2Impl : AbstractCashSelection() {
|
|||||||
""" +
|
""" +
|
||||||
(if (notary != null)
|
(if (notary != null)
|
||||||
" AND vs.notary_name = ?" else "") +
|
" AND vs.notary_name = ?" else "") +
|
||||||
(if (onlyFromIssuerParties.isNotEmpty())
|
(if (onlyFromIssuerParties.isNotEmpty()) {
|
||||||
" AND ccs.issuer_key_hash IN (?)" else "") +
|
val repeats = generateSequence { "?" }.take(onlyFromIssuerParties.size).joinToString(",")
|
||||||
(if (withIssuerRefs.isNotEmpty())
|
" AND ccs.issuer_key_hash IN ($repeats)"
|
||||||
" AND ccs.issuer_ref IN (?)" else "")
|
} else "") +
|
||||||
|
(if (withIssuerRefs.isNotEmpty()) {
|
||||||
|
val repeats = generateSequence { "?" }.take(withIssuerRefs.size).joinToString(",")
|
||||||
|
" AND ccs.issuer_ref IN ($repeats)"
|
||||||
|
} else "")
|
||||||
|
|
||||||
// Use prepared statement for protection against SQL Injection (http://www.h2database.com/html/advanced.html#sql_injection)
|
// Use prepared statement for protection against SQL Injection (http://www.h2database.com/html/advanced.html#sql_injection)
|
||||||
connection.prepareStatement(selectJoin).use { psSelectJoin ->
|
connection.prepareStatement(selectJoin).use { psSelectJoin ->
|
||||||
@ -56,10 +60,12 @@ class CashSelectionH2Impl : AbstractCashSelection() {
|
|||||||
psSelectJoin.setString(++pIndex, lockId.toString())
|
psSelectJoin.setString(++pIndex, lockId.toString())
|
||||||
if (notary != null)
|
if (notary != null)
|
||||||
psSelectJoin.setString(++pIndex, notary.name.toString())
|
psSelectJoin.setString(++pIndex, notary.name.toString())
|
||||||
if (onlyFromIssuerParties.isNotEmpty())
|
onlyFromIssuerParties.forEach {
|
||||||
psSelectJoin.setObject(++pIndex, onlyFromIssuerParties.map { it.owningKey.toStringShort() as Any }.toTypedArray())
|
psSelectJoin.setString(++pIndex, it.owningKey.toStringShort())
|
||||||
if (withIssuerRefs.isNotEmpty())
|
}
|
||||||
psSelectJoin.setObject(++pIndex, withIssuerRefs.map { it.bytes as Any }.toTypedArray())
|
withIssuerRefs.forEach {
|
||||||
|
psSelectJoin.setBytes(++pIndex, it.bytes)
|
||||||
|
}
|
||||||
log.debug { psSelectJoin.toString() }
|
log.debug { psSelectJoin.toString() }
|
||||||
|
|
||||||
psSelectJoin.executeQuery().use { rs ->
|
psSelectJoin.executeQuery().use { rs ->
|
||||||
|
@ -69,4 +69,13 @@ class CashSelectionH2ImplTest {
|
|||||||
val paymentResult = node.startFlow(CashPaymentFlow(999.POUNDS, node.info.legalIdentities[0], false)).getOrThrow()
|
val paymentResult = node.startFlow(CashPaymentFlow(999.POUNDS, node.info.legalIdentities[0], false)).getOrThrow()
|
||||||
assertNotNull(paymentResult.recipient)
|
assertNotNull(paymentResult.recipient)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `multiple issuers in issuerConstraint condition`() {
|
||||||
|
val node = mockNet.createNode()
|
||||||
|
node.startFlow(CashIssueFlow(1.POUNDS, OpaqueBytes.of(1), mockNet.defaultNotaryIdentity)).getOrThrow()
|
||||||
|
val request = CashPaymentFlow.PaymentRequest(1.POUNDS, node.info.legalIdentities[0], true, setOf(node.info.legalIdentities[0], mockNet.defaultNotaryIdentity))
|
||||||
|
val paymentResult = node.startFlow(CashPaymentFlow(request)).getOrThrow()
|
||||||
|
assertNotNull(paymentResult.recipient)
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user