Search in sources :

Example 11 with QueryTranslatorFactory

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;
}
Also used : ClassicQueryTranslatorFactory(org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) QueryTranslatorFactory(org.hibernate.hql.spi.QueryTranslatorFactory) QueryException(org.hibernate.QueryException) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) MappingException(org.hibernate.MappingException) QueryException(org.hibernate.QueryException) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) MappingException(org.hibernate.MappingException)

Example 12 with QueryTranslatorFactory

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();
}
Also used : QueryTranslatorFactory(org.hibernate.hql.spi.QueryTranslatorFactory) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) QueryTranslator(org.hibernate.hql.spi.QueryTranslator) ASTQueryTranslatorFactory(org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory)

Aggregations

QueryTranslatorFactory (org.hibernate.hql.spi.QueryTranslatorFactory)12 ASTQueryTranslatorFactory (org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory)11 QueryTranslator (org.hibernate.hql.spi.QueryTranslator)9 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)4 QueryTranslatorImpl (org.hibernate.hql.internal.ast.QueryTranslatorImpl)4 ClassicQueryTranslatorFactory (org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory)4 HashMap (java.util.HashMap)3 Map (java.util.Map)2 MappingException (org.hibernate.MappingException)2 QueryException (org.hibernate.QueryException)2 Test (org.junit.Test)2 TreeMap (java.util.TreeMap)1 StrategySelector (org.hibernate.boot.registry.selector.spi.StrategySelector)1 TestForIssue (org.hibernate.testing.TestForIssue)1