private void addNextEntryPoints(Object nextStep, int depth, List<OIdentifiable> path, OCommandContext ctx) { if (nextStep instanceof OIdentifiable) { addNextEntryPoints(((OIdentifiable) nextStep), depth, path, ctx); } else if (nextStep instanceof Iterable) { addNextEntryPoints(((Iterable) nextStep).iterator(), depth, path, ctx); } else if (nextStep instanceof OResult) { addNextEntryPoints(((OResult) nextStep), depth, path, ctx); } }
@Override protected void fetchNextEntryPoints(OCommandContext ctx, int nRecords) { OResultSet nextN = getPrev().get().syncPull(ctx, nRecords); while (nextN.hasNext()) { while (nextN.hasNext()) { OResult item = toTraverseResult(nextN.next()); if(item != null){ List<ORID> stack = new ArrayList<>(); item.getIdentity().ifPresent(x -> stack.add(x)); ((OResultInternal) item).setMetadata("$stack", stack); List<OIdentifiable> path = new ArrayList<>(); path.add(item.getIdentity().get()); ((OResultInternal) item).setMetadata("$path", path); if (item != null && item.isElement() && !traversed.contains(item.getElement().get().getIdentity())) { tryAddEntryPoint(item, ctx); } } } nextN = getPrev().get().syncPull(ctx, nRecords); } }
private void addNextEntryPoints(OIdentifiable nextStep, int depth, List<OIdentifiable> path, OCommandContext ctx) { if (this.traversed.contains(nextStep.getIdentity())) { return; } OTraverseResult res = new OTraverseResult(); res.setElement(nextStep); res.depth = depth; res.setMetadata("$depth", depth); List<OIdentifiable> newPath = new ArrayList<>(); newPath.addAll(path); newPath.add(res.getIdentity().get()); res.setMetadata("$path", newPath); List reverseStack = new ArrayList(); reverseStack.addAll(newPath); Collections.reverse(reverseStack); List newStack = new ArrayList(); newStack.addAll(reverseStack); res.setMetadata("$stack", newStack); tryAddEntryPoint(res, ctx); }
private void handleTraversal(OSelectExecutionPlan result, OCommandContext ctx, boolean profilingEnabled) { switch (strategy) { case BREADTH_FIRST: result.chain(new BreadthFirstTraverseStep(this.projections, this.whileClause, maxDepth, ctx, profilingEnabled)); break; case DEPTH_FIRST: result.chain(new DepthFirstTraverseStep(this.projections, this.whileClause, maxDepth, ctx, profilingEnabled)); break; } //TODO }
((OTraverseResult) nextStep).setMetadata("$stack", newStack); tryAddEntryPoint(nextStep, ctx); } else { OTraverseResult res = new OTraverseResult(); ((OTraverseResult) nextStep).setMetadata("$stack", newStack); tryAddEntryPoint(res, ctx);
private void addNextEntryPoints(Iterator nextStep, int depth, List<OIdentifiable> path, OCommandContext ctx) { while (nextStep.hasNext()) { addNextEntryPoints(nextStep.next(), depth, path, ctx); } }
@Override protected void fetchNextResults(OCommandContext ctx, int nRecords) { if (!this.entryPoints.isEmpty()) { OTraverseResult item = (OTraverseResult) this.entryPoints.remove(0); this.results.add(item); for (OTraverseProjectionItem proj : projections) { Object nextStep = proj.execute(item, ctx); if (this.maxDepth == null || this.maxDepth.getValue().intValue() > item.depth) { addNextEntryPoints(nextStep, item.depth + 1, (List<OIdentifiable>) item.getMetadata("$path"), ctx); } } } }