public AbstractTraverseStep(List<OTraverseProjectionItem> projections, OWhereClause whileClause, OInteger maxDepth, OCommandContext ctx, boolean profilingEnabled) { super(ctx, profilingEnabled); this.whileClause = whileClause; this.maxDepth = maxDepth; this.projections = projections.stream().map(x -> x.copy()).collect(Collectors.toList()); }
@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); } } } }
public Object execute(OResult iCurrentRecord, OCommandContext ctx) { if (isStar()) { return handleStar(iCurrentRecord, ctx); } Object result = base.execute(iCurrentRecord, ctx); if (modifier != null) { result = modifier.execute(iCurrentRecord, result, ctx); } return result; }
private Object handleStar(OResult iCurrentRecord, OCommandContext ctx) { Set<Object> result = new HashSet<>(); for (String prop : iCurrentRecord.getPropertyNames()) { Object val = iCurrentRecord.getProperty(prop); if (isOResult(val) || isValidIdentifiable(val)) { result.add(val); } else { if (val instanceof Iterable) { val = ((Iterable) val).iterator(); } if (val instanceof Iterator) { while (((Iterator) val).hasNext()) { Object sub = ((Iterator) val).next(); if (isOResult(sub) || isValidIdentifiable(sub)) { result.add(sub); } } } else if (val instanceof OResultSet) { while (((OResultSet) val).hasNext()) { result.add(((OResultSet) val).next()); } } } } return result; }
final public OTraverseProjectionItem TraverseProjectionItem() throws ParseException { OTraverseProjectionItem jjtn000 = new OTraverseProjectionItem(JJTTRAVERSEPROJECTIONITEM); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { jjtn000.base = BaseIdentifier(); jjtn000.jjtSetLastToken(getToken(0)); {if (true) return jjtn000;} } catch (Throwable jjte000) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
public boolean refersToParent() { if (projections != null && projections.stream().anyMatch(x -> x.refersToParent())) { return true; } if (this.target != null && this.target.refersToParent()) { return true; } if (this.whileClause != null && this.whileClause.refersToParent()) { return true; } return false; }
public OTraverseProjectionItem copy() { OTraverseProjectionItem result = new OTraverseProjectionItem(-1); result.base = base == null ? null : base.copy(); result.modifier = modifier == null ? null : modifier.copy(); return result; }
@Override public OStatement copy() { OTraverseStatement result = new OTraverseStatement(-1); result.projections = projections == null ? null : projections.stream().map(x -> x.copy()).collect(Collectors.toList()); result.target = target == null ? null : target.copy(); result.whileClause = whileClause == null ? null : whileClause.copy(); result.limit = limit == null ? null : limit.copy(); result.strategy = strategy; result.maxDepth = maxDepth == null ? null : maxDepth.copy(); return result; }
@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); Integer depth = item.depth != null ? item.depth : (Integer) item.getMetadata("$depth"); if (this.maxDepth == null || this.maxDepth.getValue().intValue() > depth) { addNextEntryPoints(nextStep, depth + 1, (List) item.getMetadata("$path"), (List) item.getMetadata("$stack"), ctx); } } } }
public OTraverseExecutionPlanner(OTraverseStatement statement) { //copying the content, so that it can be manipulated and optimized this.projections = statement.getProjections() == null ? null : statement.getProjections().stream().map(x -> x.copy()).collect(Collectors.toList()); this.target = statement.getTarget(); this.whileClause = statement.getWhileClause() == null ? null : statement.getWhileClause().copy(); this.strategy = statement.getStrategy() == null ? OTraverseStatement.Strategy.DEPTH_FIRST : statement.getStrategy(); this.maxDepth = statement.getMaxDepth() == null ? null : statement.getMaxDepth().copy(); this.skip = statement.getSkip(); this.limit = statement.getLimit(); }