@Override public DocumentType getDocumentType() { return docU.getDocumentType(); }
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; }
FieldUpdate readArithmeticField(DocumentUpdate update, String type) 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("Assignment update without \"field\" attribute"); } FieldUpdate fu = FieldUpdate.create(f); readArithmetic(update, type, f, fu); return fu; }
/** * The DocumentUpdate object a processor should work on. The one in args, or schema mapped. * * @return a DocumentUpdate */ private DocumentUpdate configDocUpd(DocumentProcessor proc, DocumentUpdate docU) { if (proc.getFieldMap().isEmpty()) return docU; return new ProxyDocumentUpdate(docU, proc.getDocMap(docU.getDocumentType().getName())); }
public Object evaluate(DocumentOperation op) { DocumentType doct; if (op instanceof DocumentPut) { doct = ((DocumentPut)op).getDocument().getDataType(); } else if (op instanceof DocumentUpdate) { doct = ((DocumentUpdate)op).getDocumentType(); } else if (op instanceof DocumentRemove) { DocumentRemove removeOp = (DocumentRemove)op; return (removeOp.getId().getDocType().equals(type) ? op : Boolean.FALSE); } else if (op instanceof DocumentGet) { DocumentGet getOp = (DocumentGet)op; return (getOp.getId().getDocType().equals(type) ? op : Boolean.FALSE); } else { throw new IllegalStateException("Document class '" + op.getClass().getName() + "' is not supported."); } return doct.isA(this.type) ? op : Boolean.FALSE; }
FieldUpdate readAssign(DocumentUpdate update) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { if ("field".equals(reader.getAttributeName(i).toString())) { Field f = update.getDocumentType().getField(reader.getAttributeValue(i)); if (f == null) { throw newDeserializeException("Field " + reader.getAttributeValue(i) + " not found."); } FieldValue value = f.getDataType().createFieldValue(); value.deserialize(f, this); return FieldUpdate.createAssign(f, value); } } throw newDeserializeException("Assignment update without field attribute"); }
FieldUpdate readAdd(DocumentUpdate update) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { if ("field".equals(reader.getAttributeName(i).toString())) { Field f = update.getDocumentType().getField(reader.getAttributeValue(i)); FieldValue value = f.getDataType().createFieldValue(); value.deserialize(f, this); if (value instanceof Array) { List<FieldValue> l = ((Array)value).getValues(); return FieldUpdate.createAddAll(f, l); } else if (value instanceof WeightedSet) { return FieldUpdate.createAddAll(f, ((WeightedSet) value)); } else { throw newDeserializeException("Add operation only applicable to multivalue lists"); } } } throw newDeserializeException("Add update without field attribute"); }
FieldUpdate readRemove(DocumentUpdate update) throws XMLStreamException { for (int i = 0; i < reader.getAttributeCount(); i++) { if ("field".equals(reader.getAttributeName(i).toString())) { Field f = update.getDocumentType().getField(reader.getAttributeValue(i)); FieldValue value = f.getDataType().createFieldValue(); value.deserialize(f, this); if (value instanceof Array) { List<FieldValue> l = ((Array)value).getValues(); return FieldUpdate.createRemoveAll(f, l); } else if (value instanceof WeightedSet) { return FieldUpdate.createRemoveAll(f, ((WeightedSet)value)); } else { throw newDeserializeException("Remove operation only applicable to multivalue lists"); } } } throw newDeserializeException("Remove update without field attribute"); }
@Override public void write(DocumentUpdate update) { putShort(null, Document.SERIALIZED_VERSION); update.getId().serialize(this); byte contents = 0x1; // Legacy to say we have document type putByte(null, contents); update.getDocumentType().serialize(this); putInt(null, update.fieldUpdates().size()); for (FieldUpdate up : update.fieldUpdates()) { up.serialize(this); } }
@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); } }
@Override public List<UpdateAdapter> newUpdateAdapterList(DocumentUpdate upd) { List<UpdateAdapter> ret = new ArrayList<>(); DocumentType docType = upd.getDocumentType(); DocumentId docId = upd.getId(); Document complete = new Document(docType, upd.getId());
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 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)); } }