FieldPathIteratorHandler getIteratorHandler(Document doc) { if (expression != null) { try { return new MathAssignIteratorHandler(expression, doc, removeIfZero, createMissingPath); } catch (ParseException e) { return null; } } else { return new SimpleAssignIteratorHandler(fieldValue, removeIfZero, createMissingPath); } }
@Override public String toString() { return "Add: " + super.toString() + " : " + handler.getNewValues(); } }
public static FieldPathUpdate create(Type type, DocumentType docType, DocumentUpdateReader reader) { switch (type) { case ASSIGN: return new AssignFieldPathUpdate(docType, reader); case ADD: return new AddFieldPathUpdate(docType, reader); case REMOVE: return new RemoveFieldPathUpdate(docType, reader); } throw new IllegalArgumentException("Field path update type '" + type + "' not supported."); }
public void write(FieldPathUpdate update) { putByte(null, (byte)update.getUpdateType().getCode()); put(null, update.getOriginalFieldPath()); put(null, update.getOriginalWhereClause()); }
@Override public String toString() { return "Assign: " + super.toString() + " : " + (isArithmetic() ? getExpression() : getNewValue().toString()); }
public FieldPathUpdate(Type updType, DocumentType docType, String fieldPath, String whereClause) { this.updType = updType; this.docType = docType; try { setWhereClause(whereClause); } catch (ParseException e) { throw new IllegalArgumentException(e); } setFieldPath(fieldPath); }
public RemoveFieldPathUpdate(DocumentType type, String fieldPath, String whereClause) { super(FieldPathUpdate.Type.REMOVE, type, fieldPath, whereClause); handler = new IteratorHandler(); }
/** * Creates an assignment update that overwrites the old value with the given new value. * * @param type The document type the assignment works on. * @param fieldPath The field path of the field to be overwritten. * @param whereClause A document selection string that selects documents and variables to be updated. * @param newValue The new value of the assignment. */ public AssignFieldPathUpdate(DocumentType type, String fieldPath, String whereClause, FieldValue newValue) { super(FieldPathUpdate.Type.ASSIGN, type, fieldPath, whereClause); setNewValue(newValue); }
public AddFieldPathUpdate(DocumentType type, String fieldPath, Array newValues) { super(FieldPathUpdate.Type.ADD, type, fieldPath, null); setNewValues(newValues); }
@Override public String toString() { return "Remove: " + super.toString(); } }
/** * Creates an assign statement based on a mathematical expression. * * @param type The document type the assignment works on. * @param fieldPath The field path of the field to be overwritten. * @param whereClause A document selection string that selects documents and variables to be updated. * @param expression The mathematical expression to apply. Use $value to signify the previous value of the field. */ public AssignFieldPathUpdate(DocumentType type, String fieldPath, String whereClause, String expression) { super(FieldPathUpdate.Type.ASSIGN, type, fieldPath, whereClause); setExpression(expression); }
public Array getNewValues() { return handler.getNewValues(); }
public void setNewValues(Array value) { handler = new IteratorHandler(value); }
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 RemoveFieldPathUpdate(DocumentType type, String fieldPath) { super(FieldPathUpdate.Type.REMOVE, type, fieldPath, null); handler = new IteratorHandler(); }
public AssignFieldPathUpdate(DocumentType type, String fieldPath, FieldValue newValue) { super(FieldPathUpdate.Type.ASSIGN, type, fieldPath, null); setNewValue(newValue); }
public AddFieldPathUpdate(DocumentType type, String fieldPath, String whereClause, Array newValues) { super(FieldPathUpdate.Type.ADD, type, fieldPath, whereClause); setNewValues(newValues); }
public RemoveFieldPathUpdate(DocumentType type, DocumentUpdateReader reader) { super(FieldPathUpdate.Type.REMOVE, type, reader); reader.read(this); handler = new IteratorHandler(); }