Search in sources :

Example 1 with NodeTraverser

use of org.hibernate.hql.internal.ast.util.NodeTraverser in project hibernate-orm by hibernate.

the class QueryTranslatorImpl method parse.

private HqlParser parse(boolean filter) throws TokenStreamException, RecognitionException {
    // Parse the query string into an HQL AST.
    final HqlParser parser = HqlParser.getInstance(hql);
    parser.setFilter(filter);
    LOG.debugf("parse() - HQL: %s", hql);
    parser.statement();
    final AST hqlAst = parser.getAST();
    final NodeTraverser walker = new NodeTraverser(new JavaConstantConverter(factory));
    walker.traverseDepthFirst(hqlAst);
    showHqlAst(hqlAst);
    parser.getParseErrorHandler().throwQueryException();
    return parser;
}
Also used : AST(antlr.collections.AST) NodeTraverser(org.hibernate.hql.internal.ast.util.NodeTraverser)

Example 2 with NodeTraverser

use of org.hibernate.hql.internal.ast.util.NodeTraverser in project hibernate-orm by hibernate.

the class HqlSqlWalker method handleWithFragment.

private void handleWithFragment(FromElement fromElement, AST hqlWithNode) throws SemanticException {
    try {
        withClause(hqlWithNode);
        AST hqlSqlWithNode = returnAST;
        if (LOG.isDebugEnabled()) {
            LOG.debug("handleWithFragment() : " + getASTPrinter().showAsString(hqlSqlWithNode, "-- with clause --"));
        }
        WithClauseVisitor visitor = new WithClauseVisitor(fromElement, queryTranslatorImpl);
        NodeTraverser traverser = new NodeTraverser(visitor);
        traverser.traverseDepthFirst(hqlSqlWithNode);
        SqlGenerator sql = new SqlGenerator(getSessionFactoryHelper().getFactory());
        sql.whereExpr(hqlSqlWithNode.getFirstChild());
        fromElement.setWithClauseFragment("(" + sql.getSQL() + ")");
    } catch (SemanticException e) {
        throw e;
    } catch (InvalidWithClauseException e) {
        throw e;
    } catch (Exception e) {
        throw new SemanticException(e.getMessage());
    }
}
Also used : AST(antlr.collections.AST) NodeTraverser(org.hibernate.hql.internal.ast.util.NodeTraverser) RecognitionException(antlr.RecognitionException) QueryException(org.hibernate.QueryException) SemanticException(antlr.SemanticException) SemanticException(antlr.SemanticException)

Aggregations

AST (antlr.collections.AST)2 NodeTraverser (org.hibernate.hql.internal.ast.util.NodeTraverser)2 RecognitionException (antlr.RecognitionException)1 SemanticException (antlr.SemanticException)1 QueryException (org.hibernate.QueryException)1