@Override public DocumentId getId() { return docU.getId(); }
@Override public boolean update(DocumentUpdate update) { Document document = access.documents.get(update.getId()); if (document == null) { return false; } update.applyTo(document); return true; }
@Override public boolean update(DocumentUpdate update, DocumentProtocol.Priority pri) { Document document = access.documents.get(update.getId()); if (document == null) { return false; } update.applyTo(document); return true; }
@Override public long getSequenceId() { deserialize(); return Arrays.hashCode(update.getId().getGlobalId()); }
public ProxyDocumentUpdate(DocumentUpdate docUpd, Map<String, String> fieldMap) { super(docUpd.getType(), docUpd.getId().toString()+"-schemamappedupdate"); this.docU=docUpd; this.fieldMap=fieldMap; }
@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(); }); }
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 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); } }
@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); } }
@SuppressWarnings("deprecation") private BucketId getBucketId(Message msg) { switch (msg.getType()) { case DocumentProtocol.MESSAGE_PUTDOCUMENT: return factory.getBucketId(((PutDocumentMessage)msg).getDocumentPut().getDocument().getId()); case DocumentProtocol.MESSAGE_GETDOCUMENT: return factory.getBucketId(((GetDocumentMessage)msg).getDocumentId()); case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: return factory.getBucketId(((RemoveDocumentMessage)msg).getDocumentId()); case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: return factory.getBucketId(((UpdateDocumentMessage)msg).getDocumentUpdate().getId()); case DocumentProtocol.MESSAGE_GETBUCKETLIST: return ((GetBucketListMessage)msg).getBucketId(); case DocumentProtocol.MESSAGE_STATBUCKET: return ((StatBucketMessage)msg).getBucketId(); case DocumentProtocol.MESSAGE_CREATEVISITOR: return ((CreateVisitorMessage)msg).getBuckets().get(0); case DocumentProtocol.MESSAGE_REMOVELOCATION: return ((RemoveLocationMessage)msg).getBucketId(); default: log.log(LogLevel.ERROR, "Message type '" + msg.getType() + "' not supported."); return null; } }
@Override public UpdateResult update(Bucket bucket, long timestamp, DocumentUpdate update) { GetResult result = get(bucket, new AllFields(), update.getId()); if (result.wasFound()) { Document doc = result.getDocument().clone(); update.applyTo(doc); put(bucket, timestamp, doc); return new UpdateResult(result.getLastModifiedTimestamp()); } else { return new UpdateResult(); } } }
public void readUpdate(TokenBuffer buffer, DocumentUpdate update) { if (buffer.isEmpty()) throw new IllegalArgumentException("update of document " + update.getId() + " is missing a 'fields' map"); expectObjectStart(buffer.currentToken()); int localNesting = buffer.nesting(); buffer.next(); while (localNesting <= buffer.nesting()) { expectObjectStart(buffer.currentToken()); String fieldName = buffer.currentName(); if (isFieldPath(fieldName)) { addFieldPathUpdates(update, buffer, fieldName); } else { addFieldUpdates(update, buffer, fieldName); } expectObjectEnd(buffer.currentToken()); buffer.next(); } }