public Set<String> getUsedVariableNames() { Set<String> result = new HashSet<>(); for (PathNode variableUse : variableUses) { result.add(variableUse.getEntityVariableName()); } return result; }
public String getVariableNameInUse(int index) { return variableUses.get(index).getEntityVariableName(); }
public void renameVariable(String origName, EntityReference newName) { if (origName == null) throw new NullPointerException("No original name passed"); if (newName == null) throw new NullPointerException("No new name passed"); for (PathNode variableUse : variableUses) { if (origName.equals(variableUse.getEntityVariableName())) { newName.renameVariableIn(variableUse); } } } }
public String getMainSelectedEntityVariable(PathNode pathNode) { if (pathNode == null) { throw new RuntimeException(format("Unable to find selected entity variable [%s]", StringUtils.strip(queryTree.getQueryString()))); } return pathNode.getEntityVariableName(); }
@Override public boolean supportsJoinTo(IdentificationVariableNode node) { return pathStartingEntityName.equals(node.getEffectiveEntityName()) && pathNode.getEntityVariableName().equals(node.getVariableName()); }
public String getMainSelectedEntityName(PathNode pathNode) { if (pathNode == null) { throw new RuntimeException(format("Unable to find selected entity name [%s]", StringUtils.strip(queryTree.getQueryString()))); } QueryVariableContext variableContext = queryTree.getQueryVariableContext(); JpqlEntityModel entity = variableContext.getEntityByVariableName(pathNode.getEntityVariableName()); if (entity == null) { throw new RuntimeException(format("Unable to find selected entity name [%s]", StringUtils.strip(queryTree.getQueryString()))); } return entity.getName(); }
@Override public void renameVariableIn(PathNode node) { node.renameVariableTo(pathNode.getEntityVariableName()); List newChildren = new ArrayList(pathNode.dupNode().getChildren()); while (node.getChildCount() > 0) { newChildren.add(node.deleteChild(0)); } node.addChildren(newChildren); }
@Override public List<QueryPath> getQueryPaths() { List<QueryPath> queryPaths = new ArrayList<>(); QueryVariableContext variableContext = getTree().getQueryVariableContext(); PathNodeFinder finder = getTree().visit(new PathNodeFinder()); for (PathNode node : finder.getSelectedPathNodes()) { JpqlEntityModel model = variableContext.getEntityByVariableNameHierarchically(node.getEntityVariableName()); QueryPath queryPath = new QueryPath(model.getName(), node.getEntityVariableName(), node.asPathString(), true); queryPaths.add(queryPath); } for (PathNode node : finder.getOtherPathNodes()) { JpqlEntityModel model = variableContext.getEntityByVariableNameHierarchically(node.getEntityVariableName()); QueryPath queryPath = new QueryPath(model.getName(), node.getEntityVariableName(), node.asPathString(), false); queryPaths.add(queryPath); } return queryPaths; }
@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; }
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()); boolean collectionSelect = false; try { entity = variableContext.getEntityByVariableName(pathNode.getEntityVariableName()); if (entity != null) { entityPath = pathNode.asPathString();
DomainModel model = queryTree.getModel(); JpqlEntityModel entity = model.getEntityByName(entityName); String currentVariableName = pathNode.getEntityVariableName(); PathNode currentPathNode = new PathNode(pathNode.getToken(), currentVariableName); for (int i = 0; i < pathNode.getChildCount(); i++) {