public void addFieldUpdates(Collection<FieldUpdate> fieldUpdates) { for (FieldUpdate fieldUpdate : fieldUpdates) { addFieldUpdate(fieldUpdate); } }
@Override public DocumentUpdate addFieldUpdate(FieldUpdate fieldUpdate) { return docU.addFieldUpdate(fieldUpdate); }
FieldUpdate readAlter(DocumentUpdate update) throws XMLStreamException { Field f = null; for (int i = 0; i < reader.getAttributeCount(); i++) { if ("field".equals(reader.getAttributeName(i).toString())) { f = update.getDocumentType().getField(reader.getAttributeValue(i)); } } if (f == null) { throw newDeserializeException("Alter update without \"field\" attribute"); } FieldUpdate fu = FieldUpdate.create(f); while (reader.hasNext()) { int type = reader.next(); if (type == XMLStreamReader.START_ELEMENT) { if ("increment".equals(reader.getName().toString()) || "decrement".equals(reader.getName().toString()) || "multiply".equals(reader.getName().toString()) || "divide".equals(reader.getName().toString())) { update.addFieldUpdate(readArithmetic(update, reader.getName().toString(), f, fu)); skipToEnd(reader.getName().toString()); } else { throw newDeserializeException("Element \"" + reader.getName() + "\" not appropriate within alter element"); } } else if (type == XMLStreamReader.END_ELEMENT) { break; } } return fu; }
@Override public DocumentUpdate getOutput() { Document doc = adapter.getUpdatableOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); for (Iterator<Map.Entry<Field, FieldValue>> it = doc.iterator(); it.hasNext();) { Map.Entry<Field, FieldValue> entry = it.next(); Field field = entry.getKey(); if (field.getName().equals("sddocname")) { continue; } FieldUpdate fieldUpd = FieldUpdate.create(field); fieldUpd.addValueUpdates(builder.build(entry.getValue())); if (!fieldUpd.isEmpty()) { upd.addFieldUpdate(fieldUpd); } } return upd.isEmpty() ? null : upd; }
update.addFieldUpdate(readAssign(update)); skipToEnd("assign"); } else if ("add".equals(currentName)) { update.addFieldUpdate(readAdd(update)); skipToEnd("add"); } else if ("remove".equals(currentName)) { update.addFieldUpdate(readRemove(update)); skipToEnd("remove"); } else if ("alter".equals(currentName)) { update.addFieldUpdate(readAlter(update)); skipToEnd("alter"); } else if ("increment".equals(currentName) || "multiply".equals(currentName) || "divide".equals(currentName)) { update.addFieldUpdate(readArithmeticField(update, currentName)); skipToEnd(currentName); } else {
public void read(DocumentUpdate update) { short serializationVersion = getShort(null); update.setId(new DocumentId(this)); byte contents = getByte(null); if ((contents & 0x1) == 0) { throw new DeserializationException("Cannot deserialize DocumentUpdate without doctype"); } update.setDocumentType(readDocumentType()); int size = getInt(null); for (int i = 0; i < size; i++) { update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), serializationVersion)); } }
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)); } }
private void addFieldUpdates(DocumentUpdate update, TokenBuffer buffer, String fieldName) { Field field = update.getType().getField(fieldName); int localNesting = buffer.nesting(); FieldUpdate fieldUpdate = FieldUpdate.create(field); buffer.next(); while (localNesting <= buffer.nesting()) { switch (buffer.currentName()) { case UPDATE_REMOVE: createRemoves(buffer, field, fieldUpdate); break; case UPDATE_ADD: createAdds(buffer, field, fieldUpdate); break; case UPDATE_MATCH: fieldUpdate.addValueUpdate(createMapUpdate(buffer, field)); break; case UPDATE_MODIFY: fieldUpdate.addValueUpdate(createModifyUpdate(buffer, field)); break; default: String action = buffer.currentName(); fieldUpdate.addValueUpdate(readSingleUpdate(buffer, field.getDataType(), action)); } buffer.next(); } update.addFieldUpdate(fieldUpdate); }
FieldUpdate fieldUpdate = FieldUpdate.create(docType.getField("headerval")); fieldUpdate.addValueUpdate(AssignValueUpdate.createAssign(new IntegerFieldValue(42))); update.addFieldUpdate(fieldUpdate);