Class SearchQueryBuilder
java.lang.Object
ca.uhn.fhir.jpa.search.builder.sql.SearchQueryBuilder
-
Constructor Summary
ConstructorDescriptionSearchQueryBuilder
(ca.uhn.fhir.context.FhirContext theFhirContext, StorageSettings theStorageSettings, PartitionSettings thePartitionSettings, RequestPartitionId theRequestPartitionId, String theResourceType, SqlObjectFactory theSqlBuilderFactory, HibernatePropertiesProvider theDialectProvider, boolean theCountQuery) Constructor -
Method Summary
Modifier and TypeMethodDescriptionAdd and return a predicate builder (or a root query if no root query exists yet) for selecting on a Composite Unique search parameterAdd and return a predicate builder (or a root query if no root query exists yet) for selecting on a Composite Unique search parameteraddCoordsPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a COORDS search parametervoid
addCustomJoin
(com.healthmarketscience.sqlbuilder.SelectQuery.JoinType theJoinType, com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theFromTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theToTable, com.healthmarketscience.sqlbuilder.Condition theCondition) addDatePredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a DATE search parametervoid
addJoin
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theFromTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theToTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theFromColumn, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theToColumn) void
addJoin
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theFromTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theToTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theFromColumn, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theToColumn, com.healthmarketscience.sqlbuilder.SelectQuery.JoinType theJoinType) addNumberPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a NUMBER search parametervoid
addPredicate
(com.healthmarketscience.sqlbuilder.Condition theCondition) com.healthmarketscience.sqlbuilder.ComboCondition
addPredicateLastUpdated
(ca.uhn.fhir.rest.param.DateRangeParam theDateRange) com.healthmarketscience.sqlbuilder.ComboCondition
addPredicateLastUpdated
(ca.uhn.fhir.rest.param.DateRangeParam theDateRange, ResourceTablePredicateBuilder theResourceTablePredicateBuilder) addQuantityNormalizedPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) addQuantityPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a QUANTITY search parameteraddReferencePredicateBuilder
(QueryStack theQueryStack, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a REFERENCE search parameteraddReferencePredicateBuilderReversed
(QueryStack theQueryStack, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a resource link where the source and target are reversed.void
addResourceIdsPredicate
(List<Long> thePidList) addResourceTablePredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on the Resource tableaddSearchParamPresentPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a:missing
search parametervoid
addSortCoordsNear
(CoordsPredicateBuilder theCoordsBuilder, double theLatitudeValue, double theLongitudeValue, boolean theAscending) void
addSortDate
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending) void
addSortDate
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending, boolean theUseAggregate) void
addSortDate
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theTheColumnValueNormalized, boolean theTheAscending, com.healthmarketscience.sqlbuilder.OrderObject.NullOrder theNullOrder, boolean theUseAggregate) void
addSortNumeric
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending) void
addSortNumeric
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending, boolean theUseAggregate) void
addSortNumeric
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theTheColumnValueNormalized, boolean theAscending, com.healthmarketscience.sqlbuilder.OrderObject.NullOrder theNullOrder, boolean theUseAggregate) void
addSortString
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending) void
addSortString
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending, boolean theUseAggregate) void
addSortString
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theTheColumnValueNormalized, boolean theTheAscending, com.healthmarketscience.sqlbuilder.OrderObject.NullOrder theNullOrder, boolean theUseAggregate) addSourcePredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn, com.healthmarketscience.sqlbuilder.SelectQuery.JoinType theJoinType) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a_source
search parameteraddStringPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a STRING search parametercom.healthmarketscience.sqlbuilder.dbspec.basic.DbTable
addTagPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a_tag
search parameteraddTokenPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a TOKEN search parameteraddUriPredicateBuilder
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a URI search parameterstatic String
applyLimitToSql
(org.hibernate.dialect.Dialect theDialect, Integer theOffset, Integer theMaxResultsToFetch, String theInputSql, String theSelectedColumnOrNull, List<Object> theBindVariables) This method applies the theDialect limiter (select first NNN offset MMM etc etc..) to a SQL string.static int
bindOffsetParameter
(List<Object> theBindVariables, Integer theOffset, org.hibernate.dialect.pagination.AbstractLimitHandler theLimitHandler, int theStartOfQueryParameterIndex, boolean theBindLimitParametersFirst) int
com.healthmarketscience.sqlbuilder.BinaryCondition
createConditionForValueWithComparator
(ca.uhn.fhir.rest.param.ParamPrefixEnum theComparator, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumn, Object theValue) Create a predicate builder for selecting on a DATE search parameterCreate a predicate builder for selecting on a NUMBER search parametercom.healthmarketscience.sqlbuilder.ComboCondition
createOnCondition
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceColumn, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theTargetColumn) Create a predicate builder for selecting on a QUANTITY search parametercreateReferencePredicateBuilder
(QueryStack theQueryStack) Create a predicate builder for selecting on a REFERENCE search parameterCreate a predicate builder for selecting on a STRING search parameterCreate a predicate builder for selecting on a TOKEN search parameterCreate a predicate builder for selecting on a URI search parametervoid
excludeResourceIdsPredicate
(Set<JpaPid> theExistingPidSetToExclude) Generate and return the SQL generated by this buildergeneratePlaceholder
(Object theValue) The SQL Builder library has one annoying limitation, which is that it does not use/understand bind variables for its generated SQL.generatePlaceholders
(Collection<?> theValues) ca.uhn.fhir.context.FhirContext
If at least one predicate builder already exists, return the last one added to the chain.getOrCreateFirstPredicateBuilder
(boolean theIncludeResourceTypeAndNonDeletedFlag) If at least one predicate builder already exists, return the last one added to the chain.getOrCreateResourceTablePredicateBuilder
(boolean theIncludeResourceTypeAndNonDeletedFlag) com.healthmarketscience.sqlbuilder.SelectQuery
boolean
boolean
boolean
newChildSqlBuilder
(boolean theSelectPartitionId) void
void
setNeedResourceTableRoot
(boolean theNeedResourceTableRoot) If set to true (default is false), force the generated SQL to start with theHFJ_RESOURCE
table at the root of the query.com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[]
toJoinColumns
(BaseJoiningPredicateBuilder theBuilder) com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[]
toJoinColumns
(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn partitionIdColumn, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn resourceIdColumn) Remove or keep partition_id columns depending on settings.
-
Constructor Details
-
SearchQueryBuilder
public SearchQueryBuilder(ca.uhn.fhir.context.FhirContext theFhirContext, StorageSettings theStorageSettings, PartitionSettings thePartitionSettings, RequestPartitionId theRequestPartitionId, String theResourceType, SqlObjectFactory theSqlBuilderFactory, HibernatePropertiesProvider theDialectProvider, boolean theCountQuery) Constructor
-
-
Method Details
-
getFhirContext
-
addComboUniquePredicateBuilder
Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a Composite Unique search parameter -
addComboNonUniquePredicateBuilder
Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a Composite Unique search parameter -
addCoordsPredicateBuilder
public CoordsPredicateBuilder addCoordsPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a COORDS search parameter -
addDatePredicateBuilder
public DatePredicateBuilder addDatePredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a DATE search parameter -
createDatePredicateBuilder
Create a predicate builder for selecting on a DATE search parameter -
addNumberPredicateBuilder
public NumberPredicateBuilder addNumberPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a NUMBER search parameter -
createNumberPredicateBuilder
Create a predicate builder for selecting on a NUMBER search parameter -
addResourceTablePredicateBuilder
public ResourceTablePredicateBuilder addResourceTablePredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on the Resource table -
addQuantityPredicateBuilder
public QuantityPredicateBuilder addQuantityPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a QUANTITY search parameter -
createQuantityPredicateBuilder
Create a predicate builder for selecting on a QUANTITY search parameter -
addQuantityNormalizedPredicateBuilder
public QuantityNormalizedPredicateBuilder addQuantityNormalizedPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) -
addSourcePredicateBuilder
public SourcePredicateBuilder addSourcePredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn, com.healthmarketscience.sqlbuilder.SelectQuery.JoinType theJoinType) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a_source
search parameter -
addReferencePredicateBuilder
public ResourceLinkPredicateBuilder addReferencePredicateBuilder(QueryStack theQueryStack, @Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a REFERENCE search parameter -
createReferencePredicateBuilder
Create a predicate builder for selecting on a REFERENCE search parameter -
addReferencePredicateBuilderReversed
public ResourceLinkPredicateBuilder addReferencePredicateBuilderReversed(QueryStack theQueryStack, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a resource link where the source and target are reversed. This is used for _has queries. -
addStringPredicateBuilder
public StringPredicateBuilder addStringPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a STRING search parameter -
createStringPredicateBuilder
Create a predicate builder for selecting on a STRING search parameter -
addTagPredicateBuilder
public TagPredicateBuilder addTagPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a_tag
search parameter -
addTokenPredicateBuilder
public TokenPredicateBuilder addTokenPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a TOKEN search parameter -
createTokenPredicateBuilder
Create a predicate builder for selecting on a TOKEN search parameter -
addCustomJoin
public void addCustomJoin(com.healthmarketscience.sqlbuilder.SelectQuery.JoinType theJoinType, com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theFromTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theToTable, com.healthmarketscience.sqlbuilder.Condition theCondition) -
createOnCondition
public com.healthmarketscience.sqlbuilder.ComboCondition createOnCondition(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceColumn, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theTargetColumn) -
addSearchParamPresentPredicateBuilder
public SearchParamPresentPredicateBuilder addSearchParamPresentPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Add and return a predicate builder (or a root query if no root query exists yet) for selecting on a:missing
search parameter -
addUriPredicateBuilder
public UriPredicateBuilder addUriPredicateBuilder(@Nullable com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theSourceJoinColumn) Create, add and return a predicate builder (or a root query if no root query exists yet) for selecting on a URI search parameter -
createUriPredicateBuilder
Create a predicate builder for selecting on a URI search parameter -
getSqlBuilderFactory
-
newResourceIdBuilder
-
toJoinColumns
@Nonnull public com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] toJoinColumns(BaseJoiningPredicateBuilder theBuilder) -
toJoinColumns
@Nonnull public com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] toJoinColumns(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn partitionIdColumn, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn resourceIdColumn) Remove or keep partition_id columns depending on settings. -
isIncludePartitionIdInJoins
-
addJoin
public void addJoin(com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theFromTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theToTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theFromColumn, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theToColumn) -
addJoin
public void addJoin(com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theFromTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable theToTable, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theFromColumn, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn[] theToColumn, com.healthmarketscience.sqlbuilder.SelectQuery.JoinType theJoinType) -
isSelectPartitionId
-
generate
Generate and return the SQL generated by this builder -
applyLimitToSql
public static String applyLimitToSql(org.hibernate.dialect.Dialect theDialect, Integer theOffset, Integer theMaxResultsToFetch, String theInputSql, @Nullable String theSelectedColumnOrNull, List<Object> theBindVariables) This method applies the theDialect limiter (select first NNN offset MMM etc etc..) to a SQL string. It enhances the built-in Hibernate dialect version with some additional enhancements. -
bindOffsetParameter
public static int bindOffsetParameter(List<Object> theBindVariables, @Nullable Integer theOffset, org.hibernate.dialect.pagination.AbstractLimitHandler theLimitHandler, int theStartOfQueryParameterIndex, boolean theBindLimitParametersFirst) -
getOrCreateFirstPredicateBuilder
If at least one predicate builder already exists, return the last one added to the chain. If none has been selected, create a builder on HFJ_RESOURCE, add it and return it. -
getOrCreateFirstPredicateBuilder
public BaseJoiningPredicateBuilder getOrCreateFirstPredicateBuilder(boolean theIncludeResourceTypeAndNonDeletedFlag) If at least one predicate builder already exists, return the last one added to the chain. If none has been selected, create a builder on HFJ_RESOURCE, add it and return it. -
getOrCreateResourceTablePredicateBuilder
-
getOrCreateResourceTablePredicateBuilder
public ResourceTablePredicateBuilder getOrCreateResourceTablePredicateBuilder(boolean theIncludeResourceTypeAndNonDeletedFlag) -
generatePlaceholder
The SQL Builder library has one annoying limitation, which is that it does not use/understand bind variables for its generated SQL. So we work around this by replacing our contents with a string in the SQL consisting of[random UUID]-[value index]
and then -
generatePlaceholders
-
countBindVariables
-
setMatchNothing
-
addTable
-
getPartitionSettings
-
getRequestPartitionId
-
getResourceType
-
getStorageSettings
-
addPredicate
-
addPredicateLastUpdated
public com.healthmarketscience.sqlbuilder.ComboCondition addPredicateLastUpdated(ca.uhn.fhir.rest.param.DateRangeParam theDateRange) -
addPredicateLastUpdated
public com.healthmarketscience.sqlbuilder.ComboCondition addPredicateLastUpdated(ca.uhn.fhir.rest.param.DateRangeParam theDateRange, ResourceTablePredicateBuilder theResourceTablePredicateBuilder) -
addResourceIdsPredicate
-
excludeResourceIdsPredicate
-
createConditionForValueWithComparator
public com.healthmarketscience.sqlbuilder.BinaryCondition createConditionForValueWithComparator(ca.uhn.fhir.rest.param.ParamPrefixEnum theComparator, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumn, Object theValue) -
newChildSqlBuilder
-
getSelect
-
haveAtLeastOnePredicate
-
addSortCoordsNear
public void addSortCoordsNear(CoordsPredicateBuilder theCoordsBuilder, double theLatitudeValue, double theLongitudeValue, boolean theAscending) -
addSortString
public void addSortString(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending) -
addSortString
public void addSortString(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending, boolean theUseAggregate) -
addSortNumeric
public void addSortNumeric(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending) -
addSortNumeric
public void addSortNumeric(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending, boolean theUseAggregate) -
addSortDate
public void addSortDate(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending) -
addSortDate
public void addSortDate(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumnValueNormalized, boolean theAscending, boolean theUseAggregate) -
addSortString
public void addSortString(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theTheColumnValueNormalized, boolean theTheAscending, com.healthmarketscience.sqlbuilder.OrderObject.NullOrder theNullOrder, boolean theUseAggregate) -
addSortNumeric
public void addSortNumeric(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theTheColumnValueNormalized, boolean theAscending, com.healthmarketscience.sqlbuilder.OrderObject.NullOrder theNullOrder, boolean theUseAggregate) -
addSortDate
public void addSortDate(com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theTheColumnValueNormalized, boolean theTheAscending, com.healthmarketscience.sqlbuilder.OrderObject.NullOrder theNullOrder, boolean theUseAggregate) -
setNeedResourceTableRoot
If set to true (default is false), force the generated SQL to start with theHFJ_RESOURCE
table at the root of the query.This seems to perform better if there are multiple joins on the resource ID table.
-