@Nullable public IdentificationVariableNode getMainIdentificationVariableNode() { List<IdentificationVariableNode> identificationVariables = queryTree.getAstIdentificationVariableNodes() .collect(Collectors.toList()); Optional<String> variableName = queryTree.getAstSelectedPathNodes().findFirst().map(PathNode::getEntityVariableName); if (variableName.isPresent()) { for (IdentificationVariableNode node : identificationVariables) { if (variableName.get().equalsIgnoreCase(node.getVariableName())) { return node; } } } return identificationVariables.stream().findFirst().orElse(null); }
@Override public boolean supportsJoinTo(IdentificationVariableNode node) { return pathStartingEntityName.equals(node.getEffectiveEntityName()) && pathNode.getEntityVariableName().equals(node.getVariableName()); }
public String getMainEntityVariable(IdentificationVariableNode identificationVariable) { if (identificationVariable == null) { throw new RuntimeException(format("Unable to find entity variable [%s]", StringUtils.strip(queryTree.getQueryString()))); } return identificationVariable.getVariableName(); }
@Override public boolean isEntitySelect(String targetEntity) { PathNode pathNode = getAnalyzer().getMainSelectedPathNode(); IdentificationVariableNode identificationVariable = getAnalyzer().getMainIdentificationVariableNode(); if (pathNode != null && identificationVariable != null) { return queryAnalyzer.isVariablePathNode(pathNode) && StringUtils.equalsIgnoreCase(identificationVariable.getVariableName(), pathNode.getEntityVariableName()) && Objects.equals(identificationVariable.getEntityNameFromQuery(), targetEntity); } return false; }
@Override public boolean hasIsNullCondition(String attribute) { IdentificationVariableNode identificationVariable = getAnalyzer().getMainIdentificationVariableNode(); if (identificationVariable != null) { String variableName = identificationVariable.getVariableName(); return queryTree.visit(NodesFinder.of(SimpleConditionNode.class)).getFoundNodes().stream() .filter(condition -> getAnalyzer().isConditionForEntityProperty(condition, variableName, attribute)) .anyMatch(condition -> getAnalyzer().isConditionISNULL(condition)); } return false; }
String variableName = getVariableName();
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); }
JpqlEntityModel entity = variableContext.getEntityByVariableName(pathNode.getEntityVariableName()); if (entity != null && entity.getName() != null && identificationVariable != null) { if (!StringUtils.equalsIgnoreCase(pathNode.getEntityVariableName(), identificationVariable.getVariableName())) { return new EntityNameAndPath(entity.getName(), pathNode.getEntityVariableName());