Class SearchQueryBuilder

java.lang.Object
ca.uhn.fhir.jpa.search.builder.sql.SearchQueryBuilder

public class SearchQueryBuilder extends Object
  • Constructor Details

  • Method Details

    • getFhirContext

      public ca.uhn.fhir.context.FhirContext 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)
    • addResourceHistoryProvenancePredicateBuilder

      public ResourceHistoryProvenancePredicateBuilder addResourceHistoryProvenancePredicateBuilder(@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
    • addResourceHistoryPredicateBuilder

      public ResourceHistoryPredicateBuilder addResourceHistoryPredicateBuilder(@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

      public boolean 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

      public boolean isSelectPartitionId()
    • generate

      public GeneratedSql generate(@Nullable Integer theOffset, @Nullable Integer theMaxResultsToFetch)
      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

      public String generatePlaceholder(Object theValue)
      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

      public List<String> generatePlaceholders(Collection<?> theValues)
    • countBindVariables

      public int countBindVariables()
    • setMatchNothing

      public void setMatchNothing()
    • addTable

      public com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable addTable(String theTableName)
    • getPartitionSettings

    • getRequestPartitionId

    • getResourceType

    • getStorageSettings

    • addPredicate

      public void addPredicate(@Nonnull com.healthmarketscience.sqlbuilder.Condition theCondition)
    • 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

      public void addResourceIdsPredicate(List<JpaPid> thePidList)
    • excludeResourceIdsPredicate

      public void excludeResourceIdsPredicate(Set<JpaPid> theExistingPidSetToExclude)
    • createConditionForValueWithComparator

      public com.healthmarketscience.sqlbuilder.BinaryCondition createConditionForValueWithComparator(ca.uhn.fhir.rest.param.ParamPrefixEnum theComparator, com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn theColumn, Object theValue)
    • newChildSqlBuilder

      public SearchQueryBuilder newChildSqlBuilder(boolean theSelectPartitionId)
    • getSelect

      public com.healthmarketscience.sqlbuilder.SelectQuery getSelect()
    • haveAtLeastOnePredicate

      public boolean 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

      public void setNeedResourceTableRoot(boolean theNeedResourceTableRoot)
      If set to true (default is false), force the generated SQL to start with the HFJ_RESOURCE table at the root of the query.

      This seems to perform better if there are multiple joins on the resource ID table.