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);
}
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;
}
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);
}
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));
}
Aggregations