use of org.hibernate.engine.query.spi.QueryPlanCache 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.QueryPlanCache 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.QueryPlanCache in project hibernate-orm by hibernate.
the class NativeSQLQueryPlanEqualsTest method testNativeSQLQuerySpecEquals.
@Test
public void testNativeSQLQuerySpecEquals() {
QueryPlanCache cache = new QueryPlanCache(sessionFactory());
NativeSQLQuerySpecification firstSpec = createSpec();
NativeSQLQuerySpecification secondSpec = createSpec();
NativeSQLQueryPlan firstPlan = cache.getNativeSQLQueryPlan(firstSpec);
NativeSQLQueryPlan secondPlan = cache.getNativeSQLQueryPlan(secondSpec);
assertEquals(firstPlan, secondPlan);
}
Aggregations