public Stream<PathNode> getAstSelectedPathNodes() { SelectedItemsNode selectedItems = getAstSelectedItemsNode(); if (selectedItems != null) { return generateChildrenByClass(selectedItems, SelectedItemNode.class) .flatMap(selectedItemNode -> generateChildrenByClass(selectedItemNode, PathNode.class)); } return Stream.empty(); }
public boolean removeDistinct() { Tree selectedItems = queryTree.getAstSelectedItemsNode(); boolean isDistinct = "distinct".equalsIgnoreCase(selectedItems.getChild(0).getText()); if (isDistinct) { selectedItems.deleteChild(0); selectedItems.freshenParentAndChildIndexes(); } else { return false; } return true; }
public void addDistinct() { CommonTree selectedItems = queryTree.getAstSelectedItemsNode(); boolean isDistinct = "distinct".equalsIgnoreCase(selectedItems.getChild(0).getText()); if (!isDistinct) { selectedItems.insertChild(0, new CommonTree(new CommonToken(JPA2Lexer.DISTINCT, "distinct"))); selectedItems.freshenParentAndChildIndexes(); } }
public void replaceWithCount(Tree node) { Tree selectedItems = queryTree.getAstSelectedItemsNode(); boolean isDistinct = "distinct".equalsIgnoreCase(selectedItems.getChild(0).getText()); if (!(isDistinct && selectedItems.getChildCount() == 2 || selectedItems.getChildCount() == 1)) throw new IllegalStateException("Cannot replace with count if multiple fields selected"); SelectedItemNode selectedItemNode; if (isDistinct) selectedItems.deleteChild(0); selectedItemNode = (SelectedItemNode) selectedItems.getChild(0); AggregateExpressionNode countNode = createCountNode(node, isDistinct); selectedItemNode.deleteChild(0); selectedItemNode.addChild(countNode); Tree orderBy = queryTree.getAstTree().getFirstChildWithType(JPA2Lexer.T_ORDER_BY); if (orderBy != null) { queryTree.getAstTree().deleteChild(orderBy.getChildIndex()); } queryTree.getAstTree().freshenParentAndChildIndexes(); }