Search in sources :

Example 31 with HQLQueryPlan

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

the class AbstractProducedQuery method makeQueryParametersForExecution.

protected QueryParameters makeQueryParametersForExecution(String hql) {
    final HQLQueryPlan entityGraphHintedQueryPlan;
    if (entityGraphQueryHint == null) {
        entityGraphHintedQueryPlan = null;
    } else {
        entityGraphHintedQueryPlan = new HQLQueryPlan(hql, false, getProducer().getLoadQueryInfluencers().getEnabledFilters(), getProducer().getFactory(), entityGraphQueryHint);
    }
    QueryParameters queryParameters = new QueryParameters(getQueryParameterBindings(), getLockOptions(), queryOptions, true, isReadOnly(), cacheable, cacheRegion, comment, dbHints, null, optionalObject, optionalEntityName, optionalId, resultTransformer);
    queryParameters.setQueryPlan(entityGraphHintedQueryPlan);
    if (passDistinctThrough != null) {
        queryParameters.setPassDistinctThrough(passDistinctThrough);
    }
    return queryParameters;
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) QueryParameters(org.hibernate.engine.spi.QueryParameters)

Example 32 with HQLQueryPlan

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

the class SessionImpl method iterate.

@Override
public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException {
    checkOpenOrWaitingForAutoClose();
    checkTransactionSynchStatus();
    queryParameters.validateParameters();
    HQLQueryPlan plan = queryParameters.getQueryPlan();
    if (plan == null) {
        plan = getQueryPlan(query, true);
    }
    autoFlushIfRequired(plan.getQuerySpaces());
    // stops flush being called multiple times if this method is recursively called
    dontFlushFromFind++;
    try {
        return plan.performIterate(queryParameters, this);
    } finally {
        delayedAfterCompletion();
        dontFlushFromFind--;
    }
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan)

Example 33 with HQLQueryPlan

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

the class StatelessSessionImpl method list.

// ///////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: COPY/PASTE FROM SessionImpl, pull up!
@Override
public List list(String query, QueryParameters queryParameters) throws HibernateException {
    checkOpen();
    queryParameters.validateParameters();
    HQLQueryPlan plan = getQueryPlan(query, false);
    boolean success = false;
    List results = Collections.EMPTY_LIST;
    try {
        results = plan.performList(queryParameters, this);
        success = true;
    } finally {
        afterOperation(success);
    }
    temporaryPersistenceContext.clear();
    return results;
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) List(java.util.List)

Example 34 with HQLQueryPlan

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

the class MultiInheritanceImplicitDowncastTest method testMultiJoinAddition.

private void testMultiJoinAddition(String hql) {
    final HQLQueryPlan plan = sessionFactory().getQueryPlanCache().getHQLQueryPlan(hql, false, Collections.EMPTY_MAP);
    assertEquals(1, plan.getTranslators().length);
    final QueryTranslator translator = plan.getTranslators()[0];
    final String generatedSql = translator.getSQLString();
    int sub1JoinColumnIndex = generatedSql.indexOf(".base_sub_1");
    assertNotEquals("Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub1' via 'base_sub_1':\n" + generatedSql, -1, sub1JoinColumnIndex);
    int sub2JoinColumnIndex = generatedSql.indexOf(".base_sub_2");
    assertNotEquals("Generated SQL doesn't contain a join for 'base' with 'PolymorphicSub2' via 'base_sub_2':\n" + generatedSql, -1, sub2JoinColumnIndex);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) QueryTranslator(org.hibernate.hql.spi.QueryTranslator)

Example 35 with HQLQueryPlan

use of org.hibernate.engine.query.spi.HQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateHQLQueryPlan.

@Test
public void testCreateHQLQueryPlan() {
    final Collection<PersistentClass> entityBindings = new ArrayList<PersistentClass>();
    final StandardServiceRegistryBuilder standardServiceRegistryBuilder = new StandardServiceRegistryBuilder();
    standardServiceRegistryBuilder.applySetting(AvailableSettings.DIALECT, TestDialect.class.getName());
    final StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);
    final MetadataImplementor metadata = (MetadataImplementor) metadataSources.buildMetadata();
    Table t = new Table("FOO");
    Column c = new Column("foo");
    t.addColumn(c);
    PrimaryKey key = new PrimaryKey(t);
    key.addColumn(c);
    t.setPrimaryKey(key);
    SimpleValue sv = new SimpleValue(metadata);
    sv.setNullValue("null");
    sv.setTypeName(Integer.class.getName());
    sv.setTable(t);
    sv.addColumn(c);
    final RootClass rc = new RootClass(null);
    rc.setEntityName("foo");
    rc.setJpaEntityName("foo");
    rc.setIdentifier(sv);
    rc.setTable(t);
    entityBindings.add(rc);
    MetadataImplementor wrapper = (MetadataImplementor) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { MetadataImplementor.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if ("getEntityBinding".equals(method.getName()) && args != null && args.length == 1 && "foo".equals(args[0])) {
                return rc;
            } else if ("getEntityBindings".equals(method.getName())) {
                return entityBindings;
            }
            return method.invoke(metadata, args);
        }
    });
    SessionFactoryBuilder sfb = new SessionFactoryBuilderImpl(wrapper);
    SessionFactoryImpl sfi = (SessionFactoryImpl) sfb.build();
    Map<String, Filter> filters = Collections.emptyMap();
    HQLQueryPlan hqlQueryPlan = new HQLQueryPlan("from foo", false, filters, sfi);
    IHQLQueryPlan facade = facadeFactory.createHQLQueryPlan(hqlQueryPlan);
    assertSame(hqlQueryPlan, ((IFacade) facade).getTarget());
}
Also used : StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) ArrayList(java.util.ArrayList) MetadataSources(org.hibernate.boot.MetadataSources) PrimaryKey(org.hibernate.mapping.PrimaryKey) IPrimaryKey(org.jboss.tools.hibernate.runtime.spi.IPrimaryKey) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) IColumn(org.jboss.tools.hibernate.runtime.spi.IColumn) Column(org.hibernate.mapping.Column) SessionFactoryBuilder(org.hibernate.boot.SessionFactoryBuilder) SessionFactoryBuilderImpl(org.hibernate.boot.internal.SessionFactoryBuilderImpl) PersistentClass(org.hibernate.mapping.PersistentClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) RootClass(org.hibernate.mapping.RootClass) ITable(org.jboss.tools.hibernate.runtime.spi.ITable) Table(org.hibernate.mapping.Table) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) SimpleValue(org.hibernate.mapping.SimpleValue) HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) Filter(org.hibernate.Filter) PersistentClass(org.hibernate.mapping.PersistentClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) RootClass(org.hibernate.mapping.RootClass) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass) POJOClass(org.hibernate.tool.hbm2x.pojo.POJOClass) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) Test(org.junit.jupiter.api.Test)

Aggregations

HQLQueryPlan (org.hibernate.engine.query.spi.HQLQueryPlan)46 IHQLQueryPlan (org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan)27 Filter (org.hibernate.Filter)18 TableFilter (org.hibernate.cfg.reveng.TableFilter)18 ITableFilter (org.jboss.tools.hibernate.runtime.spi.ITableFilter)18 Test (org.junit.jupiter.api.Test)18 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)16 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)11 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)11 File (java.io.File)9 FileWriter (java.io.FileWriter)9 Column (org.hibernate.mapping.Column)9 PrimaryKey (org.hibernate.mapping.PrimaryKey)9 RootClass (org.hibernate.mapping.RootClass)9 SimpleValue (org.hibernate.mapping.SimpleValue)9 Table (org.hibernate.mapping.Table)9 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)9 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)9 ISessionFactory (org.jboss.tools.hibernate.runtime.spi.ISessionFactory)9 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)9