Search in sources :

Example 11 with DomainQueryExecutionContext

use of org.hibernate.query.spi.DomainQueryExecutionContext 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");
    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)

Example 12 with DomainQueryExecutionContext

use of org.hibernate.query.spi.DomainQueryExecutionContext in project hibernate-orm by hibernate.

the class ParameterTests method testNarrowingTemporalPrecision.

@Test
public void testNarrowingTemporalPrecision() {
    try (Session session = sessionFactory().openSession()) {
        final Query query = session.createQuery("select p.id from Person p where p.dob between :start and :end");
        query.setParameter("start", Instant.now().minus(7, ChronoUnit.DAYS), TemporalType.DATE);
        query.setParameter("end", Instant.now().plus(7, ChronoUnit.DAYS), TemporalType.DATE);
        final QueryParameterBindings bindings = ((DomainQueryExecutionContext) query).getQueryParameterBindings();
        final QueryParameterBinding<?> startBinding = bindings.getBinding("start");
        assertThat(startBinding.getExplicitTemporalPrecision(), equalTo(TemporalType.DATE));
        final QueryParameterBinding<?> endBinding = bindings.getBinding("end");
        assertThat(endBinding.getExplicitTemporalPrecision(), equalTo(TemporalType.DATE));
    }
}
Also used : Query(org.hibernate.query.Query) QueryParameterBindings(org.hibernate.query.spi.QueryParameterBindings) Session(org.hibernate.Session) DomainQueryExecutionContext(org.hibernate.query.spi.DomainQueryExecutionContext) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Example 13 with DomainQueryExecutionContext

use of org.hibernate.query.spi.DomainQueryExecutionContext in project hibernate-orm by hibernate.

the class ParameterTests method testWideningTemporalPrecision.

@Test
public void testWideningTemporalPrecision() {
    try (Session session = sessionFactory().openSession()) {
        final Query query = session.createQuery("select p.id from Person p where p.anniversary between :start and :end");
        query.setParameter("start", Date.from(Instant.now().minus(7, ChronoUnit.DAYS)), TemporalType.TIMESTAMP);
        query.setParameter("end", Date.from(Instant.now().plus(7, ChronoUnit.DAYS)), TemporalType.TIMESTAMP);
        final QueryParameterBindings bindings = ((DomainQueryExecutionContext) query).getQueryParameterBindings();
        final QueryParameterBinding<?> startBinding = bindings.getBinding("start");
        assertThat(startBinding.getExplicitTemporalPrecision(), equalTo(TemporalType.TIMESTAMP));
        final QueryParameterBinding<?> endBinding = bindings.getBinding("end");
        assertThat(endBinding.getExplicitTemporalPrecision(), equalTo(TemporalType.TIMESTAMP));
    }
}
Also used : Query(org.hibernate.query.Query) QueryParameterBindings(org.hibernate.query.spi.QueryParameterBindings) Session(org.hibernate.Session) DomainQueryExecutionContext(org.hibernate.query.spi.DomainQueryExecutionContext) BaseSqmUnitTest(org.hibernate.orm.test.query.sqm.BaseSqmUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

DomainQueryExecutionContext (org.hibernate.query.spi.DomainQueryExecutionContext)13 DomainParameterXref (org.hibernate.query.sqm.internal.DomainParameterXref)9 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 SqmDeleteStatement (org.hibernate.query.sqm.tree.delete.SqmDeleteStatement)6 JoinedInheritanceTest (org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest)5 ParameterMetadataImpl (org.hibernate.query.internal.ParameterMetadataImpl)5 QueryParameterBindingsImpl (org.hibernate.query.internal.QueryParameterBindingsImpl)5 Collections (java.util.Collections)4 IdentityHashMap (java.util.IdentityHashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 List (java.util.List)4 Map (java.util.Map)4 TemporaryTable (org.hibernate.dialect.temptable.TemporaryTable)4 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 MappingModelExpressible (org.hibernate.metamodel.mapping.MappingModelExpressible)4 EntityPersister (org.hibernate.persister.entity.EntityPersister)4 SqmJdbcExecutionContextAdapter (org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter)4 MultiTableSqmMutationConverter (org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter)4 SqmParameter (org.hibernate.query.sqm.tree.expression.SqmParameter)4