Search in sources :

Example 1 with DiscriminatedAssociationModelPart

use of org.hibernate.metamodel.mapping.DiscriminatedAssociationModelPart in project hibernate-orm by hibernate.

the class DiscriminatedAssociationPathInterpretation method from.

public static <T> DiscriminatedAssociationPathInterpretation<T> from(SqmAnyValuedSimplePath<T> sqmPath, SqmToSqlAstConverter converter) {
    final TableGroup tableGroup = converter.getFromClauseAccess().findTableGroup(sqmPath.getLhs().getNavigablePath());
    final DiscriminatedAssociationModelPart mapping = (DiscriminatedAssociationModelPart) tableGroup.getModelPart().findSubPart(sqmPath.getReferencedPathSource().getPathName(), null);
    final List<Expression> tupleExpressions = new ArrayList<>();
    mapping.forEachSelectable((selectionIndex, selectableMapping) -> {
        final TableReference tableReference = tableGroup.resolveTableReference(sqmPath.getNavigablePath(), selectableMapping.getContainingTableExpression());
        final Expression expression = converter.getSqlExpressionResolver().resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, selectableMapping.getSelectionExpression()), processingState -> new ColumnReference(tableReference, selectableMapping, converter.getCreationContext().getSessionFactory()));
        tupleExpressions.add(expression);
    });
    return new DiscriminatedAssociationPathInterpretation<T>(sqmPath.getNavigablePath(), mapping, tableGroup, new SqlTuple(tupleExpressions, mapping));
}
Also used : TableReference(org.hibernate.sql.ast.tree.from.TableReference) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) Expression(org.hibernate.sql.ast.tree.expression.Expression) ArrayList(java.util.ArrayList) SqlTuple(org.hibernate.sql.ast.tree.expression.SqlTuple) DiscriminatedAssociationModelPart(org.hibernate.metamodel.mapping.DiscriminatedAssociationModelPart) ColumnReference(org.hibernate.sql.ast.tree.expression.ColumnReference)

Aggregations

ArrayList (java.util.ArrayList)1 DiscriminatedAssociationModelPart (org.hibernate.metamodel.mapping.DiscriminatedAssociationModelPart)1 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)1 Expression (org.hibernate.sql.ast.tree.expression.Expression)1 SqlTuple (org.hibernate.sql.ast.tree.expression.SqlTuple)1 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)1 TableReference (org.hibernate.sql.ast.tree.from.TableReference)1