/** * @return returns list of join variable nodes (JOIN entityName entityAlias ON clause) from FROM statement */ public Stream<JoinVariableNode> getAstJoinVariableNodes() { return generateChildrenByClass(getAstFromNode(), SelectionSourceNode.class) .flatMap(selectionSource -> generateChildrenByClass(selectionSource, JoinVariableNode.class)); }
/** * @return returns list of identification variable nodes (entityName entityAlias) from FROM statement */ public Stream<IdentificationVariableNode> getAstIdentificationVariableNodes() { return generateChildrenByClass(getAstFromNode(), SelectionSourceNode.class) .flatMap(selectionSource -> generateChildrenByClass(selectionSource, IdentificationVariableNode.class)); }
public void addSelectionSource(CommonTree selectionSource) { CommonTree from = queryTree.getAstFromNode(); from.addChild(selectionSource); from.freshenParentAndChildIndexes(); }
public void addFirstSelectionSource(CommonTree selectionSource) { CommonTree from = queryTree.getAstFromNode(); from.insertChild(0, selectionSource); from.freshenParentAndChildIndexes(); }
public void mixinJoinIntoTree(CommonTree joinClause, EntityReference entityReference, boolean renameVariable) { CommonTree from = queryTree.getAstFromNode(); for (int i = 0; i < from.getChildCount(); i++) { SelectionSourceNode selectionSource = (SelectionSourceNode) from.getChild(i); if (selectionSource.getChild(0) instanceof IdentificationVariableNode) { IdentificationVariableNode identificationVariable = (IdentificationVariableNode) selectionSource.getChild(0); if (entityReference.supportsJoinTo(identificationVariable)) { String variableName = identificationVariable.getVariableName(); JoinVariableNode joinNode = (JoinVariableNode) joinClause; if (hasJoinNode(joinNode, selectionSource)) { return; } if (renameVariable) { PathNode path = joinNode.findPathNode(); if (path != null) { path.renameVariableTo(variableName); } } selectionSource.addChild(joinClause); from.freshenParentAndChildIndexes(); return; } } } throw new RuntimeException("Join mixing failed. Cannot find selected entity with name " + entityReference); }
joinNode.addChild(joinPathNode); CommonTree from = queryTree.getAstFromNode(); from.getChild(0).addChild(joinNode); // assumption addedJoinVariables.add(joinPathNodeVariableName);
if (sourceWhere == null) { CommonTree tree = queryTree.getAstTree(); CommonTree fromNode = queryTree.getAstFromNode();