/** * Adds all the field- and field path updates of the given document update to this. If the given update refers to a * different document or document type than this, this method throws an exception. * * @param update The update whose content to add to this. * @throws IllegalArgumentException If the {@link DocumentId} or {@link DocumentType} of the given DocumentUpdate * does not match the content of this. */ public void addAll(DocumentUpdate update) { if (update == null) { return; } if (!docId.equals(update.docId)) { throw new IllegalArgumentException("Expected " + docId + ", got " + update.docId + "."); } if (!documentType.equals(update.documentType)) { throw new IllegalArgumentException("Expected " + documentType + ", got " + update.documentType + "."); } addFieldUpdates(update.fieldUpdates()); for (FieldPathUpdate pathUpd : update.fieldPathUpdates) { addFieldPathUpdate(pathUpd); } }
@Override public DocumentUpdate getOutput() { Document doc = fwdAdapter.getFullOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); upd.addFieldPathUpdate(update); return upd; }
private void addFieldPathUpdates(DocumentUpdate update, TokenBuffer buffer, String fieldPath) { int localNesting = buffer.nesting(); buffer.next(); while (localNesting <= buffer.nesting()) { String fieldPathOperation = buffer.currentName().toLowerCase(); FieldPathUpdate fieldPathUpdate; if (fieldPathOperation.equals(UPDATE_ASSIGN)) { fieldPathUpdate = readAssignFieldPathUpdate(update.getType(), fieldPath, buffer); } else if (fieldPathOperation.equals(UPDATE_ADD)) { fieldPathUpdate = readAddFieldPathUpdate(update.getType(), fieldPath, buffer); } else if (fieldPathOperation.equals(UPDATE_REMOVE)) { fieldPathUpdate = readRemoveFieldPathUpdate(update.getType(), fieldPath, buffer); } else if (SingleValueReader.UPDATE_OPERATION_TO_ARITHMETIC_SIGN.containsKey(fieldPathOperation)) { fieldPathUpdate = readArithmeticFieldPathUpdate(update.getType(), fieldPath, buffer, fieldPathOperation); } else { throw new IllegalArgumentException("Field path update type '" + fieldPathOperation + "' not supported."); } update.addFieldPathUpdate(fieldPathUpdate); buffer.next(); } }
if (hasFieldPath()) { if ("assign".equals(currentName)) { update.addFieldPathUpdate(new AssignFieldPathUpdate(doctype, this)); skipToEnd("assign"); } else if ("add".equals(currentName)) { update.addFieldPathUpdate(new AddFieldPathUpdate(doctype, this)); skipToEnd("add"); } else if ("remove".equals(currentName)) { update.addFieldPathUpdate(new RemoveFieldPathUpdate(doctype, this)); skipToEnd("remove"); } else {
value.getClass().getName() + "."); out.addFieldPathUpdate(new AddFieldPathUpdate(update.getDocumentType(), new FieldPath(path).toString(), update.getOriginalWhereClause(), (Array)value)); } else if (update instanceof AssignFieldPathUpdate) { out.addFieldPathUpdate(new AssignFieldPathUpdate(update.getDocumentType(), new FieldPath(path).toString(), update.getOriginalWhereClause(), value)); } else if (update instanceof RemoveFieldPathUpdate) { out.addFieldPathUpdate(new RemoveFieldPathUpdate(update.getDocumentType(), new FieldPath(path).toString(), update.getOriginalWhereClause()));
public void read(DocumentUpdate update) { update.setId(new DocumentId(this)); update.setDocumentType(readDocumentType()); int size = getInt(null); for (int i = 0; i < size; i++) { update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), 8)); } int sizeAndFlags = getInt(null); update.setCreateIfNonExistent(DocumentUpdateFlags.extractFlags(sizeAndFlags).getCreateIfNonExistent()); size = DocumentUpdateFlags.extractValue(sizeAndFlags); for (int i = 0; i < size; i++) { int type = getByte(null); update.addFieldPathUpdate(FieldPathUpdate.create(FieldPathUpdate.Type.valueOf(type), update.getDocumentType(), this)); } }