private HqlParser parse(boolean filter) throws TokenStreamException { // Parse the query string into an HQL AST. final HqlParser parser = HqlParser.getInstance( hql ); parser.setFilter( filter ); LOG.debugf( "parse() - HQL: %s", hql ); try { parser.statement(); } catch (RecognitionException e) { throw new HibernateException( "Unexpected error parsing HQL", e ); } final AST hqlAst = parser.getAST(); parser.getParseErrorHandler().throwQueryException(); final NodeTraverser walker = new NodeTraverser( new JavaConstantConverter( factory ) ); walker.traverseDepthFirst( hqlAst ); showHqlAst( hqlAst ); return parser; }
public void showAst(AST ast, PrintStream out) { showAst( ast, new PrintWriter( out ) ); }
/** * Get a HqlParser instance for the given HQL string. * * @param hql The HQL query string * * @return The parser. */ public static HqlParser getInstance(String hql) { return new HqlParser( hql ); }
@Override public void matchOptionalFrom() throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); AST optionalFrom_AST = null; if ( LA( 1 ) == FROM ) { if ( LA( 2 ) != DOT ) { match( FROM ); optionalFrom_AST = (AST) currentAST.root; returnAST = optionalFrom_AST; } } }
HqlParser parser = HqlParser.getInstance(jpaQuery); parser.statement(); AST hqlAst = parser.getAST(); parser.showAst(hqlAst, System.out);
ASTFactory inputAstFactory = hqlParser.getASTFactory(); AST fromElement = inputAstFactory.create( HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName ); ASTUtil.createSibling( inputAstFactory, HqlTokenTypes.ALIAS, "this", fromElement ); queryTranslatorImpl.showHqlAst( hqlParser.getAST() );
private HqlSqlWalker analyze(HqlParser parser, String collectionRole) throws QueryException, RecognitionException { final HqlSqlWalker w = new HqlSqlWalker( this, factory, parser, tokenReplacements, collectionRole ); final AST hqlAst = parser.getAST(); // Transform the tree. w.statement( hqlAst ); if ( LOG.isDebugEnabled() ) { LOG.debug( TokenPrinters.SQL_TOKEN_PRINTER.showAsString( w.getAST(), "--- SQL AST ---" ) ); } w.getParseErrorHandler().throwQueryException(); return w; }
reportWarning( "Keyword '" + token.getText() token.setType( HqlTokenTypes.WEIRD_IDENT ); astFactory.addASTChild( currentAST, astFactory.create( token ) ); consume(); return currentAST.root;
ASTFactory inputAstFactory = hqlParser.getASTFactory(); AST fromElement = ASTUtil.create( inputAstFactory, HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName ); ASTUtil.createSibling( inputAstFactory, HqlTokenTypes.ALIAS, "this", fromElement ); queryTranslatorImpl.showHqlAst( hqlParser.getAST() );
@Override public void handleDotIdent() throws TokenStreamException { // This handles HHH-354, where there is a strange property name in a where clause. // If the lookahead contains a DOT then something that isn't an IDENT... if ( LA( 1 ) == DOT && LA( 2 ) != IDENT ) { // See if the second lookahead token can be an identifier. HqlToken t = (HqlToken) LT( 2 ); if ( t.isPossibleID() ) { // Set it! LT( 2 ).setType( IDENT ); if ( LOG.isDebugEnabled() ) { LOG.debugf( "handleDotIdent() : new LT(2) token - %s", LT( 1 ) ); } } } }
private HqlSqlWalker analyze(HqlParser parser, Map<?, ?> tokenReplacements, String collectionRole) throws QueryException, RecognitionException { final HqlSqlWalker w = new HqlSqlWalker( delegate, sessionFactory, parser, tokenReplacements, collectionRole ) { @Override public Map getEnabledFilters() { return filters; } }; final AST hqlAst = parser.getAST(); // Transform the tree. w.statement( hqlAst ); w.getParseErrorHandler().throwQueryException(); return w; }
reportWarning( "Keyword '" + token.getText() + "' is being interpreted as an identifier due to: " + mte.getMessage() ); token.setType( HqlTokenTypes.WEIRD_IDENT ); astFactory.addASTChild( currentAST, astFactory.create( token ) ); consume(); AST identifierAST = currentAST.root; return identifierAST;
private HqlParser parse(boolean filter) throws TokenStreamException, RecognitionException { // Parse the query string into an HQL AST. final HqlParser parser = HqlParser.getInstance( query ); parser.setFilter( filter ); parser.statement(); final AST hqlAst = parser.getAST(); final NodeTraverser walker = new NodeTraverser( new JavaConstantConverter( sessionFactory ) ); walker.traverseDepthFirst( hqlAst ); parser.getParseErrorHandler().throwQueryException(); return parser; }
ASTFactory inputAstFactory = hqlParser.getASTFactory(); AST fromElement = ASTUtil.create( inputAstFactory, HqlTokenTypes.FILTER_ENTITY, collectionElementEntityName ); ASTUtil.createSibling( inputAstFactory, HqlTokenTypes.ALIAS, "this", fromElement ); queryTranslatorImpl.showHqlAst( hqlParser.getAST() );
@Override public void handlePrimaryExpressionDotIdent() throws TokenStreamException { if ( LA( 2 ) == DOT && LA( 3 ) != IDENT ) { // See if the second lookahead token can be an identifier. HqlToken t = (HqlToken) LT( 3 ); if ( t.isPossibleID() ) { // Set it! t.setType( IDENT ); if ( LOG.isDebugEnabled() ) { LOG.debugf( "handleDotIdent() : new LT(3) token - %s", LT( 1 ) ); } } } }
private HqlSqlWalker analyze(HqlParser parser, String collectionRole) throws QueryException, RecognitionException { HqlSqlWalker w = new HqlSqlWalker( this, factory, parser, tokenReplacements, collectionRole ); AST hqlAst = parser.getAST(); // Transform the tree. w.statement( hqlAst ); if ( LOG.isDebugEnabled() ) { ASTPrinter printer = new ASTPrinter( SqlTokenTypes.class ); LOG.debug( printer.showAsString( w.getAST(), "--- SQL AST ---" ) ); } w.getParseErrorHandler().throwQueryException(); return w; }
public void showAst(AST ast, PrintStream out) { showAst( ast, new PrintWriter( out ) ); }
reportWarning( "Keyword '" + token.getText() + "' is being interpreted as an identifier due to: " + mte.getMessage() ); token.setType( HqlTokenTypes.WEIRD_IDENT ); astFactory.addASTChild( currentAST, astFactory.create( token ) ); consume(); AST identifierAST = currentAST.root; return identifierAST;