use of org.hibernate.sql.ast.tree.expression.ColumnReference in project hibernate-orm by hibernate.
the class EmbeddedCollectionPart method toSqlExpression.
@Override
public SqlTuple toSqlExpression(TableGroup tableGroup, Clause clause, SqmToSqlAstConverter walker, SqlAstCreationState sqlAstCreationState) {
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final List<Expression> expressions = new ArrayList<>();
getEmbeddableTypeDescriptor().forEachSelectable((columnIndex, selection) -> {
assert containingTableExpression.equals(selection.getContainingTableExpression());
final TableReference tableReference = tableGroup.resolveTableReference(tableGroup.getNavigablePath().append(getNavigableRole().getNavigableName()), selection.getContainingTableExpression());
expressions.add(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, selection.getSelectionExpression()), sqlAstProcessingState -> new ColumnReference(tableReference, selection, sqlAstCreationState.getCreationContext().getSessionFactory())));
});
return new SqlTuple(expressions, this);
}
use of org.hibernate.sql.ast.tree.expression.ColumnReference in project hibernate-orm by hibernate.
the class EmbeddedForeignKeyDescriptor method isSimpleJoinPredicate.
@Override
public boolean isSimpleJoinPredicate(Predicate predicate) {
if (!(predicate instanceof Junction)) {
return false;
}
final Junction junction = (Junction) predicate;
if (junction.getNature() != Junction.Nature.CONJUNCTION) {
return false;
}
final List<Predicate> predicates = junction.getPredicates();
if (predicates.size() != keySelectableMappings.getJdbcTypeCount()) {
return false;
}
Boolean lhsIsKey = null;
for (int i = 0; i < predicates.size(); i++) {
final Predicate p = predicates.get(i);
if (!(p instanceof ComparisonPredicate)) {
return false;
}
final ComparisonPredicate comparisonPredicate = (ComparisonPredicate) p;
if (comparisonPredicate.getOperator() != ComparisonOperator.EQUAL) {
return false;
}
final Expression lhsExpr = comparisonPredicate.getLeftHandExpression();
final Expression rhsExpr = comparisonPredicate.getRightHandExpression();
if (!(lhsExpr instanceof ColumnReference) || !(rhsExpr instanceof ColumnReference)) {
return false;
}
final ColumnReference lhs = (ColumnReference) lhsExpr;
final ColumnReference rhs = (ColumnReference) rhsExpr;
if (lhsIsKey == null) {
final String keyExpression = keySelectableMappings.getSelectable(i).getSelectionExpression();
final String targetExpression = targetSelectableMappings.getSelectable(i).getSelectionExpression();
if (keyExpression.equals(targetExpression)) {
if (!lhs.getColumnExpression().equals(keyExpression) || !rhs.getColumnExpression().equals(keyExpression)) {
return false;
}
} else {
if (keyExpression.equals(lhs.getColumnExpression())) {
if (!targetExpression.equals(rhs.getColumnExpression())) {
return false;
}
lhsIsKey = true;
} else if (keyExpression.equals(rhs.getColumnExpression())) {
if (!targetExpression.equals(lhs.getColumnExpression())) {
return false;
}
lhsIsKey = false;
} else {
return false;
}
}
} else {
final String lhsSelectionExpression;
final String rhsSelectionExpression;
if (lhsIsKey) {
lhsSelectionExpression = keySelectableMappings.getSelectable(i).getSelectionExpression();
rhsSelectionExpression = targetSelectableMappings.getSelectable(i).getSelectionExpression();
} else {
lhsSelectionExpression = targetSelectableMappings.getSelectable(i).getSelectionExpression();
rhsSelectionExpression = keySelectableMappings.getSelectable(i).getSelectionExpression();
}
if (!lhs.getColumnExpression().equals(lhsSelectionExpression) || !rhs.getColumnExpression().equals(rhsSelectionExpression)) {
return false;
}
}
}
return true;
}
use of org.hibernate.sql.ast.tree.expression.ColumnReference in project hibernate-orm by hibernate.
the class EntityVersionMappingImpl method resolveSqlSelection.
private SqlSelection resolveSqlSelection(TableGroup tableGroup, DomainResultCreationState creationState) {
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final TableReference columnTableReference = tableGroup.resolveTableReference(tableGroup.getNavigablePath().append(getNavigableRole().getNavigableName()), columnTableExpression);
return sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(columnTableReference, columnExpression), sqlAstProcessingState -> new ColumnReference(columnTableReference, columnExpression, false, null, null, versionBasicType, sqlAstCreationState.getCreationContext().getSessionFactory())), versionBasicType.getJdbcMapping().getJavaTypeDescriptor(), sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration());
}
use of org.hibernate.sql.ast.tree.expression.ColumnReference in project hibernate-orm by hibernate.
the class EntityVersionMappingImpl method generateFetch.
@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
final TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().findTableGroup(fetchParent.getNavigablePath());
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final TableReference columnTableReference = tableGroup.resolveTableReference(fetchablePath, columnTableExpression);
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(sqlExpressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(columnTableReference, columnExpression), sqlAstProcessingState -> new ColumnReference(columnTableReference, columnExpression, false, null, null, versionBasicType, sqlAstCreationState.getCreationContext().getSessionFactory())), versionBasicType.getJdbcMapping().getJavaTypeDescriptor(), sqlAstCreationState.getCreationContext().getSessionFactory().getTypeConfiguration());
return new BasicFetch<>(sqlSelection.getValuesArrayPosition(), fetchParent, fetchablePath, this, null, fetchTiming, creationState);
}
use of org.hibernate.sql.ast.tree.expression.ColumnReference in project hibernate-orm by hibernate.
the class ExplicitColumnDiscriminatorMappingImpl method resolveSqlExpression.
@Override
public Expression resolveSqlExpression(NavigablePath navigablePath, JdbcMapping jdbcMappingToUse, TableGroup tableGroup, SqlAstCreationState creationState) {
final SqlExpressionResolver expressionResolver = creationState.getSqlExpressionResolver();
final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, tableExpression);
final String selectionExpression = getSelectionExpression();
return expressionResolver.resolveSqlExpression(createColumnReferenceKey(tableReference, selectionExpression), sqlAstProcessingState -> new ColumnReference(tableReference, selectionExpression, columnFormula != null, null, null, jdbcMappingToUse, getSessionFactory()));
}
Aggregations