use of org.hibernate.query.sqm.tree.delete.SqmDeleteStatement in project hibernate-orm by hibernate.
the class SemanticQueryBuilder method visitDeleteStatement.
@Override
public SqmDeleteStatement<R> visitDeleteStatement(HqlParser.DeleteStatementContext ctx) {
final int dmlTargetIndex;
if (ctx.getChild(1) instanceof HqlParser.TargetEntityContext) {
dmlTargetIndex = 1;
} else {
dmlTargetIndex = 2;
}
final HqlParser.TargetEntityContext dmlTargetContext = (HqlParser.TargetEntityContext) ctx.getChild(dmlTargetIndex);
final SqmRoot<R> root = visitTargetEntity(dmlTargetContext);
final SqmDeleteStatement<R> deleteStatement = new SqmDeleteStatement<>(root, SqmQuerySource.HQL, creationContext.getNodeBuilder());
parameterCollector = deleteStatement;
final SqmDmlCreationProcessingState sqmDeleteCreationState = new SqmDmlCreationProcessingState(deleteStatement, this);
sqmDeleteCreationState.getPathRegistry().register(root);
processingStateStack.push(sqmDeleteCreationState);
try {
if (dmlTargetIndex + 1 <= ctx.getChildCount()) {
deleteStatement.applyPredicate(visitWhereClause((HqlParser.WhereClauseContext) ctx.getChild(dmlTargetIndex + 1)));
}
return deleteStatement;
} finally {
processingStateStack.pop();
}
}
use of org.hibernate.query.sqm.tree.delete.SqmDeleteStatement in project hibernate-orm by hibernate.
the class IdSelectionTests method testSecondaryTableRestrictedOnNonRootTable.
@Test
public void testSecondaryTableRestrictedOnNonRootTable(SessionFactoryScope scope) {
final SqmDeleteStatement<?> sqm = (SqmDeleteStatement<?>) scope.getSessionFactory().getQueryEngine().getHqlTranslator().translate("delete SimpleEntityWithSecondaryTables where data = :d", null);
final DomainParameterXref domainParameterXref = DomainParameterXref.from(sqm);
final ParameterMetadataImpl parameterMetadata = new ParameterMetadataImpl(domainParameterXref.getQueryParameters());
final QueryParameterBindingsImpl domainParamBindings = QueryParameterBindingsImpl.from(parameterMetadata, scope.getSessionFactory());
domainParamBindings.getBinding("d").setBindValue("123");
scope.inTransaction(session -> {
final DomainQueryExecutionContext executionContext = new TestExecutionContext(session, domainParamBindings);
MatchingIdSelectionHelper.selectMatchingIds(sqm, domainParameterXref, executionContext);
});
}
use of org.hibernate.query.sqm.tree.delete.SqmDeleteStatement in project hibernate-orm by hibernate.
the class IdSelectionTests method testSecondaryTableRestrictedOnRootTable.
@Test
public void testSecondaryTableRestrictedOnRootTable(SessionFactoryScope scope) {
final SqmDeleteStatement<?> sqm = (SqmDeleteStatement<?>) scope.getSessionFactory().getQueryEngine().getHqlTranslator().translate("delete SimpleEntityWithSecondaryTables where name = :n", null);
final DomainParameterXref domainParameterXref = DomainParameterXref.from(sqm);
final ParameterMetadataImpl parameterMetadata = new ParameterMetadataImpl(domainParameterXref.getQueryParameters());
final QueryParameterBindingsImpl domainParamBindings = QueryParameterBindingsImpl.from(parameterMetadata, scope.getSessionFactory());
domainParamBindings.getBinding("n").setBindValue("abc");
scope.inTransaction(session -> {
final DomainQueryExecutionContext executionContext = new TestExecutionContext(session, domainParamBindings);
MatchingIdSelectionHelper.selectMatchingIds(sqm, domainParameterXref, executionContext);
});
}
Aggregations