public static CommonTree parse(String input, boolean failOnErrors) throws RecognitionException { JPA2Parser parser = createParser(input); JPA2Parser.ql_statement_return aReturn = parser.ql_statement(); CommonTree tree = (CommonTree) aReturn.getTree(); if (failOnErrors) { checkTreeForExceptions(input, tree); } return tree; }
@Override public void addFirstSelectionSource(String selection) { try { getTransformer().addFirstSelectionSource(Parser.parseSelectionSource(selection)); } catch (RecognitionException e) { throw new RuntimeException(e); } }
/** * copy from another statement * * @param statement from we copy where clause */ @Override @Deprecated public void mergeWhere(String statement) { try { EntityReference entityReference = createMainIdentificationVariableReference(); CommonTree whereTree = Parser.parse(statement, true); CommonTree whereClause = (CommonTree) whereTree.getFirstChildWithType(JPA2Lexer.T_CONDITION); addWhere(whereClause, entityReference, true); } catch (RecognitionException e) { throw new RuntimeException(e); } }
protected List<JoinVariableNode> parseJoinCondition(String joinCondition) { try { return Parser.parseJoinClause(joinCondition); } catch (RecognitionException | JPA2RecognitionException e) { throw new JpqlSyntaxException(format("Errors found while parsing join condition:[%s] for query:[%s]\n%s", StringUtils.strip(joinCondition), StringUtils.strip(query), e.getMessage())); } }
protected CommonTree parseWhereCondition(String whereCondition) { try { return Parser.parseWhereClause("where " + whereCondition); } catch (RecognitionException | JPA2RecognitionException e) { throw new JpqlSyntaxException(format("Errors found while parsing where condition:[%s] for query:[%s]\n%s", StringUtils.strip(whereCondition), StringUtils.strip(query), e.getMessage())); } }
public QueryTree(DomainModel model, String query, boolean failOnErrors) { Preconditions.checkNotNull(query, "query is null"); String modifiedQuery = StringUtils.replaceChars(query, "\n\r\t", " "); this.model = model; this.queryString = modifiedQuery; try { this.tree = Parser.parse(modifiedQuery, failOnErrors); } catch (RecognitionException e) { throw new JPA2RecognitionException("JPA grammar recognition error", e); } this.idVarSelector = new IdVarSelector(model); new TreeVisitor().visit(tree, idVarSelector); }
public static CommonTree parseWhereClause(String input) throws RecognitionException { JPA2Parser parser = createParser(input); JPA2Parser.where_clause_return aReturn = parser.where_clause(); CommonTree tree = (CommonTree) aReturn.getTree(); checkTreeForExceptions(input, tree); return tree; }
protected CommonTree parseSelectionSource(String selectionSource) { try { return Parser.parseSelectionSource(selectionSource); } catch (RecognitionException | JPA2RecognitionException e) { throw new JpqlSyntaxException(format("Errors found while parsing selection source:[%s] for query:[%s]\n%s", StringUtils.strip(selectionSource), StringUtils.strip(query), e.getMessage())); } }
public static CommonTree parseSelectionSource(String input) throws RecognitionException { JPA2Parser parser = createParser(input); JPA2Parser.identification_variable_declaration_or_collection_member_declaration_return aReturn = parser.identification_variable_declaration_or_collection_member_declaration(); CommonTree tree = (CommonTree) aReturn.getTree(); checkTreeForExceptions(input, tree); return tree; }
public static List<JoinVariableNode> parseJoinClause(String join) throws RecognitionException { JPA2Parser parser = createParser(join); JPA2Parser.join_section_return aReturn = parser.join_section(); CommonTree tree = (CommonTree) aReturn.getTree(); if (tree == null) { parser = createParser("join " + join); aReturn = parser.join_section(); tree = (CommonTree) aReturn.getTree(); } if (tree instanceof JoinVariableNode) { checkTreeForExceptions(join, tree); return Collections.singletonList((JoinVariableNode) tree); } else { List<JoinVariableNode> joins = tree.getChildren().stream() .filter(node -> node instanceof JoinVariableNode) .map(JoinVariableNode.class::cast) .collect(Collectors.toList()); checkTreeForExceptions(join, tree); return joins; } }