use of org.hibernate.sql.ast.tree.update.UpdateStatement in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method visitUpdateStatement.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Update statement
@Override
public UpdateStatement visitUpdateStatement(SqmUpdateStatement<?> sqmStatement) {
final CteContainer cteContainer = this.visitCteContainer(sqmStatement);
final SqmRoot<?> sqmTarget = sqmStatement.getTarget();
final String entityName = sqmTarget.getEntityName();
final EntityPersister entityDescriptor = getCreationContext().getSessionFactory().getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(entityName);
assert entityDescriptor != null;
pushProcessingState(new SqlAstProcessingStateImpl(getCurrentProcessingState(), this, getCurrentClauseStack()::getCurrent));
try {
final NavigablePath rootPath = sqmTarget.getNavigablePath();
final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup(true, rootPath, sqmStatement.getRoot().getAlias(), () -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates(additionalRestrictions, predicate), this, getCreationContext());
if (!rootTableGroup.getTableReferenceJoins().isEmpty()) {
throw new HibernateException("Not expecting multiple table references for an SQM UPDATE");
}
if (sqmTarget.hasJoins()) {
throw new HibernateException("SQM UPDATE does not support explicit joins");
}
getFromClauseAccess().registerTableGroup(rootPath, rootTableGroup);
final List<Assignment> assignments = visitSetClause(sqmStatement.getSetClause());
addVersionedAssignment(assignments::add, sqmStatement);
FilterHelper.applyBaseRestrictions((filterPredicate) -> additionalRestrictions = filterPredicate, entityDescriptor, rootTableGroup, AbstractSqlAstTranslator.rendersTableReferenceAlias(Clause.UPDATE), getLoadQueryInfluencers(), this);
Predicate suppliedPredicate = null;
final SqmWhereClause whereClause = sqmStatement.getWhereClause();
if (whereClause != null) {
suppliedPredicate = visitWhereClause(whereClause.getPredicate());
}
return new UpdateStatement(cteContainer, (NamedTableReference) rootTableGroup.getPrimaryTableReference(), assignments, SqlAstTreeHelper.combinePredicates(suppliedPredicate, additionalRestrictions), Collections.emptyList());
} finally {
popProcessingStateStack();
}
}
use of org.hibernate.sql.ast.tree.update.UpdateStatement in project hibernate-orm by hibernate.
the class SqlTreePrinter method visitStatement.
private void visitStatement(Statement sqlAstStatement) {
if (sqlAstStatement instanceof SelectStatement) {
final SelectStatement selectStatement = (SelectStatement) sqlAstStatement;
logNode("SelectStatement", () -> visitQueryPart(selectStatement.getQueryPart()));
} else if (sqlAstStatement instanceof DeleteStatement) {
final DeleteStatement deleteStatement = (DeleteStatement) sqlAstStatement;
logNode("DeleteStatement", () -> logWithIndentation("target : " + deleteStatement.getTargetTable().getTableExpression()));
} else if (sqlAstStatement instanceof UpdateStatement) {
final UpdateStatement updateStatement = (UpdateStatement) sqlAstStatement;
logNode("UpdateStatement", () -> logWithIndentation("target : " + updateStatement.getTargetTable().getTableExpression()));
} else if (sqlAstStatement instanceof InsertStatement) {
final InsertStatement insertStatement = (InsertStatement) sqlAstStatement;
logNode("InsertStatement", () -> logWithIndentation("target : " + insertStatement.getTargetTable().getTableExpression()));
} else {
throw new UnsupportedOperationException("Printing for this type of SQL AST not supported : " + sqlAstStatement);
}
}
Aggregations