Search in sources :

Example 6 with SqmDeleteStatement

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();
    }
}
Also used : TIMEZONE_HOUR(org.hibernate.query.sqm.TemporalUnit.TIMEZONE_HOUR) WEEK_OF_YEAR(org.hibernate.query.sqm.TemporalUnit.WEEK_OF_YEAR) DAY_OF_YEAR(org.hibernate.query.sqm.TemporalUnit.DAY_OF_YEAR) IDENTIFIER(org.hibernate.grammars.hql.HqlParser.IDENTIFIER) HqlParser(org.hibernate.grammars.hql.HqlParser) SqmDeleteStatement(org.hibernate.query.sqm.tree.delete.SqmDeleteStatement) SqmDmlCreationProcessingState(org.hibernate.query.sqm.internal.SqmDmlCreationProcessingState)

Example 7 with SqmDeleteStatement

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);
    });
}
Also used : SqmDeleteStatement(org.hibernate.query.sqm.tree.delete.SqmDeleteStatement) DomainParameterXref(org.hibernate.query.sqm.internal.DomainParameterXref) QueryParameterBindingsImpl(org.hibernate.query.internal.QueryParameterBindingsImpl) ParameterMetadataImpl(org.hibernate.query.internal.ParameterMetadataImpl) DomainQueryExecutionContext(org.hibernate.query.spi.DomainQueryExecutionContext) JoinedInheritanceTest(org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest) Test(org.junit.jupiter.api.Test)

Example 8 with SqmDeleteStatement

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);
    });
}
Also used : SqmDeleteStatement(org.hibernate.query.sqm.tree.delete.SqmDeleteStatement) DomainParameterXref(org.hibernate.query.sqm.internal.DomainParameterXref) QueryParameterBindingsImpl(org.hibernate.query.internal.QueryParameterBindingsImpl) ParameterMetadataImpl(org.hibernate.query.internal.ParameterMetadataImpl) DomainQueryExecutionContext(org.hibernate.query.spi.DomainQueryExecutionContext) JoinedInheritanceTest(org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest) Test(org.junit.jupiter.api.Test)

Aggregations

SqmDeleteStatement (org.hibernate.query.sqm.tree.delete.SqmDeleteStatement)8 JoinedInheritanceTest (org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest)5 ParameterMetadataImpl (org.hibernate.query.internal.ParameterMetadataImpl)5 QueryParameterBindingsImpl (org.hibernate.query.internal.QueryParameterBindingsImpl)5 DomainQueryExecutionContext (org.hibernate.query.spi.DomainQueryExecutionContext)5 DomainParameterXref (org.hibernate.query.sqm.internal.DomainParameterXref)5 Test (org.junit.jupiter.api.Test)5 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HibernateException (org.hibernate.HibernateException)1 LockMode (org.hibernate.LockMode)1 LockOptions (org.hibernate.LockOptions)1 JdbcEnvironment (org.hibernate.engine.jdbc.env.spi.JdbcEnvironment)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 HqlParser (org.hibernate.grammars.hql.HqlParser)1 IDENTIFIER (org.hibernate.grammars.hql.HqlParser.IDENTIFIER)1 EntityIdentifierMapping (org.hibernate.metamodel.mapping.EntityIdentifierMapping)1 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)1