Search in sources :

Example 1 with QueryParameterBindingsImpl

use of org.hibernate.query.internal.QueryParameterBindingsImpl in project hibernate-orm by hibernate.

the class IdSelectionTests method testJoinedSubclassRestrictedOnPrimaryNonRootTable.

@Test
public void testJoinedSubclassRestrictedOnPrimaryNonRootTable(SessionFactoryScope scope) {
    final SqmDeleteStatement<?> sqm = (SqmDeleteStatement<?>) scope.getSessionFactory().getQueryEngine().getHqlTranslator().translate("delete ForeignCustomer where vat = :v");
    final DomainParameterXref domainParameterXref = DomainParameterXref.from(sqm);
    final ParameterMetadataImpl parameterMetadata = new ParameterMetadataImpl(domainParameterXref.getQueryParameters());
    final QueryParameterBindingsImpl domainParamBindings = QueryParameterBindingsImpl.from(parameterMetadata, scope.getSessionFactory());
    domainParamBindings.getBinding("v").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 2 with QueryParameterBindingsImpl

use of org.hibernate.query.internal.QueryParameterBindingsImpl in project hibernate-orm by hibernate.

the class IdSelectionTests method testJoinedSubclassRestrictedOnRootTable.

@Test
public void testJoinedSubclassRestrictedOnRootTable(SessionFactoryScope scope) {
    final SqmDeleteStatement<?> sqm = (SqmDeleteStatement<?>) scope.getSessionFactory().getQueryEngine().getHqlTranslator().translate("delete Customer 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("Acme");
    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 3 with QueryParameterBindingsImpl

use of org.hibernate.query.internal.QueryParameterBindingsImpl in project hibernate-orm by hibernate.

the class IdSelectionTests method testJoinedSubclassRestrictedOnNonPrimaryRootTable.

@Test
public void testJoinedSubclassRestrictedOnNonPrimaryRootTable(SessionFactoryScope scope) {
    final SqmDeleteStatement<?> sqm = (SqmDeleteStatement<?>) scope.getSessionFactory().getQueryEngine().getHqlTranslator().translate("delete ForeignCustomer 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("Acme");
    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 4 with QueryParameterBindingsImpl

use of org.hibernate.query.internal.QueryParameterBindingsImpl in project blaze-persistence by Blazebit.

the class Hibernate53Access method expandParameterLists.

@Override
public String expandParameterLists(SessionImplementor session, org.hibernate.Query hibernateQuery, Map<String, TypedValue> namedParamsCopy) {
    QueryParameterBindingsImpl queryParameterBindings = hibernateQuery.unwrap(QueryParameterBindingsImpl.class);
    SharedSessionContractImplementor producer = (SharedSessionContractImplementor) ((QueryImplementor<?>) hibernateQuery).getProducer();
    String query = hibernateQuery.getQueryString();
    // NOTE: In Hibernate 5.3.0.CR1 this is call causes a side effect which is why this is essentially unusable for us
    query = queryParameterBindings.expandListValuedParameters(query, producer);
    return query;
}
Also used : SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) QueryParameterBindingsImpl(org.hibernate.query.internal.QueryParameterBindingsImpl)

Example 5 with QueryParameterBindingsImpl

use of org.hibernate.query.internal.QueryParameterBindingsImpl in project blaze-persistence by Blazebit.

the class Hibernate56Access method expandParameterLists.

@Override
public String expandParameterLists(SessionImplementor session, org.hibernate.Query hibernateQuery, Map<String, TypedValue> namedParamsCopy) {
    QueryParameterBindingsImpl queryParameterBindings = hibernateQuery.unwrap(QueryParameterBindingsImpl.class);
    SharedSessionContractImplementor producer = (SharedSessionContractImplementor) ((QueryImplementor<?>) hibernateQuery).getProducer();
    String query = hibernateQuery.getQueryString();
    // NOTE: In Hibernate 5.3.0.CR1 this is call causes a side effect which is why this is essentially unusable for us
    query = queryParameterBindings.expandListValuedParameters(query, producer);
    return query;
}
Also used : SharedSessionContractImplementor(org.hibernate.engine.spi.SharedSessionContractImplementor) QueryParameterBindingsImpl(org.hibernate.query.internal.QueryParameterBindingsImpl)

Aggregations

QueryParameterBindingsImpl (org.hibernate.query.internal.QueryParameterBindingsImpl)9 JoinedInheritanceTest (org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest)5 ParameterMetadataImpl (org.hibernate.query.internal.ParameterMetadataImpl)5 DomainQueryExecutionContext (org.hibernate.query.spi.DomainQueryExecutionContext)5 DomainParameterXref (org.hibernate.query.sqm.internal.DomainParameterXref)5 SqmDeleteStatement (org.hibernate.query.sqm.tree.delete.SqmDeleteStatement)5 Test (org.junit.jupiter.api.Test)5 SharedSessionContractImplementor (org.hibernate.engine.spi.SharedSessionContractImplementor)4