Search in sources :

Example 26 with HQLQueryPlan

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

the class PaginationTest method testLimitWithExpreesionAndFetchJoin.

/**
 * @author Piotr Findeisen <piotr.findeisen@gmail.com>
 */
@Test
@TestForIssue(jiraKey = "HHH-951")
@RequiresDialectFeature(value = DialectChecks.SupportLimitCheck.class, comment = "Dialect does not support limit")
public void testLimitWithExpreesionAndFetchJoin() {
    Session session = openSession();
    session.beginTransaction();
    String hql = "SELECT b, 1 FROM DataMetaPoint b inner join fetch b.dataPoint dp";
    session.createQuery(hql).setMaxResults(3).list();
    HQLQueryPlan queryPlan = new HQLQueryPlan(hql, false, Collections.EMPTY_MAP, sessionFactory());
    String sqlQuery = queryPlan.getTranslators()[0].collectSqlStrings().get(0);
    session.getTransaction().commit();
    session.close();
    Matcher matcher = Pattern.compile("(?is)\\b(?<column>\\w+\\.\\w+)\\s+as\\s+(?<alias>\\w+)\\b.*\\k<column>\\s+as\\s+\\k<alias>").matcher(sqlQuery);
    if (matcher.find()) {
        fail(format("Column %s mapped to alias %s twice in generated SQL: %s", matcher.group("column"), matcher.group("alias"), sqlQuery));
    }
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) Matcher(java.util.regex.Matcher) Session(org.hibernate.Session) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature) TestForIssue(org.hibernate.testing.TestForIssue)

Example 27 with HQLQueryPlan

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

the class TupleSupportTest method testImplicitTupleNotInList.

@Test
public void testImplicitTupleNotInList() {
    final String hql = "from TheEntity e where e.compositeValue not in (:p1,:p2)";
    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("<>"));
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) Test(org.junit.Test)

Example 28 with HQLQueryPlan

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

the class StatelessSessionImpl method scroll.

@Override
public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException {
    checkOpen();
    HQLQueryPlan plan = getQueryPlan(query, false);
    return plan.performScroll(queryParameters, this);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan)

Example 29 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 30 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)46 IHQLQueryPlan (org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan)27 Filter (org.hibernate.Filter)18 TableFilter (org.hibernate.cfg.reveng.TableFilter)18 ITableFilter (org.jboss.tools.hibernate.runtime.spi.ITableFilter)18 Test (org.junit.jupiter.api.Test)18 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)16 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)11 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)11 File (java.io.File)9 FileWriter (java.io.FileWriter)9 Column (org.hibernate.mapping.Column)9 PrimaryKey (org.hibernate.mapping.PrimaryKey)9 RootClass (org.hibernate.mapping.RootClass)9 SimpleValue (org.hibernate.mapping.SimpleValue)9 Table (org.hibernate.mapping.Table)9 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)9 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)9 ISessionFactory (org.jboss.tools.hibernate.runtime.spi.ISessionFactory)9 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)9