private void write(FieldPath fieldPath, Collection<FieldPathUpdate> fieldPathUpdates, JsonGenerator generator) throws IOException { generator.writeObjectFieldStart(fieldPath.toString()); for (FieldPathUpdate update : fieldPathUpdates) { if (writeArithmeticFieldPathUpdate(update, generator)) continue; generator.writeFieldName(update.getUpdateType().name().toLowerCase()); if (update instanceof AssignFieldPathUpdate) { AssignFieldPathUpdate assignUp = (AssignFieldPathUpdate) update; if (assignUp.getExpression() != null) { throw new RuntimeException("Unable to parse expression: " + assignUp.getExpression()); } else { assignUp.getNewValue().serialize(null, this); } } else if (update instanceof AddFieldPathUpdate) { ((AddFieldPathUpdate) update).getNewValues().serialize(null, this); } else if (update instanceof RemoveFieldPathUpdate) { generator.writeNumber(0); } else { throw new RuntimeException("Unsupported fieldpath operation: " + update.getClass().getName()); } } generator.writeEndObject(); }
public static Type valueOf(int code) { for (Type type : values()) { if (type.code == code) { return type; } } throw new IllegalArgumentException("Field path update type " + code + " not supported."); }
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)); } }
public void write(FieldPathUpdate update) { putByte(null, (byte)update.getUpdateType().getCode()); put(null, update.getOriginalFieldPath()); put(null, update.getOriginalWhereClause()); }