Search in sources :

Example 6 with ASTQueryTranslatorFactory

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

Example 7 with ASTQueryTranslatorFactory

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

Example 8 with ASTQueryTranslatorFactory

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

Example 9 with ASTQueryTranslatorFactory

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;
}
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 10 with ASTQueryTranslatorFactory

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

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