/** * Takes the "where" parameter and turns it into a Java Object that can be used for querying * * @param whereParam String * @return Query a parsed version of the where clause, represented in Java */ default Query getWhereClause(String whereParam) throws InvalidQueryException { if (whereParam == null) return QueryImpl.EMPTY; try { CommonTree whereTree = WhereCompiler.compileWhereClause(whereParam); if (whereTree instanceof CommonErrorNode) { rpeLogger().debug("Error parsing the WHERE clause " + whereTree); throw new InvalidQueryException(whereTree); } return new QueryImpl(whereTree); } catch (RewriteCardinalityException re) { //Catch any error so it doesn't get thrown up the stack rpeLogger().info("Unhandled Error parsing the WHERE clause: " + re); } catch (RecognitionException e) { whereParam += ", " + WhereCompiler.resolveMessage(e); rpeLogger().info("Error parsing the WHERE clause: " + whereParam); } //Default to throw out an invalid query throw new InvalidQueryException(whereParam); }
/** * Gets the clause specificed in paramName * * @param param * @param paramName * @return bean property names potentially using JSON Pointer syntax */ default List<String> getClause(String param, String paramName) { if (param == null) return Collections.emptyList(); try { CommonTree selectedPropsTree = WhereCompiler.compileSelectClause(param); if (selectedPropsTree instanceof CommonErrorNode) { rpeLogger().debug("Error parsing the " + paramName + " clause " + selectedPropsTree); throw new InvalidSelectException(paramName, selectedPropsTree); } if (selectedPropsTree.getChildCount() == 0 && !selectedPropsTree.getText().isEmpty()) { return Arrays.asList(selectedPropsTree.getText()); } List<Tree> children = (List<Tree>) selectedPropsTree.getChildren(); if (children != null && !children.isEmpty()) { List<String> properties = new ArrayList<String>(children.size()); for (Tree child : children) { properties.add(child.getText()); } return properties; } } catch (RewriteCardinalityException re) { //Catch any error so it doesn't get thrown up the stack rpeLogger().debug("Unhandled Error parsing the " + paramName + " clause: " + re); } catch (RecognitionException e) { rpeLogger().debug("Error parsing the \"+paramName+\" clause: " + param); } catch (InvalidQueryException iqe) { throw new InvalidSelectException(paramName, iqe.getQueryParam()); } //Default to throw out an invalid query throw new InvalidSelectException(paramName, param); }