Search in sources :

Example 6 with QueryTranslatorImpl

use of org.hibernate.hql.internal.ast.QueryTranslatorImpl in project hibernate-orm by hibernate.

the class EJBQLTest method testEjb3PositionalParameters.

@Test
public void testEjb3PositionalParameters() throws Exception {
    QueryTranslatorImpl qt = compile("from Animal a where a.bodyWeight = ?1");
    AST ast = (AST) qt.getSqlAST();
    // make certain that the ejb3-positional param got recognized as a named param
    List namedParams = ASTUtil.collectChildren(ast, new ASTUtil.FilterPredicate() {

        public boolean exclude(AST n) {
            return n.getType() != HqlSqlTokenTypes.NAMED_PARAM;
        }
    });
    assertTrue("ejb3 positional param not recognized as a named param", namedParams.size() > 0);
}
Also used : AST(antlr.collections.AST) List(java.util.List) ASTUtil(org.hibernate.hql.internal.ast.util.ASTUtil) QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl) Test(org.junit.Test)

Example 7 with QueryTranslatorImpl

use of org.hibernate.hql.internal.ast.QueryTranslatorImpl in project hibernate-orm by hibernate.

the class EJBQLTest method compile.

private QueryTranslatorImpl compile(String input) {
    QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
    QueryTranslator queryTranslator = ast.createQueryTranslator(input, input, Collections.EMPTY_MAP, sessionFactory(), null);
    queryTranslator.compile(Collections.EMPTY_MAP, true);
    return (QueryTranslatorImpl) queryTranslator;
}
Also used : QueryTranslatorFactory(org.hibernate.hql.spi.QueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl)

Example 8 with QueryTranslatorImpl

use of org.hibernate.hql.internal.ast.QueryTranslatorImpl in project hibernate-orm by hibernate.

the class HQLTest method testRowValueConstructorSyntaxInInListBeingTranslated.

@Test
@SkipForDialect(value = { Oracle8iDialect.class, AbstractHANADialect.class, PostgreSQL81Dialect.class, MySQLDialect.class })
public void testRowValueConstructorSyntaxInInListBeingTranslated() {
    QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?)");
    assertInExist("'in' should be translated to 'and'", false, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in ?");
    assertInExist("'in' should be translated to 'and'", false, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
    assertInExist("'in' should be translated to 'and'", false, translator);
    translator = createNewQueryTranslator("from Animal a where a.id in (?)");
    assertInExist("only translated tuple has 'in' syntax", true, translator);
    translator = createNewQueryTranslator("from Animal a where a.id in ?");
    assertInExist("only translated tuple has 'in' syntax", true, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in (select a1 from Animal a1 left join a1.offspring o where a1.id = 1)");
    assertInExist("do not translate sub-queries", true, translator);
}
Also used : QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl) SkipForDialect(org.hibernate.testing.SkipForDialect) Test(org.junit.Test)

Example 9 with QueryTranslatorImpl

use of org.hibernate.hql.internal.ast.QueryTranslatorImpl in project hibernate-orm by hibernate.

the class HQLTest method testDateTimeArithmeticReturnTypesAndParameterGuessing.

@Test
public void testDateTimeArithmeticReturnTypesAndParameterGuessing() {
    QueryTranslatorImpl translator = createNewQueryTranslator("select o.orderDate - o.orderDate from Order o");
    assertEquals("incorrect return type count", 1, translator.getReturnTypes().length);
    assertEquals("incorrect return type", DoubleType.INSTANCE, translator.getReturnTypes()[0]);
    translator = createNewQueryTranslator("select o.orderDate + 2 from Order o");
    assertEquals("incorrect return type count", 1, translator.getReturnTypes().length);
    assertEquals("incorrect return type", CalendarDateType.INSTANCE, translator.getReturnTypes()[0]);
    translator = createNewQueryTranslator("select o.orderDate -2 from Order o");
    assertEquals("incorrect return type count", 1, translator.getReturnTypes().length);
    assertEquals("incorrect return type", CalendarDateType.INSTANCE, translator.getReturnTypes()[0]);
    translator = createNewQueryTranslator("from Order o where o.orderDate > ?");
    assertEquals("incorrect expected param type", CalendarDateType.INSTANCE, translator.getParameterTranslations().getOrdinalParameterExpectedType(0));
    translator = createNewQueryTranslator("select o.orderDate + ? from Order o");
    assertEquals("incorrect return type count", 1, translator.getReturnTypes().length);
    assertEquals("incorrect return type", CalendarDateType.INSTANCE, translator.getReturnTypes()[0]);
    assertEquals("incorrect expected param type", DoubleType.INSTANCE, translator.getParameterTranslations().getOrdinalParameterExpectedType(0));
}
Also used : QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl) Test(org.junit.Test)

Aggregations

QueryTranslatorImpl (org.hibernate.hql.internal.ast.QueryTranslatorImpl)9 Test (org.junit.Test)6 QueryTranslatorFactory (org.hibernate.hql.spi.QueryTranslatorFactory)4 ASTQueryTranslatorFactory (org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory)3 ClassicQueryTranslatorFactory (org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory)2 QueryTranslator (org.hibernate.hql.spi.QueryTranslator)2 AST (antlr.collections.AST)1 List (java.util.List)1 QueryException (org.hibernate.QueryException)1 ASTUtil (org.hibernate.hql.internal.ast.util.ASTUtil)1 RequiresDialectFeature (org.hibernate.testing.RequiresDialectFeature)1 SkipForDialect (org.hibernate.testing.SkipForDialect)1 TestForIssue (org.hibernate.testing.TestForIssue)1