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 protected SearchQueryBuilder getSearchQueryBuilder() { 045 return mySearchSqlBuilder; 046 } 047 048 PartitionSettings getPartitionSettings() { 049 return mySearchSqlBuilder.getPartitionSettings(); 050 } 051 052 RequestPartitionId getRequestPartitionId() { 053 return mySearchSqlBuilder.getRequestPartitionId(); 054 } 055 056 String getResourceType() { 057 return mySearchSqlBuilder.getResourceType(); 058 } 059 060 StorageSettings getStorageSettings() { 061 return mySearchSqlBuilder.getStorageSettings(); 062 } 063 064 @Nonnull 065 String generatePlaceholder(Object theInput) { 066 return mySearchSqlBuilder.generatePlaceholder(theInput); 067 } 068 069 @Nonnull 070 List<String> generatePlaceholders(Collection<?> theValues) { 071 return mySearchSqlBuilder.generatePlaceholders(theValues); 072 } 073 074 protected FhirContext getFhirContext() { 075 return mySearchSqlBuilder.getFhirContext(); 076 } 077 078 protected void setMatchNothing() { 079 mySearchSqlBuilder.setMatchNothing(); 080 } 081 082 protected BinaryCondition createConditionForValueWithComparator( 083 ParamPrefixEnum theComparator, DbColumn theColumn, Object theValue) { 084 return mySearchSqlBuilder.createConditionForValueWithComparator(theComparator, theColumn, theValue); 085 } 086 087 protected BaseJoiningPredicateBuilder getOrCreateQueryRootTable(boolean theIncludeResourceTypeAndNonDeletedFlag) { 088 return mySearchSqlBuilder.getOrCreateFirstPredicateBuilder(theIncludeResourceTypeAndNonDeletedFlag); 089 } 090 091 public void addJoin(DbTable theFromTable, DbTable theToTable, DbColumn[] theFromColumn, DbColumn[] theToColumn) { 092 mySearchSqlBuilder.addJoin(theFromTable, theToTable, theFromColumn, theToColumn); 093 } 094}