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