Search in sources :

Example 6 with HQLQueryPlan

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

the class GetHqlQueryPlanTest method testHqlQueryPlan.

@Test
public void testHqlQueryPlan() {
    Session s = openSession();
    QueryPlanCache cache = ((SessionImplementor) s).getFactory().getQueryPlanCache();
    assertTrue(getEnabledFilters(s).isEmpty());
    HQLQueryPlan plan1 = cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s));
    HQLQueryPlan plan2 = cache.getHQLQueryPlan("from Person where name is null", false, getEnabledFilters(s));
    HQLQueryPlan plan3 = cache.getHQLQueryPlan("from Person where name = :name", false, getEnabledFilters(s));
    HQLQueryPlan plan4 = cache.getHQLQueryPlan("from Person where name = ?", false, getEnabledFilters(s));
    assertNotSame(plan1, plan2);
    assertNotSame(plan1, plan3);
    assertNotSame(plan1, plan4);
    assertNotSame(plan2, plan3);
    assertNotSame(plan2, plan4);
    assertNotSame(plan3, plan4);
    assertSame(plan1, cache.getHQLQueryPlan("from Person", false, getEnabledFilters(s)));
    assertSame(plan2, cache.getHQLQueryPlan("from Person where name is null", false, getEnabledFilters(s)));
    assertSame(plan3, cache.getHQLQueryPlan("from Person where name = :name", false, getEnabledFilters(s)));
    assertSame(plan4, cache.getHQLQueryPlan("from Person where name = ?", false, getEnabledFilters(s)));
    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 7 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 8 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)

Example 9 with HQLQueryPlan

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

the class SessionImpl method list.

@Override
public List list(String query, QueryParameters queryParameters) throws HibernateException {
    checkOpenOrWaitingForAutoClose();
    checkTransactionSynchStatus();
    queryParameters.validateParameters();
    HQLQueryPlan plan = queryParameters.getQueryPlan();
    if (plan == null) {
        plan = getQueryPlan(query, false);
    }
    autoFlushIfRequired(plan.getQuerySpaces());
    List results = Collections.EMPTY_LIST;
    boolean success = false;
    //stops flush being called multiple times if this method is recursively called
    dontFlushFromFind++;
    try {
        results = plan.performList(queryParameters, this);
        success = true;
    } finally {
        dontFlushFromFind--;
        afterOperation(success);
        delayedAfterCompletion();
    }
    return results;
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with HQLQueryPlan

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

the class StatelessSessionImpl method executeUpdate.

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

Aggregations

HQLQueryPlan (org.hibernate.engine.query.spi.HQLQueryPlan)17 Test (org.junit.Test)9 Session (org.hibernate.Session)4 QueryTranslator (org.hibernate.hql.spi.QueryTranslator)3 List (java.util.List)2 QueryPlanCache (org.hibernate.engine.query.spi.QueryPlanCache)2 TestForIssue (org.hibernate.testing.TestForIssue)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 QueryParameters (org.hibernate.engine.spi.QueryParameters)1 SQLGrammarException (org.hibernate.exception.SQLGrammarException)1 RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)1 SkipForDialect (org.hibernate.testing.SkipForDialect)1