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);
}
}
Aggregations