@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); } }
public void addFieldUpdates(Collection<FieldUpdate> fieldUpdates) { for (FieldUpdate fieldUpdate : fieldUpdates) { addFieldUpdate(fieldUpdate); } }
/** * 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); } }
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)); } }
@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); } }
@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 DocumentId getId() { return docU.getId(); }
public void read(DocumentUpdate update) { short serializationVersion = getShort(null); update.setId(new DocumentId(this)); byte contents = getByte(null); if ((contents & 0x1) == 0) { throw new DeserializationException("Cannot deserialize DocumentUpdate without doctype"); } update.setDocumentType(readDocumentType()); int size = getInt(null); for (int i = 0; i < size; i++) { update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), serializationVersion)); } }
static DocumentOperationMessageV3 newUpdateMessage(VespaXMLFeedReader.Operation op, String operationId) { DocumentUpdate update = op.getDocumentUpdate(); update.setCondition(op.getCondition()); Message msg = new UpdateDocumentMessage(update); String id = (operationId == null) ? update.getId().toString() : operationId; return new DocumentOperationMessageV3(id, msg); }
@Override public DocumentUpdate getOutput() { Document doc = adapter.getUpdatableOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); for (Iterator<Map.Entry<Field, FieldValue>> it = doc.iterator(); it.hasNext();) { Map.Entry<Field, FieldValue> entry = it.next(); Field field = entry.getKey(); if (field.getName().equals("sddocname")) { continue; } FieldUpdate fieldUpd = FieldUpdate.create(field); fieldUpd.addValueUpdates(builder.build(entry.getValue())); if (!fieldUpd.isEmpty()) { upd.addFieldUpdate(fieldUpd); } } return upd.isEmpty() ? null : upd; }
DocumentUpdate update = new DocumentUpdate(docType, doc1.getId()); FieldUpdate fieldUpdate = FieldUpdate.create(docType.getField("headerval")); fieldUpdate.addValueUpdate(AssignValueUpdate.createAssign(new IntegerFieldValue(42))); update.addFieldUpdate(fieldUpdate);
@Override public DocumentUpdate getOutput() { Document doc = adapter.getFullOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); createUpdatesAt(new ArrayList<>(), adapter.getUpdatableOutput(), 0, upd); return upd; }
@Override public DocumentType getDocumentType() { return docU.getDocumentType(); }
FieldUpdate readAlter(DocumentUpdate update) throws XMLStreamException { Field f = null; for (int i = 0; i < reader.getAttributeCount(); i++) { if ("field".equals(reader.getAttributeName(i).toString())) { f = update.getDocumentType().getField(reader.getAttributeValue(i)); } } if (f == null) { throw newDeserializeException("Alter update without \"field\" attribute"); } FieldUpdate fu = FieldUpdate.create(f); while (reader.hasNext()) { int type = reader.next(); if (type == XMLStreamReader.START_ELEMENT) { if ("increment".equals(reader.getName().toString()) || "decrement".equals(reader.getName().toString()) || "multiply".equals(reader.getName().toString()) || "divide".equals(reader.getName().toString())) { update.addFieldUpdate(readArithmetic(update, reader.getName().toString(), f, fu)); skipToEnd(reader.getName().toString()); } else { throw newDeserializeException("Element \"" + reader.getName() + "\" not appropriate within alter element"); } } else if (type == XMLStreamReader.END_ELEMENT) { break; } } return fu; }
break; case UPDATE: documentOperation = new DocumentUpdate(documentType, documentParseInfo.documentId); readUpdate(documentParseInfo.fieldsBuffer, (DocumentUpdate) documentOperation); verifyEndState(documentParseInfo.fieldsBuffer, JsonToken.END_OBJECT); update.setCreateIfNonExistent(documentParseInfo.create.get());
public static DocumentUpdate execute(Expression expression, AdapterFactory factory, DocumentUpdate update) { DocumentUpdate ret = null; for (UpdateAdapter adapter : factory.newUpdateAdapterList(update)) { DocumentUpdate output = adapter.getExpression(expression).execute(adapter); if (output == null) { // ignore } else if (ret != null) { ret.addAll(output); } else { ret = output; } } if (ret != null) { ret.setCreateIfNonExistent(update.getCreateIfNonExistent()); } return ret; }
@Override public DocumentUpdate getOutput() { Document doc = fwdAdapter.getFullOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); upd.addFieldPathUpdate(update); return upd; }
private VespaXMLFeedReader.Operation createUpdateOperation(HttpRequest request, String id, String condition, Optional<Boolean> create) { final VespaXMLFeedReader.Operation operationUpdate = singleDocumentParser.parseUpdate(request.getData(), id); if (condition != null && ! condition.isEmpty()) { operationUpdate.getDocumentUpdate().setCondition(new TestAndSetCondition(condition)); } create.ifPresent(c -> operationUpdate.getDocumentUpdate().setCreateIfNonExistent(c)); return operationUpdate; }