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);
});
}
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));
}
}
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));
}
}
Aggregations