Search in sources :

Example 16 with HQLQueryPlan

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

the class CompositeIdTest method testNonDistinctCountOfEntityWithCompositeId.

@Test
public void testNonDistinctCountOfEntityWithCompositeId() {
    // the check here is all based on whether we had commas in the expressions inside the count
    final HQLQueryPlan plan = sessionFactory().getQueryPlanCache().getHQLQueryPlan("select count(o) from Order o", false, Collections.EMPTY_MAP);
    assertEquals(1, plan.getTranslators().length);
    final QueryTranslator translator = plan.getTranslators()[0];
    final String generatedSql = translator.getSQLString();
    final int countExpressionListStart = generatedSql.indexOf("count(");
    final int countExpressionListEnd = generatedSql.indexOf(")", countExpressionListStart);
    final String countExpressionFragment = generatedSql.substring(countExpressionListStart + 6, countExpressionListEnd + 1);
    final boolean hadCommas = countExpressionFragment.contains(",");
    // set up the expectation based on Dialect...
    final boolean expectCommas = sessionFactory().getDialect().supportsTupleCounts();
    assertEquals(expectCommas, hadCommas);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) Test(org.junit.Test)

Example 17 with HQLQueryPlan

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

the class HQLTest method testReturnMetadata.

@Test
public void testReturnMetadata() {
    HQLQueryPlan plan = createQueryPlan("from Animal a");
    check(plan.getReturnMetadata(), false, true);
    plan = createQueryPlan("select a as animal from Animal a");
    check(plan.getReturnMetadata(), false, false);
    plan = createQueryPlan("from java.lang.Object");
    check(plan.getReturnMetadata(), true, true);
    plan = createQueryPlan("select o as entity from java.lang.Object o");
    check(plan.getReturnMetadata(), true, false);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) Test(org.junit.Test)

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