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