001/*- 002 * #%L 003 * HAPI FHIR JPA Server 004 * %% 005 * Copyright (C) 2014 - 2024 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 public BasePredicateBuilder(SearchQueryBuilder theSearchSqlBuilder) { 041 mySearchSqlBuilder = theSearchSqlBuilder; 042 } 043 044 PartitionSettings getPartitionSettings() { 045 return mySearchSqlBuilder.getPartitionSettings(); 046 } 047 048 RequestPartitionId getRequestPartitionId() { 049 return mySearchSqlBuilder.getRequestPartitionId(); 050 } 051 052 String getResourceType() { 053 return mySearchSqlBuilder.getResourceType(); 054 } 055 056 StorageSettings getStorageSettings() { 057 return mySearchSqlBuilder.getStorageSettings(); 058 } 059 060 @Nonnull 061 String generatePlaceholder(Object theInput) { 062 return mySearchSqlBuilder.generatePlaceholder(theInput); 063 } 064 065 @Nonnull 066 List<String> generatePlaceholders(Collection<?> theValues) { 067 return mySearchSqlBuilder.generatePlaceholders(theValues); 068 } 069 070 protected FhirContext getFhirContext() { 071 return mySearchSqlBuilder.getFhirContext(); 072 } 073 074 protected void setMatchNothing() { 075 mySearchSqlBuilder.setMatchNothing(); 076 } 077 078 protected BinaryCondition createConditionForValueWithComparator( 079 ParamPrefixEnum theComparator, DbColumn theColumn, Object theValue) { 080 return mySearchSqlBuilder.createConditionForValueWithComparator(theComparator, theColumn, theValue); 081 } 082 083 protected BaseJoiningPredicateBuilder getOrCreateQueryRootTable(boolean theIncludeResourceTypeAndNonDeletedFlag) { 084 return mySearchSqlBuilder.getOrCreateFirstPredicateBuilder(theIncludeResourceTypeAndNonDeletedFlag); 085 } 086 087 public void addJoin(DbTable theFromTable, DbTable theToTable, DbColumn theFromColumn, DbColumn theToColumn) { 088 mySearchSqlBuilder.addJoin(theFromTable, theToTable, theFromColumn, theToColumn); 089 } 090}