/** * 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); }
private AssignFieldPathUpdate readArithmeticFieldPathUpdate( DocumentType documentType, String fieldPath, TokenBuffer buffer, String fieldPathOperation) { AssignFieldPathUpdate fieldPathUpdate = new AssignFieldPathUpdate(documentType, fieldPath); String arithmeticSign = SingleValueReader.UPDATE_OPERATION_TO_ARITHMETIC_SIGN.get(fieldPathOperation); double value = Double.valueOf(buffer.currentText()); String expression = String.format("$value %s %s", arithmeticSign, value); fieldPathUpdate.setExpression(expression); return fieldPathUpdate; }
public void read(AssignFieldPathUpdate update) { try { for (int i = 0; i < reader.getAttributeCount(); i++) { if (reader.getAttributeName(i).toString().equals("removeifzero")) { update.setRemoveIfZero(Boolean.parseBoolean(reader.getAttributeValue(i))); } else if (reader.getAttributeName(i).toString().equals("createmissingpath")) { update.setCreateMissingPath(Boolean.parseBoolean(reader.getAttributeValue(i))); } } DataType dt = update.getFieldPath().getResultingDataType(); if (dt instanceof NumericDataType) { update.setExpression(reader.getElementText()); } else { FieldValue fv = dt.createFieldValue(); fv.deserialize(resolveField(update), this); update.setNewValue(fv); } } catch (XMLStreamException e) { throw newException(e); } }
public void read(AssignFieldPathUpdate update) { byte flags = getByte(null); update.setRemoveIfZero((flags & AssignFieldPathUpdate.REMOVE_IF_ZERO) != 0); update.setCreateMissingPath((flags & AssignFieldPathUpdate.CREATE_MISSING_PATH) != 0); if ((flags & AssignFieldPathUpdate.ARITHMETIC_EXPRESSION) != 0) { update.setExpression(getString(null)); } else { DataType dt = update.getFieldPath().getResultingDataType(); FieldValue fv = dt.createFieldValue(); fv.deserialize(this); update.setNewValue(fv); } }
public void read(AssignFieldPathUpdate update) { byte flags = getByte(null); update.setRemoveIfZero((flags & AssignFieldPathUpdate.REMOVE_IF_ZERO) != 0); update.setCreateMissingPath((flags & AssignFieldPathUpdate.CREATE_MISSING_PATH) != 0); if ((flags & AssignFieldPathUpdate.ARITHMETIC_EXPRESSION) != 0) { update.setExpression(getString(null)); } else { DataType dt = update.getFieldPath().getResultingDataType(); FieldValue fv = dt.createFieldValue(); fv.deserialize(this); update.setNewValue(fv); } }