Search in sources :

Example 1 with HQLQueryPlan

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

the class EntityJoinTest method testNoImpliedJoinGeneratedForEqualityComparison.

@Test
@TestForIssue(jiraKey = "HHH-11538")
public void testNoImpliedJoinGeneratedForEqualityComparison() {
    doInHibernate(this::sessionFactory, session -> {
        final HQLQueryPlan plan = sessionFactory().getQueryPlanCache().getHQLQueryPlan("select r.id, cust.name " + "from FinancialRecord r " + "	join Customer cust on r.customer = cust" + "   order by r.id", false, Collections.EMPTY_MAP);
        assertEquals(1, plan.getTranslators().length);
        final QueryTranslator translator = plan.getTranslators()[0];
        final String generatedSql = translator.getSQLString();
        int tableReferenceIndex = generatedSql.indexOf(" customer ");
        assertNotEquals("Generated SQL doesn't contain a table reference for customer", -1, tableReferenceIndex);
        int nextTableReferenceIndex = generatedSql.indexOf(" customer ", tableReferenceIndex + 1);
        assertEquals("Generated SQL wrongly joined customer twice", -1, nextTableReferenceIndex);
    });
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 2 with HQLQueryPlan

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

the class TupleSupportTest method testImplicitTupleNotEquals.

@Test
public void testImplicitTupleNotEquals() {
    final String hql = "from TheEntity e where e.compositeValue <> :p1";
    HQLQueryPlan queryPlan = ((SessionFactoryImplementor) sessionFactory).getQueryPlanCache().getHQLQueryPlan(hql, false, Collections.<String, Filter>emptyMap());
    assertEquals(1, queryPlan.getSqlStrings().length);
    System.out.println(" SQL : " + queryPlan.getSqlStrings()[0]);
    assertTrue(queryPlan.getSqlStrings()[0].contains("<>"));
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) Test(org.junit.Test)

Example 3 with HQLQueryPlan

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

the class GetHqlQueryPlanTest method testHqlQueryPlanWithEnabledFilter.

@Test
public void testHqlQueryPlanWithEnabledFilter() {
    Session s = openSession();
    QueryPlanCache cache = ((SessionImplementor) s).getFactory().getQueryPlanCache();
    HQLQueryPlan plan1A = cache.getHQLQueryPlan("from Person", true, getEnabledFilters(s));
    HQLQueryPlan plan1B = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s));
    s.enableFilter("sex").setParameter("sexCode", Character.valueOf('F'));
    HQLQueryPlan plan2A = cache.getHQLQueryPlan("from Person", true, getEnabledFilters(s));
    HQLQueryPlan plan2B = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s));
    s.disableFilter("sex");
    HQLQueryPlan plan3A = cache.getHQLQueryPlan("from Person", true, getEnabledFilters(s));
    HQLQueryPlan plan3B = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s));
    s.enableFilter("sex").setParameter("sexCode", Character.valueOf('M'));
    HQLQueryPlan plan4A = cache.getHQLQueryPlan("from Person", true, getEnabledFilters(s));
    HQLQueryPlan plan4B = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s));
    assertSame(plan1A, plan3A);
    assertSame(plan1B, plan3B);
    assertSame(plan2A, plan4A);
    assertSame(plan2B, plan4B);
    assertNotSame(plan1A, plan1B);
    assertNotSame(plan1A, plan2A);
    assertNotSame(plan1A, plan2B);
    assertNotSame(plan1B, plan2A);
    assertNotSame(plan1B, plan2B);
    s.close();
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) QueryPlanCache(org.hibernate.engine.query.spi.QueryPlanCache) Session(org.hibernate.Session) Test(org.junit.Test)

Example 4 with HQLQueryPlan

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

the class SessionImpl method scroll.

@Override
public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException {
    checkOpenOrWaitingForAutoClose();
    checkTransactionSynchStatus();
    HQLQueryPlan plan = queryParameters.getQueryPlan();
    if (plan == null) {
        plan = getQueryPlan(query, false);
    }
    autoFlushIfRequired(plan.getQuerySpaces());
    dontFlushFromFind++;
    try {
        return plan.performScroll(queryParameters, this);
    } finally {
        delayedAfterCompletion();
        dontFlushFromFind--;
    }
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan)

Example 5 with HQLQueryPlan

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

the class SessionImpl method executeUpdate.

@Override
public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException {
    checkOpenOrWaitingForAutoClose();
    checkTransactionSynchStatus();
    queryParameters.validateParameters();
    HQLQueryPlan plan = getQueryPlan(query, false);
    autoFlushIfRequired(plan.getQuerySpaces());
    boolean success = false;
    int result = 0;
    try {
        result = plan.performExecuteUpdate(queryParameters, this);
        success = true;
    } finally {
        afterOperation(success);
        delayedAfterCompletion();
    }
    return result;
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan)

Aggregations

HQLQueryPlan (org.hibernate.engine.query.spi.HQLQueryPlan)35 Test (org.junit.Test)19 IHQLQueryPlan (org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan)16 Filter (org.hibernate.Filter)11 TableFilter (org.hibernate.cfg.reveng.TableFilter)11 ITableFilter (org.jboss.tools.hibernate.runtime.spi.ITableFilter)11 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)10 Column (org.hibernate.mapping.Column)6 PrimaryKey (org.hibernate.mapping.PrimaryKey)6 RootClass (org.hibernate.mapping.RootClass)6 SimpleValue (org.hibernate.mapping.SimpleValue)6 Table (org.hibernate.mapping.Table)6 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)6 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)6 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)6 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)6 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)6 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 File (java.io.File)4 FileWriter (java.io.FileWriter)4