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.api.SearchIncludeDeletedEnum;
028import ca.uhn.fhir.rest.param.ParamPrefixEnum;
029import com.healthmarketscience.sqlbuilder.BinaryCondition;
030import com.healthmarketscience.sqlbuilder.dbspec.basic.DbColumn;
031import com.healthmarketscience.sqlbuilder.dbspec.basic.DbTable;
032import jakarta.annotation.Nonnull;
033
034import java.util.Collection;
035import java.util.List;
036
037public abstract class BasePredicateBuilder {
038
039        private final SearchQueryBuilder mySearchSqlBuilder;
040
041        protected final PartitionSettings myPartitionSettings;
042
043        public BasePredicateBuilder(SearchQueryBuilder theSearchSqlBuilder) {
044                mySearchSqlBuilder = theSearchSqlBuilder;
045                myPartitionSettings = mySearchSqlBuilder.getPartitionSettings();
046        }
047
048        protected SearchQueryBuilder getSearchQueryBuilder() {
049                return mySearchSqlBuilder;
050        }
051
052        protected PartitionSettings getPartitionSettings() {
053                return myPartitionSettings;
054        }
055
056        RequestPartitionId getRequestPartitionId() {
057                return mySearchSqlBuilder.getRequestPartitionId();
058        }
059
060        String getResourceType() {
061                return mySearchSqlBuilder.getResourceType();
062        }
063
064        StorageSettings getStorageSettings() {
065                return mySearchSqlBuilder.getStorageSettings();
066        }
067
068        @Nonnull
069        String generatePlaceholder(Object theInput) {
070                return mySearchSqlBuilder.generatePlaceholder(theInput);
071        }
072
073        @Nonnull
074        List<String> generatePlaceholders(Collection<?> theValues) {
075                return mySearchSqlBuilder.generatePlaceholders(theValues);
076        }
077
078        protected FhirContext getFhirContext() {
079                return mySearchSqlBuilder.getFhirContext();
080        }
081
082        protected void setMatchNothing() {
083                mySearchSqlBuilder.setMatchNothing();
084        }
085
086        protected BinaryCondition createConditionForValueWithComparator(
087                        ParamPrefixEnum theComparator, DbColumn theColumn, Object theValue) {
088                return mySearchSqlBuilder.createConditionForValueWithComparator(theComparator, theColumn, theValue);
089        }
090
091        protected BaseJoiningPredicateBuilder getOrCreateQueryRootTable(boolean theIncludeResourceTypeAndNonDeletedFlag) {
092                return mySearchSqlBuilder.getOrCreateFirstPredicateBuilder(theIncludeResourceTypeAndNonDeletedFlag, null);
093        }
094
095        protected BaseJoiningPredicateBuilder getOrCreateQueryRootTable(SearchIncludeDeletedEnum theIncludeDeletedFlag) {
096                return mySearchSqlBuilder.getOrCreateFirstPredicateBuilder(true, theIncludeDeletedFlag);
097        }
098
099        public void addJoin(DbTable theFromTable, DbTable theToTable, DbColumn[] theFromColumn, DbColumn[] theToColumn) {
100                mySearchSqlBuilder.addJoin(theFromTable, theToTable, theFromColumn, theToColumn);
101        }
102}