@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof DocumentUpdate)) return false; DocumentUpdate that = (DocumentUpdate) o; if (docId != null ? !docId.equals(that.docId) : that.docId != null) return false; if (documentType != null ? !documentType.equals(that.documentType) : that.documentType != null) return false; if (!fieldPathUpdates.equals(that.fieldPathUpdates)) return false; if (!id2FieldUpdates.equals(that.id2FieldUpdates)) return false; if (this.getCreateIfNonExistent() != ((DocumentUpdate) o).getCreateIfNonExistent()) return false; return true; }
@Override public String toString() { StringBuilder string = new StringBuilder(); string.append("update of document '"); string.append(docId); string.append("': "); string.append("create-if-non-existent="); string.append(getCreateIfNonExistent()); string.append(": "); string.append("["); for (FieldUpdate fieldUpdate : id2FieldUpdates.values()) { string.append(fieldUpdate).append(" "); } string.append("]"); if (fieldPathUpdates.size() > 0) { string.append(" [ "); for (FieldPathUpdate up : fieldPathUpdates) { string.append(up.toString()).append(" "); } string.append(" ]"); } return string.toString(); }
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 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); } }