@Override public ModificationStatus iterateNested(FieldPath fieldPath, int pos, FieldPathIteratorHandler handler) { return doc.iterateNested(fieldPath, pos, handler); }
public void applyTo(Document doc) { if (selector == null) { FieldPathIteratorHandler handler = getIteratorHandler(doc); doc.iterateNested(fieldPath, 0, handler); } else { ResultList results = selector.getMatchingResultList(new DocumentPut(doc)); ListIterator<ResultList.ResultPair> resultIter = results.getResults().listIterator(results.getResults().size()); while (resultIter.hasPrevious()) { ResultList.ResultPair rp = resultIter.previous(); if (rp.getResult() == Result.TRUE) { FieldPathIteratorHandler handler = getIteratorHandler(doc); handler.getVariables().clear(); handler.getVariables().putAll(rp.getVariables()); doc.iterateNested(fieldPath, 0, handler); } } } }
private static Object evaluateFieldPath(String fieldPth, Object value) { if (value instanceof DocumentPut) { final Document doc = ((DocumentPut) value).getDocument(); FieldPath fieldPath = doc.getDataType().buildFieldPath(fieldPth); IteratorHandler handler = new IteratorHandler(); doc.iterateNested(fieldPath, 0, handler); if (handler.values.isEmpty()) { return null; } return handler.values; } else if (value instanceof DocumentUpdate) { return Result.INVALID; } else if (value instanceof DocumentRemove) { return Result.INVALID; } else if (value instanceof DocumentGet) { return Result.INVALID; } return Result.FALSE; }
public static void applyUpdate(FieldPathUpdate update, Document doc) { if (update instanceof AddFieldPathUpdate) { update.applyTo(doc); } else if (update instanceof AssignFieldPathUpdate) { AssignFieldPathUpdate assign = (AssignFieldPathUpdate)update; boolean createMissingPath = assign.getCreateMissingPath(); boolean removeIfZero = assign.getRemoveIfZero(); assign.setCreateMissingPath(true); assign.setRemoveIfZero(false); assign.applyTo(doc); assign.setCreateMissingPath(createMissingPath); assign.setRemoveIfZero(removeIfZero); } else if (update instanceof RemoveFieldPathUpdate) { doc.iterateNested(update.getFieldPath(), 0, new MyHandler()); } }