mirror of
https://github.com/corda/corda.git
synced 2024-12-19 04:57:58 +00:00
CORDA-3191: When querying for attachment ids now only retrieve the attachment id columm not whole object. (#6199)
This commit is contained in:
parent
ecf74053c0
commit
9bcb9b2f54
@ -458,17 +458,38 @@ class NodeAttachmentService @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO do not retrieve whole attachments only to return ids - https://r3-cev.atlassian.net/browse/CORDA-3191 raised to address this
|
||||
override fun queryAttachments(criteria: AttachmentQueryCriteria, sorting: AttachmentSort?): List<AttachmentId> {
|
||||
log.info("Attachment query criteria: $criteria, sorting: $sorting")
|
||||
return database.transaction {
|
||||
createAttachmentsQuery(
|
||||
createAttachmentsIdsQuery(
|
||||
criteria,
|
||||
sorting
|
||||
).resultList.map { AttachmentId.parse(it.attId) }
|
||||
).resultList.map { AttachmentId.parse(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun createAttachmentsIdsQuery(
|
||||
criteria: AttachmentQueryCriteria,
|
||||
sorting: AttachmentSort?
|
||||
): Query<String> {
|
||||
val session = currentDBSession()
|
||||
val criteriaBuilder = session.criteriaBuilder
|
||||
|
||||
val criteriaQuery = criteriaBuilder.createQuery(String::class.java)
|
||||
val root = criteriaQuery.from(DBAttachment::class.java)
|
||||
criteriaQuery.select(root.get("${DBAttachment::attId.name}"))
|
||||
|
||||
val criteriaParser = HibernateAttachmentQueryCriteriaParser<DBAttachment,String>(
|
||||
criteriaBuilder,
|
||||
criteriaQuery,
|
||||
root
|
||||
)
|
||||
// parse criteria and build where predicates
|
||||
criteriaParser.parse(criteria, sorting)
|
||||
// prepare query for execution
|
||||
return session.createQuery(criteriaQuery)
|
||||
}
|
||||
|
||||
private fun createAttachmentsQuery(
|
||||
criteria: AttachmentQueryCriteria,
|
||||
sorting: AttachmentSort?
|
||||
@ -477,11 +498,13 @@ class NodeAttachmentService @JvmOverloads constructor(
|
||||
val criteriaBuilder = session.criteriaBuilder
|
||||
|
||||
val criteriaQuery = criteriaBuilder.createQuery(DBAttachment::class.java)
|
||||
val root = criteriaQuery.from(DBAttachment::class.java)
|
||||
criteriaQuery.select(root)
|
||||
|
||||
val criteriaParser = HibernateAttachmentQueryCriteriaParser(
|
||||
val criteriaParser = HibernateAttachmentQueryCriteriaParser<DBAttachment,DBAttachment>(
|
||||
criteriaBuilder,
|
||||
criteriaQuery,
|
||||
criteriaQuery.from(DBAttachment::class.java)
|
||||
root
|
||||
)
|
||||
|
||||
// parse criteria and build where predicates
|
||||
|
@ -155,18 +155,14 @@ abstract class AbstractQueryCriteriaParser<Q : GenericQueryCriteria<Q,P>, in P:
|
||||
}
|
||||
}
|
||||
|
||||
class HibernateAttachmentQueryCriteriaParser(override val criteriaBuilder: CriteriaBuilder,
|
||||
private val criteriaQuery: CriteriaQuery<NodeAttachmentService.DBAttachment>, val root: Root<NodeAttachmentService.DBAttachment>) :
|
||||
class HibernateAttachmentQueryCriteriaParser<T,R>(override val criteriaBuilder: CriteriaBuilder,
|
||||
private val criteriaQuery: CriteriaQuery<R>, val root: Root<T>) :
|
||||
AbstractQueryCriteriaParser<AttachmentQueryCriteria, AttachmentsQueryCriteriaParser, AttachmentSort>(), AttachmentsQueryCriteriaParser {
|
||||
|
||||
private companion object {
|
||||
private val log = contextLogger()
|
||||
}
|
||||
|
||||
init {
|
||||
criteriaQuery.select(root)
|
||||
}
|
||||
|
||||
override fun parse(criteria: AttachmentQueryCriteria, sorting: AttachmentSort?): Collection<Predicate> {
|
||||
val predicateSet = criteria.visit(this)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user