Class QueryStack
RES_ID
column on the HFJ_RESOURCE
(ResourceTable
)
table.
We add predicates (WHERE A=B) to it, and can join other tables to it as well. At the root of the query
we are typically doing a select RES_ID from HFJ_RESOURCE where (....)
and this class
is used to build the where clause. In the case of subqueries though, we may be performing a
select on a different table since many tables have a column with a FK dependency on RES_ID.
-
Constructor Summary
ConstructorDescriptionQueryStack
(javax.persistence.criteria.CriteriaBuilder theCriteriaBuilder, String theResourceType, SearchParameterMap theSearchParameterMap, ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId) Constructor -
Method Summary
Modifier and TypeMethodDescriptionjavax.persistence.criteria.Predicate
Add a predicate that will never match any resourcesvoid
addPredicate
(javax.persistence.criteria.Predicate thePredicate) Adds a predicate to the current select statementvoid
addPredicates
(List<javax.persistence.criteria.Predicate> thePredicates) Adds predicate(s) to the current select statementvoid
addPredicatesWithImplicitTypeSelection
(List<javax.persistence.criteria.Predicate> thePredicates) Adds predicates and marks them as having implicit type selection in it.void
addPredicateWithImplicitTypeSelection
(javax.persistence.criteria.Predicate thePredicate) Adds a predicate and marks it as having implicit type selection in it.void
void
Clear all predicates from the current select statement<T> javax.persistence.criteria.From<?,
T> createJoin
(SearchBuilderJoinEnum theType, String theSearchParameterName) Creates a new SQL join from the current select statement to another table, using the resource PID as the joining key<Y> javax.persistence.criteria.Path<Y>
Gets an attribute (aka a column) from the current select statement.Optional<javax.persistence.criteria.Join<?,
?>> getExistingJoin
(SearchBuilderJoinKey theKey) Returns a join that was previously created by a call tocreateJoin(SearchBuilderJoinEnum, String)
, if one exists for the given key.Map<String,
javax.persistence.criteria.From<?, ResourceIndexedSearchParamDate>> javax.persistence.criteria.Expression<Date>
Fetch the column for the current table root that corresponds to the resource's lastUpdated timeList<javax.persistence.criteria.Predicate>
Fetch all the current predicatesjavax.persistence.criteria.Expression<Long>
Fetch the column for the current table root that corresponds to the resource's PIDjavax.persistence.criteria.Root<?>
TODO This class should avoid leaking the internal query root, but we need to do so for how composite search params are currently implemented.boolean
isEmpty()
void
Add an SQLorder by
expressionjavax.persistence.criteria.AbstractQuery<Long>
pop()
This method must be called once all predicates have been addedvoid
Add a newselect RES_ID from (....)
to the stack, where the specific table being selected on will be determined based on the first call tocreateJoin(SearchBuilderJoinEnum, String)
.void
Add a newselect count(RES_ID) from HFJ_RESOURCE
to the stack.void
Add a newselect DISTINCT RES_ID from HFJ_RESOURCE
to the stack.void
Add a newselect RES_ID from HFJ_RESOURCE
to the stack.void
pushResourceTableSubQuery
(String theResourceType) Add a newselect RES_ID from HFJ_RESOURCE
to the stack.javax.persistence.criteria.Subquery<Long>
-
Constructor Details
-
QueryStack
public QueryStack(javax.persistence.criteria.CriteriaBuilder theCriteriaBuilder, String theResourceType, SearchParameterMap theSearchParameterMap, ca.uhn.fhir.interceptor.model.RequestPartitionId theRequestPartitionId) Constructor
-
-
Method Details
-
pushResourceTableQuery
Add a newselect RES_ID from HFJ_RESOURCE
to the stack. All predicates added to the QueryRootStack will be added to this select clause untilpop()
is called.This method must only be called when the stack is empty.
-
pushResourceTableDistinctQuery
Add a newselect DISTINCT RES_ID from HFJ_RESOURCE
to the stack. All predicates added to the QueryRootStack will be added to this select clause untilpop()
is called.This method must only be called when the stack is empty.
-
pushResourceTableCountQuery
Add a newselect count(RES_ID) from HFJ_RESOURCE
to the stack. All predicates added to the QueryRootStack will be added to this select clause untilpop()
is called.This method must only be called when the stack is empty.
-
pushResourceTableSubQuery
Add a newselect RES_ID from HFJ_RESOURCE
to the stack. All predicates added to the QueryRootStack will be added to this select clause untilpop()
is called.This method must only be called when the stack is NOT empty.
-
pushIndexTableSubQuery
Add a newselect RES_ID from (....)
to the stack, where the specific table being selected on will be determined based on the first call tocreateJoin(SearchBuilderJoinEnum, String)
. All predicates added to the QueryRootStack will be added to this select clause untilpop()
is called.This method must only be called when the stack is NOT empty.
-
pop
This method must be called once all predicates have been added -
createJoin
public <T> javax.persistence.criteria.From<?,T> createJoin(SearchBuilderJoinEnum theType, String theSearchParameterName) Creates a new SQL join from the current select statement to another table, using the resource PID as the joining key -
getExistingJoin
Returns a join that was previously created by a call tocreateJoin(SearchBuilderJoinEnum, String)
, if one exists for the given key. -
get
Gets an attribute (aka a column) from the current select statement.- Parameters:
theAttributeName
- Must be the name of a java field for the entity/table being selected on
-
addPredicate
Adds a predicate to the current select statement -
addPredicateWithImplicitTypeSelection
public void addPredicateWithImplicitTypeSelection(javax.persistence.criteria.Predicate thePredicate) Adds a predicate and marks it as having implicit type selection in it. In other words, call this method if a this predicate will ensure:- Only Resource PIDs for the correct resource type will be selected
- Only Resource PIDs for non-deleted resources will be selected
-
addPredicatesWithImplicitTypeSelection
public void addPredicatesWithImplicitTypeSelection(List<javax.persistence.criteria.Predicate> thePredicates) Adds predicates and marks them as having implicit type selection in it. In other words, call this method if a this predicate will ensure:- Only Resource PIDs for the correct resource type will be selected
- Only Resource PIDs for non-deleted resources will be selected
-
addPredicates
Adds predicate(s) to the current select statement -
clearPredicates
Clear all predicates from the current select statement -
getPredicates
Fetch all the current predicatesTODO This should really be package protected, but it is called externally in one spot - We need to clean that up at some point.
-
clearHasImplicitTypeSelection
- See Also:
-
setHasImplicitTypeSelection()
-
isEmpty
-
orderBy
Add an SQLorder by
expression -
getLastUpdatedColumn
Fetch the column for the current table root that corresponds to the resource's lastUpdated time -
getResourcePidColumn
Fetch the column for the current table root that corresponds to the resource's PID -
subqueryForTagNegation
-
getRootForComposite
TODO This class should avoid leaking the internal query root, but we need to do so for how composite search params are currently implemented. These only half work in the first place so I'm not going to worry about the fact that they rely on a leaky abstraction right now.. But when we get around to implementing composites properly, let's not continue this. JA 2020-05-12 -
addNeverMatchingPredicate
Add a predicate that will never match any resources -
getJoinMap
-