public OResult serialize() { OResultInternal result = new OResultInternal(); result.setProperty("value", value); return result; }
private Object toResult(OIdentifiable nextElement) { OResultInternal result = new OResultInternal(); result.setElement(nextElement); return result; }
@Override public OResult next() { Object val = iterator.next(); if (val instanceof OResult) { return (OResult) val; } OResultInternal result = new OResultInternal(); if (val instanceof OIdentifiable) { result.setElement((OIdentifiable) val); } else { result.setProperty("value", val); } return result; }
public OResult next(OCommandContext ctx) { init(ctx); if (!downstream.hasNext()) { throw new IllegalStateException(); } String endPointAlias = getEndpointAlias(); OResultInternal nextR = downstream.next(); OIdentifiable nextElement = nextR.getElement().get(); Object prevValue = sourceRecord.getProperty(endPointAlias); if (prevValue != null && !equals(prevValue, nextElement)) { return null; } OResultInternal result = new OResultInternal(); for (String prop : sourceRecord.getPropertyNames()) { result.setProperty(prop, sourceRecord.getProperty(prop)); } result.setProperty(endPointAlias, toResult(nextElement)); if (edge.edge.item.getFilter().getDepthAlias() != null) { result.setProperty(edge.edge.item.getFilter().getDepthAlias(), nextR.getMetadata("$depth")); } if (edge.edge.item.getFilter().getPathAlias() != null) { result.setProperty(edge.edge.item.getFilter().getPathAlias(), nextR.getMetadata("$matchPath")); } return result; }
@Override public OResult serialize() { OResultInternal result = OExecutionStepInternal.basicSerialize(this); result.setProperty("className", className); result.setProperty("orderByRidAsc", orderByRidAsc); result.setProperty("orderByRidDesc", orderByRidDesc); return result; }
public OResult next(OCommandContext ctx) { init(ctx); if (!downstream.hasNext()) { throw new IllegalStateException(); } String endPointAlias = getEndpointAlias(); Object prevValue = sourceRecord.getProperty(endPointAlias); OResultInternal next = downstream.next(); if (isEmptyOptional(prevValue)) { return sourceRecord; } if (!isEmptyOptional(next)) { if (prevValue != null && !equals(prevValue, next.getElement().get())) { return null; } } OResultInternal result = new OResultInternal(); for (String prop : sourceRecord.getPropertyNames()) { result.setProperty(prop, sourceRecord.getProperty(prop)); } result.setProperty(endPointAlias, next.getElement().map(x -> toResult(x)).orElse(null)); return result; }
private OResultInternal toOResultInternal(Object x) { if (x instanceof OResultInternal) { return (OResultInternal) x; } if (x instanceof OIdentifiable) { return new OResultInternal((OIdentifiable) x); } throw new OCommandExecutionException("Cannot execute traversal on " + x); } }
@Override public OElement toElement() { if (isElement()) { return getElement().get(); for (String s : getPropertyNames()) { if (s == null) { continue; } else if (s.equalsIgnoreCase("@rid")) { Object newRid = getProperty(s); if (newRid instanceof OIdentifiable) { newRid = ((OIdentifiable) newRid).getIdentity(); oldId.setClusterPosition(((ORID) newRid).getClusterPosition()); } else if (s.equalsIgnoreCase("@version")) { Object v = getProperty(s); if (v instanceof Number) { ORecordInternal.setVersion(doc, ((Number) v).intValue()); doc.setClassName(getProperty(s)); } else { doc.setProperty(s, convertToElement(getProperty(s)));
private Object initSchemafullCollections(OResultInternal doc, String propName) { OClass oClass = doc.getElement().flatMap(x -> x.getSchemaType()).orElse(null); if (oClass == null) { return null; } OProperty prop = oClass.getProperty(propName); if (prop == null) { return null; } Object result = null; if (prop.getType() == OType.EMBEDDEDMAP || prop.getType() == OType.LINKMAP) { result = new HashMap<>(); doc.setProperty(propName, result); } else if (prop.getType() == OType.EMBEDDEDLIST || prop.getType() == OType.LINKLIST) { result = new ArrayList<>(); doc.setProperty(propName, result); } else if (prop.getType() == OType.EMBEDDEDSET || prop.getType() == OType.LINKSET) { result = new HashSet<>(); doc.setProperty(propName, result); } return result; }
@Override public OResult next() { OResult result = upstream.next(); if (result instanceof OResultInternal) { if (!(result.getElement().orElse(null) instanceof ODocument)) { ((OResultInternal) result).setElement(result.getElement().get().getRecord()); } if (!(result.getElement().orElse(null) instanceof ODocument)) { return result; } handleMerge((ODocument) result.getElement().orElse(null), ctx); } return result; }
if (iRecord.type == ORecordOperation.UPDATED) { OResultInternal before = copy(iRecord.before); record.setMetadata(BEFORE_METADATA_KEY, before); record.setMetadata(BEFORE_METADATA_KEY, record); switch (iRecord.type) { case ORecordOperation.DELETED: record.setMetadata(BEFORE_METADATA_KEY, null); clientListener.onDelete(execDb, record); break; case ORecordOperation.UPDATED: OResult before = (OResult) record.getMetadata(BEFORE_METADATA_KEY); record.setMetadata(BEFORE_METADATA_KEY, null); clientListener.onUpdate(execDb, before, record); break;
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof OResultInternal)) { return false; } OResultInternal resultObj = (OResultInternal) obj; if (element != null) { if (!resultObj.getElement().isPresent()) { return false; } return element.equals(resultObj.getElement().get()); } else { if (resultObj.getElement().isPresent()) { return false; } return this.content.equals(resultObj.content); } }
private Object convertToElement(Object property) { if (property instanceof OResult) { return ((OResult) property).toElement(); } if (property instanceof List) { return ((List) property).stream().map(x -> convertToElement(x)).collect(Collectors.toList()); } if (property instanceof Set) { return ((Set) property).stream().map(x -> convertToElement(x)).collect(Collectors.toSet()); } if (property instanceof Map) { Map<Object, Object> result = new HashMap<>(); Map<Object, Object> prop = ((Map) property); for (Map.Entry<Object, Object> o : prop.entrySet()) { result.put(o.getKey(), convertToElement(o.getValue())); } } return property; }
public void setElement(OIdentifiable element) { if (element instanceof OElement) { this.element = element; } else if (element instanceof OIdentifiable) { this.element = element.getRecord(); } else { this.element = element; } if (element instanceof OContextualRecordId) { this.addMetadata(((OContextualRecordId) element).getContext()); } }
private void fetchNext(OCommandContext ctx) { this.nextResult = null; while (true) { while (currentIterator == null || !currentIterator.hasNext()) { if (!clusterIterators.hasNext()) { return; } currentIterator = clusterIterators.next(); } ORecord rec = currentIterator.next(); if (rec instanceof ODocument) { OResultInternal x = new OResultInternal(); x.setElement(rec); for (ORID rid : ridsToFind) { List<String> resultForRecord = checkObject(Collections.singleton(rid), x, rec, ""); if (resultForRecord.size() > 0) { nextResult = new OResultInternal(); nextResult.setProperty("rid", rid); nextResult.setProperty("referredBy", rec); nextResult.setProperty("fields", resultForRecord); return; } } } } }
@Override public OResult serialize() { OResultInternal result = OExecutionStepInternal.basicSerialize(this); result.setProperty("clusterId", clusterId); result.setProperty("order", order); return result; }
protected void init(OCommandContext ctx) { if (!this.inited) { Object val = source.execute(new OResultInternal(), ctx); this.iterator = OMultiValue.getMultiValueIterator(val); this.inited = true; } }
@Override public OResult next() { OResult result = upstream.next(); if (result instanceof OResultInternal) { if (!(result.getElement().get() instanceof OElement)) { ((OResultInternal) result).setElement(result.getElement().get().getRecord()); } if (!(result.getElement().get() instanceof OElement)) { return result; } handleContent((OElement) result.getElement().get(), ctx); } return result; }
public OResult serialize() { OResultInternal result = new OResultInternal(); result.setProperty("value", value); return result; }
protected Object toResult(OIdentifiable nextElement) { OResultInternal result = new OResultInternal(); result.setElement(nextElement); return result; }