use of org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory in project hibernate-orm by hibernate.
the class EJBQLTest method assertEjbqlEqualsHql.
private void assertEjbqlEqualsHql(String ejbql, String hql) {
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
QueryTranslator queryTranslator = ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, sessionFactory(), null);
queryTranslator.compile(Collections.EMPTY_MAP, true);
String hqlSql = queryTranslator.getSQLString();
queryTranslator = ast.createQueryTranslator(ejbql, ejbql, Collections.EMPTY_MAP, sessionFactory(), null);
queryTranslator.compile(Collections.EMPTY_MAP, true);
String ejbqlSql = queryTranslator.getSQLString();
assertEquals(hqlSql, ejbqlSql);
}
use of org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory 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.ASTQueryTranslatorFactory in project hibernate-orm by hibernate.
the class HQLTest method compileWithAstQueryTranslator.
private void compileWithAstQueryTranslator(String hql, boolean scalar) {
Map replacements = new HashMap();
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
SessionFactoryImplementor factory = getSessionFactoryImplementor();
QueryTranslator newQueryTranslator = ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, factory, null);
newQueryTranslator.compile(replacements, scalar);
}
use of org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory in project hibernate-orm by hibernate.
the class QueryTranslatorTestCase method compileBadHql.
protected Exception compileBadHql(String hql, boolean scalar) {
QueryTranslator newQueryTranslator;
Map replacements = null;
Exception newException = null;
SessionFactoryImplementor factory = sessionFactory();
try {
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory();
newQueryTranslator = ast.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, factory, null);
newQueryTranslator.compile(replacements, scalar);
} catch (QueryException e) {
newException = e;
} catch (MappingException e) {
newException = e;
}
assertNotNull("Expected exception from compilation of '" + hql + "'!", newException);
return newException;
}
use of org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory in project midpoint by Evolveum.
the class HibernateToSqlTranslator method toSql.
/**
* Do not use in production code! Only for testing purposes only. Used for example during query engine upgrade.
* Method provides translation from hibernate HQL query to plain SQL string query.
*
* @param sessionFactory
* @param hqlQueryText
* @return SQL string, null if hqlQueryText parameter is empty.
*/
public static String toSql(SessionFactory sessionFactory, String hqlQueryText) {
Validate.notNull(sessionFactory, "Session factory must not be null.");
if (StringUtils.isEmpty(hqlQueryText)) {
return null;
}
final QueryTranslatorFactory translatorFactory = new ASTQueryTranslatorFactory();
final SessionFactoryImplementor factory = (SessionFactoryImplementor) sessionFactory;
final QueryTranslator translator = translatorFactory.createQueryTranslator(hqlQueryText, hqlQueryText, Collections.EMPTY_MAP, factory, null);
translator.compile(Collections.EMPTY_MAP, false);
return translator.getSQLString();
}
Aggregations