Search in sources :

Example 1 with QueryTranslatorImpl

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

the class CollectionPropertyDeprecationsTest method compileQuery.

private QueryTranslatorImpl compileQuery(String hql) {
    QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
    QueryTranslatorImpl newQueryTranslator = (QueryTranslatorImpl) ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, sessionFactory(), null);
    newQueryTranslator.compile(Collections.emptyMap(), false);
    return newQueryTranslator;
}
Also used : QueryTranslatorFactory(org.hibernate.hql.spi.QueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl)

Example 2 with QueryTranslatorImpl

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

the class QueryTranslatorTestCase method createNewQueryTranslator.

private QueryTranslatorImpl createNewQueryTranslator(String hql, Map replacements, boolean scalar, SessionFactoryImplementor factory) {
    QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
    QueryTranslatorImpl newQueryTranslator = (QueryTranslatorImpl) ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, factory, null);
    newQueryTranslator.compile(replacements, scalar);
    return newQueryTranslator;
}
Also used : ClassicQueryTranslatorFactory(org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) QueryTranslatorFactory(org.hibernate.hql.spi.QueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl)

Example 3 with QueryTranslatorImpl

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

the class HQLTest method testBogusQuery.

@Test
@TestForIssue(jiraKey = "HHH-2187")
public void testBogusQuery() {
    try {
        QueryTranslatorImpl translator = createNewQueryTranslator("bogus");
        fail("This should have failed with a QueryException");
    } catch (Throwable t) {
        assertTyping(QueryException.class, t);
    }
}
Also used : QueryException(org.hibernate.QueryException) QueryTranslatorImpl(org.hibernate.hql.internal.ast.QueryTranslatorImpl) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 4 with QueryTranslatorImpl

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

the class HQLTest method testRowValueConstructorSyntaxInInList.

@Test
@RequiresDialectFeature(DialectChecks.SupportsRowValueConstructorSyntaxInInListCheck.class)
public void testRowValueConstructorSyntaxInInList() {
    QueryTranslatorImpl translator = createNewQueryTranslator("from LineItem l where l.id in (?1)");
    assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in ?1");
    assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
    translator = createNewQueryTranslator("from LineItem l where l.id in (('a1',1,'b1'),('a2',2,'b2'))");
    assertInExist(" 'in' should be kept, since the dialect supports this syntax", true, translator);
    translator = createNewQueryTranslator("from Animal a where a.id in (?1)");
    assertInExist("only translated tuple has 'in' syntax", true, translator);
    translator = createNewQueryTranslator("from Animal a where a.id in ?1");
    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) Test(org.junit.Test) RequiresDialectFeature(org.hibernate.testing.RequiresDialectFeature)

Example 5 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)

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