001/*-
002 * #%L
003 * HAPI FHIR JPA Server
004 * %%
005 * Copyright (C) 2014 - 2025 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.jpa.search.builder.predicate;
021
022import ca.uhn.fhir.context.FhirContext;
023import ca.uhn.fhir.interceptor.model.RequestPartitionId;
024import ca.uhn.fhir.jpa.model.config.PartitionSettings;
025import ca.uhn.fhir.jpa.model.entity.StorageSettings;
026import ca.uhn.fhir.jpa.search.builder.sql.SearchQueryBuilder;
027import ca.uhn.fhir.rest.param.ParamPrefixEnum;
028import com.healthmarketscience.sqlbuilder.BinaryCondition;
029import com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn;
030import com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable;
031import jakarta.annotation.Nonnull;
032
033import java.util.Collection;
034import java.util.List;
035
036public abstract class BasePredicateBuilder {
037
038        private final SearchQueryBuilder mySearchSqlBuilder;
039
040        protected final PartitionSettings myPartitionSettings;
041
042        public BasePredicateBuilder(SearchQueryBuilder theSearchSqlBuilder) {
043                mySearchSqlBuilder = theSearchSqlBuilder;
044                myPartitionSettings = mySearchSqlBuilder.getPartitionSettings();
045        }
046
047        protected SearchQueryBuilder getSearchQueryBuilder() {
048                return mySearchSqlBuilder;
049        }
050
051        protected PartitionSettings getPartitionSettings() {
052                return myPartitionSettings;
053        }
054
055        RequestPartitionId getRequestPartitionId() {
056                return mySearchSqlBuilder.getRequestPartitionId();
057        }
058
059        String getResourceType() {
060                return mySearchSqlBuilder.getResourceType();
061        }
062
063        StorageSettings getStorageSettings() {
064                return mySearchSqlBuilder.getStorageSettings();
065        }
066
067        @Nonnull
068        String generatePlaceholder(Object theInput) {
069                return mySearchSqlBuilder.generatePlaceholder(theInput);
070        }
071
072        @Nonnull
073        List<String> generatePlaceholders(Collection<?> theValues) {
074                return mySearchSqlBuilder.generatePlaceholders(theValues);
075        }
076
077        protected FhirContext getFhirContext() {
078                return mySearchSqlBuilder.getFhirContext();
079        }
080
081        protected void setMatchNothing() {
082                mySearchSqlBuilder.setMatchNothing();
083        }
084
085        protected BinaryCondition createConditionForValueWithComparator(
086                        ParamPrefixEnum theComparator, DbColumn theColumn, Object theValue) {
087                return mySearchSqlBuilder.createConditionForValueWithComparator(theComparator, theColumn, theValue);
088        }
089
090        protected BaseJoiningPredicateBuilder getOrCreateQueryRootTable(boolean theIncludeResourceTypeAndNonDeletedFlag) {
091                return mySearchSqlBuilder.getOrCreateFirstPredicateBuilder(theIncludeResourceTypeAndNonDeletedFlag);
092        }
093
094        public void addJoin(DbTable theFromTable, DbTable theToTable, DbColumn[] theFromColumn, DbColumn[] theToColumn) {
095                mySearchSqlBuilder.addJoin(theFromTable, theToTable, theFromColumn, theToColumn);
096        }
097}