Search in sources :

Example 16 with Predicate

use of org.hibernate.sql.ast.tree.predicate.Predicate in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method visitInListPredicate.

@Override
public Predicate visitInListPredicate(SqmInListPredicate<?> predicate) {
    // handling for "expansion"
    if (predicate.getListExpressions().size() == 1) {
        final SqmExpression<?> sqmExpression = predicate.getListExpressions().get(0);
        if (sqmExpression instanceof SqmParameter) {
            final SqmParameter<?> sqmParameter = (SqmParameter<?>) sqmExpression;
            if (sqmParameter.allowMultiValuedBinding()) {
                final Predicate specialCase = processInListWithSingleParameter(predicate, sqmParameter);
                if (specialCase != null) {
                    return specialCase;
                }
            }
        }
    }
    // otherwise - no special case...
    final FromClauseIndex fromClauseIndex = fromClauseIndexStack.getCurrent();
    inferrableTypeAccessStack.push(() -> {
        for (SqmExpression<?> listExpression : predicate.getListExpressions()) {
            final MappingModelExpressible<?> mapping = determineValueMapping(listExpression, fromClauseIndex);
            if (mapping != null) {
                return mapping;
            }
        }
        return null;
    });
    final Expression testExpression;
    try {
        testExpression = (Expression) predicate.getTestExpression().accept(this);
    } finally {
        inferrableTypeAccessStack.pop();
    }
    final InListPredicate inPredicate = new InListPredicate(testExpression, predicate.isNegated(), getBooleanType());
    inferrableTypeAccessStack.push(() -> determineValueMapping(predicate.getTestExpression(), fromClauseIndex));
    try {
        for (SqmExpression<?> expression : predicate.getListExpressions()) {
            inPredicate.addExpression((Expression) expression.accept(this));
        }
    } finally {
        inferrableTypeAccessStack.pop();
    }
    return inPredicate;
}
Also used : BinaryArithmeticExpression(org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression) SqmModifiedSubQueryExpression(org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression) SelfRenderingFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression) SelfRenderingAggregateFunctionSqlAstExpression(org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression) CaseSearchedExpression(org.hibernate.sql.ast.tree.expression.CaseSearchedExpression) SelfRenderingSqlFragmentExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression) Expression(org.hibernate.sql.ast.tree.expression.Expression) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) SqmExpression(org.hibernate.query.sqm.tree.expression.SqmExpression) CaseSimpleExpression(org.hibernate.sql.ast.tree.expression.CaseSimpleExpression) SqlSelectionExpression(org.hibernate.sql.ast.tree.expression.SqlSelectionExpression) ModifiedSubQueryExpression(org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression) SqmInListPredicate(org.hibernate.query.sqm.tree.predicate.SqmInListPredicate) InListPredicate(org.hibernate.sql.ast.tree.predicate.InListPredicate) SqmParameter(org.hibernate.query.sqm.tree.expression.SqmParameter) InSubQueryPredicate(org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate) SqmBooleanExpressionPredicate(org.hibernate.query.sqm.tree.predicate.SqmBooleanExpressionPredicate) SelfRenderingPredicate(org.hibernate.sql.ast.tree.predicate.SelfRenderingPredicate) NegatedPredicate(org.hibernate.sql.ast.tree.predicate.NegatedPredicate) LikePredicate(org.hibernate.sql.ast.tree.predicate.LikePredicate) BetweenPredicate(org.hibernate.sql.ast.tree.predicate.BetweenPredicate) SqmPredicate(org.hibernate.query.sqm.tree.predicate.SqmPredicate) SqmNegatedPredicate(org.hibernate.query.sqm.tree.predicate.SqmNegatedPredicate) ExistsPredicate(org.hibernate.sql.ast.tree.predicate.ExistsPredicate) SqmAndPredicate(org.hibernate.query.sqm.tree.predicate.SqmAndPredicate) SqmMemberOfPredicate(org.hibernate.query.sqm.tree.predicate.SqmMemberOfPredicate) SqmLikePredicate(org.hibernate.query.sqm.tree.predicate.SqmLikePredicate) SqmExistsPredicate(org.hibernate.query.sqm.tree.predicate.SqmExistsPredicate) SqmOrPredicate(org.hibernate.query.sqm.tree.predicate.SqmOrPredicate) SqmNullnessPredicate(org.hibernate.query.sqm.tree.predicate.SqmNullnessPredicate) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) SqmGroupedPredicate(org.hibernate.query.sqm.tree.predicate.SqmGroupedPredicate) SqmInListPredicate(org.hibernate.query.sqm.tree.predicate.SqmInListPredicate) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate) NullnessPredicate(org.hibernate.sql.ast.tree.predicate.NullnessPredicate) SqmBetweenPredicate(org.hibernate.query.sqm.tree.predicate.SqmBetweenPredicate) GroupedPredicate(org.hibernate.sql.ast.tree.predicate.GroupedPredicate) BooleanExpressionPredicate(org.hibernate.sql.ast.tree.predicate.BooleanExpressionPredicate) InListPredicate(org.hibernate.sql.ast.tree.predicate.InListPredicate) SqmInSubQueryPredicate(org.hibernate.query.sqm.tree.predicate.SqmInSubQueryPredicate) SqmEmptinessPredicate(org.hibernate.query.sqm.tree.predicate.SqmEmptinessPredicate) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate)

Example 17 with Predicate

use of org.hibernate.sql.ast.tree.predicate.Predicate in project hibernate-orm by hibernate.

the class RestrictedDeleteExecutionDelegate method execute.

@Override
public int execute(DomainQueryExecutionContext executionContext) {
    final EntityPersister entityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(sqmDelete.getTarget().getEntityName());
    final String hierarchyRootTableName = ((Joinable) entityDescriptor).getTableName();
    final TableGroup deletingTableGroup = converter.getMutatingTableGroup();
    final TableReference hierarchyRootTableReference = deletingTableGroup.resolveTableReference(deletingTableGroup.getNavigablePath(), hierarchyRootTableName);
    assert hierarchyRootTableReference != null;
    final Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions;
    final Map<SqmParameter<?>, MappingModelExpressible<?>> paramTypeResolutions;
    if (domainParameterXref.getSqmParameterCount() == 0) {
        parameterResolutions = Collections.emptyMap();
        paramTypeResolutions = Collections.emptyMap();
    } else {
        parameterResolutions = new IdentityHashMap<>();
        paramTypeResolutions = new LinkedHashMap<>();
    }
    // Use the converter to interpret the where-clause.  We do this for 2 reasons:
    // 1) the resolved Predicate is ultimately the base for applying restriction to the deletes
    // 2) we also inspect each ColumnReference that is part of the where-clause to see which
    // table it comes from.  if all of the referenced columns (if any at all) are from the root table
    // we can perform all of the deletes without using an id-table
    final MutableBoolean needsIdTableWrapper = new MutableBoolean(false);
    final Predicate specifiedRestriction = converter.visitWhereClause(sqmDelete.getWhereClause(), columnReference -> {
        if (!hierarchyRootTableReference.getIdentificationVariable().equals(columnReference.getQualifier())) {
            needsIdTableWrapper.setValue(true);
        }
    }, (sqmParameter, mappingType, jdbcParameters) -> {
        parameterResolutions.computeIfAbsent(sqmParameter, k -> new ArrayList<>(1)).add(jdbcParameters);
        paramTypeResolutions.put(sqmParameter, mappingType);
    });
    final PredicateCollector predicateCollector = new PredicateCollector(specifiedRestriction);
    entityDescriptor.applyBaseRestrictions((filterPredicate) -> {
        needsIdTableWrapper.setValue(true);
        predicateCollector.applyPredicate(filterPredicate);
    }, deletingTableGroup, true, executionContext.getSession().getLoadQueryInfluencers().getEnabledFilters(), null, converter);
    converter.pruneTableGroupJoins();
    // We need an id table if we want to delete from an intermediate table to avoid FK violations
    // The intermediate table has a FK to the root table, so we can't delete from the root table first
    // Deleting from the intermediate table first also isn't possible,
    // because that is the source for deletion in other tables, hence we need an id table
    final boolean needsIdTable = needsIdTableWrapper.getValue() || entityDescriptor != entityDescriptor.getRootEntityDescriptor();
    final SqmJdbcExecutionContextAdapter executionContextAdapter = SqmJdbcExecutionContextAdapter.omittingLockingAndPaging(executionContext);
    if (needsIdTable) {
        return executeWithIdTable(predicateCollector.getPredicate(), deletingTableGroup, parameterResolutions, paramTypeResolutions, executionContextAdapter);
    } else {
        return executeWithoutIdTable(predicateCollector.getPredicate(), deletingTableGroup, parameterResolutions, paramTypeResolutions, converter.getSqlExpressionResolver(), executionContextAdapter);
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) ExecutionContext(org.hibernate.sql.exec.spi.ExecutionContext) EntityPersister(org.hibernate.persister.entity.EntityPersister) PredicateCollector(org.hibernate.sql.ast.tree.predicate.PredicateCollector) Joinable(org.hibernate.persister.entity.Joinable) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) MappingModelHelper(org.hibernate.metamodel.mapping.MappingModelHelper) SqmJdbcExecutionContextAdapter(org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter) ForeignKeyDescriptor(org.hibernate.metamodel.mapping.ForeignKeyDescriptor) SqmUtil(org.hibernate.query.sqm.internal.SqmUtil) Map(java.util.Map) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) MutableBoolean(org.hibernate.internal.util.MutableBoolean) InSubQueryPredicate(org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate) SqmDeleteStatement(org.hibernate.query.sqm.tree.delete.SqmDeleteStatement) IdentityHashMap(java.util.IdentityHashMap) Expression(org.hibernate.sql.ast.tree.expression.Expression) SqlExpressionResolver(org.hibernate.sql.ast.spi.SqlExpressionResolver) EntityIdentifierMapping(org.hibernate.metamodel.mapping.EntityIdentifierMapping) LoadQueryInfluencers(org.hibernate.engine.spi.LoadQueryInfluencers) List(java.util.List) SqmMutationStrategyHelper(org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) SqmParameter(org.hibernate.query.sqm.tree.expression.SqmParameter) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) SelectableConsumer(org.hibernate.metamodel.mapping.SelectableConsumer) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) QueryOptions(org.hibernate.query.spi.QueryOptions) Logger(org.jboss.logging.Logger) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) JdbcParameterBindings(org.hibernate.sql.exec.spi.JdbcParameterBindings) ArrayList(java.util.ArrayList) TableReference(org.hibernate.sql.ast.tree.from.TableReference) LinkedHashMap(java.util.LinkedHashMap) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) MultiTableSqmMutationConverter(org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter) SqmParameterMappingModelResolutionAccess(org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess) UnionTableReference(org.hibernate.sql.ast.tree.from.UnionTableReference) TemporaryTable(org.hibernate.dialect.temptable.TemporaryTable) DeleteStatement(org.hibernate.sql.ast.tree.delete.DeleteStatement) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) MutableInteger(org.hibernate.internal.util.MutableInteger) QueryParameterBindings(org.hibernate.query.spi.QueryParameterBindings) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) JdbcDelete(org.hibernate.sql.exec.spi.JdbcDelete) DomainQueryExecutionContext(org.hibernate.query.spi.DomainQueryExecutionContext) Consumer(java.util.function.Consumer) JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) DomainParameterXref(org.hibernate.query.sqm.internal.DomainParameterXref) Collections(java.util.Collections) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) MutableBoolean(org.hibernate.internal.util.MutableBoolean) ArrayList(java.util.ArrayList) SqmJdbcExecutionContextAdapter(org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter) InSubQueryPredicate(org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) TableReference(org.hibernate.sql.ast.tree.from.TableReference) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) UnionTableReference(org.hibernate.sql.ast.tree.from.UnionTableReference) PredicateCollector(org.hibernate.sql.ast.tree.predicate.PredicateCollector) Joinable(org.hibernate.persister.entity.Joinable) List(java.util.List) ArrayList(java.util.ArrayList) SqmParameter(org.hibernate.query.sqm.tree.expression.SqmParameter)

Example 18 with Predicate

use of org.hibernate.sql.ast.tree.predicate.Predicate in project hibernate-orm by hibernate.

the class TableBasedUpdateHandler method resolveDelegate.

private ExecutionDelegate resolveDelegate(DomainQueryExecutionContext executionContext) {
    final SessionFactoryImplementor sessionFactory = getSessionFactory();
    final MappingMetamodel domainModel = sessionFactory.getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = domainModel.getEntityDescriptor(getSqmDeleteOrUpdateStatement().getTarget().getEntityName());
    final String rootEntityName = entityDescriptor.getRootEntityName();
    final EntityPersister rootEntityDescriptor = domainModel.getEntityDescriptor(rootEntityName);
    final String hierarchyRootTableName = ((Joinable) rootEntityDescriptor).getTableName();
    final MultiTableSqmMutationConverter converterDelegate = new MultiTableSqmMutationConverter(entityDescriptor, getSqmDeleteOrUpdateStatement(), getSqmDeleteOrUpdateStatement().getTarget(), domainParameterXref, executionContext.getQueryOptions(), executionContext.getSession().getLoadQueryInfluencers(), executionContext.getQueryParameterBindings(), sessionFactory);
    final TableGroup updatingTableGroup = converterDelegate.getMutatingTableGroup();
    final TableReference hierarchyRootTableReference = updatingTableGroup.resolveTableReference(updatingTableGroup.getNavigablePath(), hierarchyRootTableName);
    assert hierarchyRootTableReference != null;
    final Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions;
    if (domainParameterXref.getSqmParameterCount() == 0) {
        parameterResolutions = Collections.emptyMap();
    } else {
        parameterResolutions = new IdentityHashMap<>();
    }
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // visit the set-clause using our special converter, collecting
    // information about the assignments
    final List<Assignment> assignments = new ArrayList<>();
    final Map<SqmParameter<?>, MappingModelExpressible<?>> paramTypeResolutions = new LinkedHashMap<>();
    converterDelegate.visitSetClause(getSqmDeleteOrUpdateStatement().getSetClause(), assignments::add, (sqmParameter, mappingType, jdbcParameters) -> {
        parameterResolutions.computeIfAbsent(sqmParameter, k -> new ArrayList<>(1)).add(jdbcParameters);
        paramTypeResolutions.put(sqmParameter, mappingType);
    });
    converterDelegate.addVersionedAssignment(assignments::add, getSqmDeleteOrUpdateStatement());
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // visit the where-clause using our special converter, collecting information
    // about the restrictions
    final Predicate providedPredicate;
    final SqmWhereClause whereClause = getSqmUpdate().getWhereClause();
    if (whereClause == null || whereClause.getPredicate() == null) {
        providedPredicate = null;
    } else {
        providedPredicate = converterDelegate.visitWhereClause(whereClause, columnReference -> {
        }, (sqmParameter, mappingType, jdbcParameters) -> {
            parameterResolutions.computeIfAbsent(sqmParameter, k -> new ArrayList<>(1)).add(jdbcParameters);
            paramTypeResolutions.put(sqmParameter, mappingType);
        });
        assert providedPredicate != null;
    }
    final PredicateCollector predicateCollector = new PredicateCollector(providedPredicate);
    entityDescriptor.applyBaseRestrictions(predicateCollector::applyPredicate, updatingTableGroup, true, executionContext.getSession().getLoadQueryInfluencers().getEnabledFilters(), null, converterDelegate);
    converterDelegate.pruneTableGroupJoins();
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // cross-reference the TableReference by alias.  The TableGroup already
    // cross-references it by name, bu the ColumnReference only has the alias
    final Map<String, TableReference> tableReferenceByAlias = CollectionHelper.mapOfSize(updatingTableGroup.getTableReferenceJoins().size() + 1);
    collectTableReference(updatingTableGroup.getPrimaryTableReference(), tableReferenceByAlias::put);
    for (int i = 0; i < updatingTableGroup.getTableReferenceJoins().size(); i++) {
        collectTableReference(updatingTableGroup.getTableReferenceJoins().get(i), tableReferenceByAlias::put);
    }
    return new UpdateExecutionDelegate(getSqmUpdate(), converterDelegate, idTable, afterUseAction, sessionUidAccess, domainParameterXref, updatingTableGroup, hierarchyRootTableReference, tableReferenceByAlias, assignments, predicateCollector.getPredicate(), parameterResolutions, paramTypeResolutions, executionContext);
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) CollectionHelper(org.hibernate.internal.util.collections.CollectionHelper) ExecutionContext(org.hibernate.sql.exec.spi.ExecutionContext) EntityPersister(org.hibernate.persister.entity.EntityPersister) PredicateCollector(org.hibernate.sql.ast.tree.predicate.PredicateCollector) Logger(org.jboss.logging.Logger) Function(java.util.function.Function) Joinable(org.hibernate.persister.entity.Joinable) ArrayList(java.util.ArrayList) SqmJdbcExecutionContextAdapter(org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter) TableReference(org.hibernate.sql.ast.tree.from.TableReference) LinkedHashMap(java.util.LinkedHashMap) MultiTableSqmMutationConverter(org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) SqmUpdateStatement(org.hibernate.query.sqm.tree.update.SqmUpdateStatement) TableReferenceJoin(org.hibernate.sql.ast.tree.from.TableReferenceJoin) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Assignment(org.hibernate.sql.ast.tree.update.Assignment) IdentityHashMap(java.util.IdentityHashMap) TemporaryTable(org.hibernate.dialect.temptable.TemporaryTable) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) DomainQueryExecutionContext(org.hibernate.query.spi.DomainQueryExecutionContext) MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) List(java.util.List) JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) SqmWhereClause(org.hibernate.query.sqm.tree.predicate.SqmWhereClause) UpdateHandler(org.hibernate.query.sqm.mutation.internal.UpdateHandler) SqmParameter(org.hibernate.query.sqm.tree.expression.SqmParameter) AbstractMutationHandler(org.hibernate.query.sqm.mutation.spi.AbstractMutationHandler) DomainParameterXref(org.hibernate.query.sqm.internal.DomainParameterXref) Collections(java.util.Collections) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) MappingModelExpressible(org.hibernate.metamodel.mapping.MappingModelExpressible) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) Assignment(org.hibernate.sql.ast.tree.update.Assignment) TableReference(org.hibernate.sql.ast.tree.from.TableReference) ArrayList(java.util.ArrayList) List(java.util.List) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) JdbcParameter(org.hibernate.sql.ast.tree.expression.JdbcParameter) MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) PredicateCollector(org.hibernate.sql.ast.tree.predicate.PredicateCollector) Joinable(org.hibernate.persister.entity.Joinable) SqmWhereClause(org.hibernate.query.sqm.tree.predicate.SqmWhereClause) SqmParameter(org.hibernate.query.sqm.tree.expression.SqmParameter) MultiTableSqmMutationConverter(org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter)

Example 19 with Predicate

use of org.hibernate.sql.ast.tree.predicate.Predicate in project hibernate-orm by hibernate.

the class SQLServerSqlAstTranslator method renderTableGroupJoin.

@Override
protected void renderTableGroupJoin(TableGroupJoin tableGroupJoin, List<TableGroupJoin> tableGroupJoinCollector) {
    appendSql(WHITESPACE);
    if (tableGroupJoin.getJoinedGroup().isLateral()) {
        if (tableGroupJoin.getJoinType() == SqlAstJoinType.LEFT) {
            appendSql("outer apply ");
        } else {
            appendSql("cross apply ");
        }
    } else {
        appendSql(tableGroupJoin.getJoinType().getText());
        appendSql("join ");
    }
    final Predicate predicate = tableGroupJoin.getPredicate();
    if (predicate != null && !predicate.isEmpty()) {
        if (tableGroupJoin.getJoinedGroup().isLateral()) {
            // We have to inject the lateral predicate into the sub-query
            final Predicate lateralPredicate = this.lateralPredicate;
            this.lateralPredicate = predicate;
            renderTableGroup(tableGroupJoin.getJoinedGroup(), null, tableGroupJoinCollector);
            this.lateralPredicate = lateralPredicate;
        } else {
            renderTableGroup(tableGroupJoin.getJoinedGroup(), predicate, tableGroupJoinCollector);
        }
    } else {
        renderTableGroup(tableGroupJoin.getJoinedGroup(), null, tableGroupJoinCollector);
    }
}
Also used : Predicate(org.hibernate.sql.ast.tree.predicate.Predicate)

Example 20 with Predicate

use of org.hibernate.sql.ast.tree.predicate.Predicate in project hibernate-orm by hibernate.

the class TimesTenSqlAstTranslator method renderTableGroupJoin.

@Override
protected void renderTableGroupJoin(TableGroupJoin tableGroupJoin, List<TableGroupJoin> tableGroupJoinCollector) {
    if (tableGroupJoin.getJoinType() == SqlAstJoinType.CROSS) {
        appendSql(", ");
    } else {
        appendSql(WHITESPACE);
        appendSql(tableGroupJoin.getJoinType().getText());
        appendSql("join ");
    }
    final Predicate predicate;
    if (tableGroupJoin.getPredicate() == null) {
        if (tableGroupJoin.getJoinType() == SqlAstJoinType.CROSS) {
            predicate = null;
        } else {
            predicate = new BooleanExpressionPredicate(new QueryLiteral<>(true, getBooleanType()));
        }
    } else {
        predicate = tableGroupJoin.getPredicate();
    }
    if (predicate != null && !predicate.isEmpty()) {
        renderTableGroup(tableGroupJoin.getJoinedGroup(), predicate, tableGroupJoinCollector);
    } else {
        renderTableGroup(tableGroupJoin.getJoinedGroup(), null, tableGroupJoinCollector);
    }
}
Also used : QueryLiteral(org.hibernate.sql.ast.tree.expression.QueryLiteral) BooleanExpressionPredicate(org.hibernate.sql.ast.tree.predicate.BooleanExpressionPredicate) Predicate(org.hibernate.sql.ast.tree.predicate.Predicate) BooleanExpressionPredicate(org.hibernate.sql.ast.tree.predicate.BooleanExpressionPredicate)

Aggregations

Predicate (org.hibernate.sql.ast.tree.predicate.Predicate)40 ComparisonPredicate (org.hibernate.sql.ast.tree.predicate.ComparisonPredicate)25 InSubQueryPredicate (org.hibernate.sql.ast.tree.predicate.InSubQueryPredicate)24 NullnessPredicate (org.hibernate.sql.ast.tree.predicate.NullnessPredicate)24 BooleanExpressionPredicate (org.hibernate.sql.ast.tree.predicate.BooleanExpressionPredicate)23 InListPredicate (org.hibernate.sql.ast.tree.predicate.InListPredicate)23 NegatedPredicate (org.hibernate.sql.ast.tree.predicate.NegatedPredicate)23 BetweenPredicate (org.hibernate.sql.ast.tree.predicate.BetweenPredicate)21 ExistsPredicate (org.hibernate.sql.ast.tree.predicate.ExistsPredicate)21 GroupedPredicate (org.hibernate.sql.ast.tree.predicate.GroupedPredicate)21 LikePredicate (org.hibernate.sql.ast.tree.predicate.LikePredicate)21 SelfRenderingPredicate (org.hibernate.sql.ast.tree.predicate.SelfRenderingPredicate)21 ArrayList (java.util.ArrayList)14 SqmPredicate (org.hibernate.query.sqm.tree.predicate.SqmPredicate)14 Expression (org.hibernate.sql.ast.tree.expression.Expression)14 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)12 SqmAndPredicate (org.hibernate.query.sqm.tree.predicate.SqmAndPredicate)12 SqmBetweenPredicate (org.hibernate.query.sqm.tree.predicate.SqmBetweenPredicate)12 SqmBooleanExpressionPredicate (org.hibernate.query.sqm.tree.predicate.SqmBooleanExpressionPredicate)12 SqmComparisonPredicate (org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate)12