use of org.hibernate.query.sqm.tree.update.SqmAssignment in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method visitSetClause.
@Override
public List<Assignment> visitSetClause(SqmSetClause setClause) {
final List<Assignment> assignments = new ArrayList<>(setClause.getAssignments().size());
for (SqmAssignment sqmAssignment : setClause.getAssignments()) {
final List<ColumnReference> targetColumnReferences = new ArrayList<>();
pushProcessingState(new SqlAstProcessingStateImpl(getCurrentProcessingState(), this, getCurrentClauseStack()::getCurrent) {
@Override
public Expression resolveSqlExpression(String key, Function<SqlAstProcessingState, Expression> creator) {
final Expression expression = getParentState().getSqlExpressionResolver().resolveSqlExpression(key, creator);
assert expression instanceof ColumnReference;
targetColumnReferences.add((ColumnReference) expression);
return expression;
}
}, getFromClauseIndex());
final SqmPathInterpretation<?> assignedPathInterpretation;
try {
assignedPathInterpretation = (SqmPathInterpretation<?>) sqmAssignment.getTargetPath().accept(this);
} finally {
popProcessingStateStack();
}
inferrableTypeAccessStack.push(assignedPathInterpretation::getExpressionType);
// final List<ColumnReference> valueColumnReferences = new ArrayList<>();
pushProcessingState(new SqlAstProcessingStateImpl(getCurrentProcessingState(), this, getCurrentClauseStack()::getCurrent) {
@Override
public Expression resolveSqlExpression(String key, Function<SqlAstProcessingState, Expression> creator) {
final Expression expression = getParentState().getSqlExpressionResolver().resolveSqlExpression(key, creator);
assert expression instanceof ColumnReference;
// valueColumnReferences.add( (ColumnReference) expression );
return expression;
}
}, getFromClauseIndex());
try {
final SqmExpression<?> assignmentValue = sqmAssignment.getValue();
final SqmParameter<?> assignmentValueParameter = getSqmParameter(assignmentValue);
if (assignmentValueParameter != null) {
consumeSqmParameter(assignmentValueParameter, assignedPathInterpretation.getExpressionType(), (index, jdbcParameter) -> assignments.add(new Assignment(targetColumnReferences.get(index), jdbcParameter)));
} else {
final Expression valueExpression = (Expression) assignmentValue.accept(this);
final int valueExprJdbcCount = getKeyExpressible(valueExpression.getExpressionType()).getJdbcTypeCount();
final int assignedPathJdbcCount = getKeyExpressible(assignedPathInterpretation.getExpressionType()).getJdbcTypeCount();
if (valueExprJdbcCount != assignedPathJdbcCount) {
SqlTreeCreationLogger.LOGGER.debugf("JDBC type count does not match in UPDATE assignment between the assigned-path and the assigned-value; " + "this will likely lead to problems executing the query");
}
assert assignedPathJdbcCount == valueExprJdbcCount;
for (ColumnReference columnReference : targetColumnReferences) {
assignments.add(new Assignment(columnReference, valueExpression));
}
}
} finally {
popProcessingStateStack();
inferrableTypeAccessStack.pop();
}
}
return assignments;
}
Aggregations