use of org.hibernate.hql.spi.QueryTranslatorFactory 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.spi.QueryTranslatorFactory 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