Search in sources :

Example 1 with DiscriminatorSqmPath

use of org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath in project hibernate-orm by hibernate.

the class BaseSqmToSqlAstConverter method createTreatTypeRestriction.

private Predicate createTreatTypeRestriction(SqmPath<?> lhs, Set<String> subclassEntityNames) {
    final MappingMetamodel domainModel = creationContext.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    // Do what visitSelfInterpretingSqmPath does, except for calling preparingReusablePath
    // as that would register a type usage for the table group that we don't want here
    final DiscriminatorSqmPath discriminatorSqmPath = (DiscriminatorSqmPath) lhs.type();
    registerTypeUsage(discriminatorSqmPath);
    final Expression typeExpression = discriminatorSqmPath.interpret(this, this, jpaQueryComplianceEnabled);
    if (subclassEntityNames.size() == 1) {
        return new ComparisonPredicate(typeExpression, ComparisonOperator.EQUAL, new EntityTypeLiteral(domainModel.findEntityDescriptor(subclassEntityNames.iterator().next())));
    } else {
        final List<Expression> typeLiterals = new ArrayList<>(subclassEntityNames.size());
        for (String subclassEntityName : subclassEntityNames) {
            typeLiterals.add(new EntityTypeLiteral(domainModel.findEntityDescriptor(subclassEntityName)));
        }
        return new InListPredicate(typeExpression, typeLiterals);
    }
}
Also used : MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) EntityTypeLiteral(org.hibernate.sql.ast.tree.expression.EntityTypeLiteral) DiscriminatorSqmPath(org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath) 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) ArrayList(java.util.ArrayList) SqmInListPredicate(org.hibernate.query.sqm.tree.predicate.SqmInListPredicate) InListPredicate(org.hibernate.sql.ast.tree.predicate.InListPredicate) SqmComparisonPredicate(org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate)

Aggregations

ArrayList (java.util.ArrayList)1 MappingMetamodel (org.hibernate.metamodel.MappingMetamodel)1 DiscriminatorSqmPath (org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath)1 SelfRenderingAggregateFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingAggregateFunctionSqlAstExpression)1 SelfRenderingFunctionSqlAstExpression (org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression)1 SqmExpression (org.hibernate.query.sqm.tree.expression.SqmExpression)1 SqmModifiedSubQueryExpression (org.hibernate.query.sqm.tree.expression.SqmModifiedSubQueryExpression)1 SqmComparisonPredicate (org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate)1 SqmInListPredicate (org.hibernate.query.sqm.tree.predicate.SqmInListPredicate)1 BinaryArithmeticExpression (org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression)1 CaseSearchedExpression (org.hibernate.sql.ast.tree.expression.CaseSearchedExpression)1 CaseSimpleExpression (org.hibernate.sql.ast.tree.expression.CaseSimpleExpression)1 EntityTypeLiteral (org.hibernate.sql.ast.tree.expression.EntityTypeLiteral)1 Expression (org.hibernate.sql.ast.tree.expression.Expression)1 ModifiedSubQueryExpression (org.hibernate.sql.ast.tree.expression.ModifiedSubQueryExpression)1 SelfRenderingExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingExpression)1 SelfRenderingSqlFragmentExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingSqlFragmentExpression)1 SqlSelectionExpression (org.hibernate.sql.ast.tree.expression.SqlSelectionExpression)1 ComparisonPredicate (org.hibernate.sql.ast.tree.predicate.ComparisonPredicate)1 InListPredicate (org.hibernate.sql.ast.tree.predicate.InListPredicate)1