@Override public Collection<FieldUpdate> fieldUpdates() { return docU.fieldUpdates(); } @Override
@Override public void write(DocumentUpdate update) { putShort(null, Document.SERIALIZED_VERSION); update.getId().serialize(this); byte contents = 0x1; // Legacy to say we have document type putByte(null, contents); update.getDocumentType().serialize(this); putInt(null, update.fieldUpdates().size()); for (FieldUpdate up : update.fieldUpdates()) { up.serialize(this); } }
/** * 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 void write(DocumentUpdate update) { wrapIOException(() -> { generator.writeStartObject(); generator.writeStringField("update", update.getId().toString()); if (update.getCondition().isPresent()) { generator.writeStringField("condition", update.getCondition().getSelection()); } Optional<Boolean> createIfNotExistent = update.getOptionalCreateIfNonExistent(); if (createIfNotExistent.isPresent()) { generator.writeBooleanField("create", createIfNotExistent.get()); } generator.writeObjectFieldStart("fields"); for (FieldUpdate up : update.fieldUpdates()) { up.serialize(this); } update.fieldPathUpdates().stream() .collect(Collectors.groupingBy(FieldPathUpdate::getFieldPath)) .forEach((fieldPath, fieldPathUpdates) -> wrapIOException(() -> write(fieldPath, fieldPathUpdates, generator))); generator.writeEndObject(); generator.writeEndObject(); generator.flush(); }); }
@Override public void write(DocumentUpdate update) { update.getId().serialize(this); update.getDocumentType().serialize(this); putInt(null, update.fieldUpdates().size()); for (FieldUpdate up : update.fieldUpdates()) { up.serialize(this); } DocumentUpdateFlags flags = new DocumentUpdateFlags(); flags.setCreateIfNonExistent(update.getCreateIfNonExistent()); putInt(null, flags.injectInto(update.fieldPathUpdates().size())); for (FieldPathUpdate up : update.fieldPathUpdates()) { up.serialize(this); } }
for (FieldUpdate fieldUpd : upd.fieldUpdates()) { Field field = fieldUpd.getField(); for (ValueUpdate valueUpd : fieldUpd.getValueUpdates()) {