@Override public Tree dupNode() { JoinVariableNode result = new JoinVariableNode(token, joinSpec, variableName); dupChildren(result); return result; }
protected boolean hasJoinNode(JoinVariableNode joinNode, SelectionSourceNode selectionSource) { JoinVariableNode existingJoinNode = selectionSource.getChildren().stream() .filter(e -> e instanceof JoinVariableNode) .map(e -> (JoinVariableNode) e) .filter(e -> Objects.equals(e.getVariableName(), joinNode.getVariableName())) .findFirst().orElse(null); if (existingJoinNode != null) { PathNode existingPathNode = existingJoinNode.findPathNode(); PathNode pathNode = joinNode.findPathNode(); if (existingPathNode != null && pathNode != null) { if (Objects.equals(existingPathNode.asPathString(), pathNode.asPathString())) { return true; } } } return false; }
@Nullable public PathNode findPathNode() { for (Object child : getChildren()) { if (child instanceof PathNode) { return (PathNode) child; } } return null; }
@Override public CommonTree treeToQueryPre(QueryBuilder sb, List<ErrorRec> invalidNodes) { int childCount = getChildCount(); if (childCount == 0) { invalidNodes.add(new ErrorRec(this, "No children found")); return null; } sb.appendSpace(); sb.appendString(joinSpec); sb.appendSpace(); sb.appendString(toQuery(getChild(0))); sb.appendSpace(); sb.appendString(variableName); if (childCount > 1) { sb.appendSpace(); sb.appendString("on"); for (int idx = 1; idx < childCount; idx++) { sb.appendSpace(); sb.appendString(toQuery(getChild(idx))); } } return null; }
String joinPathNodeVariableName = joinPathNode.asPathString('_'); if (!addedJoinVariables.contains(joinPathNodeVariableName)) { JoinVariableNode joinNode = new JoinVariableNode(JPA2Lexer.T_JOIN_VAR, "left join", joinPathNodeVariableName); joinNode.addChild(joinPathNode);
protected void resolveEntityNames(Set<String> entityNames, JoinVariableNode node, DomainModel model, QueryVariableContext queryVariableContext) { JpqlEntityModel entityModel = queryVariableContext.getEntityByVariableName(node.getVariableName()); if (entityModel != null) { entityNames.add(entityModel.getName()); } } }
@Override public Object post(Object t) { if (!(t instanceof CommonTree)) return t; if (t instanceof CommonErrorNode) { return t; } CommonTree node = (CommonTree) t; if (node.token == null) return t; if ((node instanceof QueryNode) && node.getParent() != null && "T_CONDITION".equals(((CommonTree) node.getParent()).token.getText())) { stack.peekLast().setPropagateVariablesUp(false); return t; } if (node instanceof IdentificationVariableNode) { IdentificationVariableNode vnode = (IdentificationVariableNode) node; vnode.identifyVariableEntity(model, stack, invalidIdVarNodes); return t; } if (node instanceof JoinVariableNode) { JoinVariableNode vnode = (JoinVariableNode) node; vnode.identifyVariableEntity(model, stack, invalidIdVarNodes); return t; } return t; }
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); }
root_1 = (Object)adaptor.becomeRoot(new JoinVariableNode(T_JOIN_VAR, (join_spec28!=null?input.toString(join_spec28.start,join_spec28.stop):null), (identification_variable31!=null?input.toString(identification_variable31.start,identification_variable31.stop):null)), root_1); adaptor.addChild(root_1, stream_join_association_path_expression.nextTree());