@Override public FieldValue setFieldValue(Field field, FieldValue fieldValue) { checkAccess(field); return doc.setFieldValue(field, fieldValue); }
/** * Copies fields from one document to another based on whether the fields match the given * fieldset. */ public void copyFields(Document source, Document target, FieldSet fieldSet) { for (Iterator<Map.Entry<Field, FieldValue>> i = source.iterator(); i.hasNext();) { Map.Entry<Field, FieldValue> v = i.next(); if (fieldSet.contains(v.getKey())) { target.setFieldValue(v.getKey(), v.getValue()); } } }
public Document createRandomDocumentAtLocation(long location, long timestamp, int minSize, int maxSize) { Document document = new Document(getDocumentType("testdoctype1"), new DocumentId("userdoc:footype:" + location + ":" + timestamp)); document.setFieldValue("headerval", new IntegerFieldValue((int)timestamp)); StringBuffer value = new StringBuffer(); int length = (int)(Math.random() * (maxSize - minSize)) + minSize; for (int i = 0; i < length; ++i) { value.append("A"); } document.setFieldValue("content", new StringFieldValue(value.toString())); return document; } }
@SuppressWarnings({ "unchecked" }) @Override public SimpleDocumentAdapter setOutputValue(Expression exp, String fieldName, FieldValue fieldValue) { Field field = output.getField(fieldName); if (field == null) { throw new IllegalArgumentException("Field '" + fieldName + "' not found in document type '" + output.getDataType().getName() + "'."); } output.setFieldValue(field, fieldValue); return this; } }
public static void applyUpdate(Field field, ValueUpdate update, Document doc) { doc.setFieldValue(field, createFieldValue(field.getDataType().createFieldValue(), update)); }
document.setFieldValue(f, fv); skipToEnd(f.getName()); } else if (type == XMLStreamReader.END_ELEMENT) {
/** * Applies this field update. * * @param doc the document to apply the update to * @return a reference to itself */ public FieldUpdate applyTo(Document doc) { for (ValueUpdate vupd : valueUpdates) { DataType dataType = field.getDataType(); FieldValue oldValue = doc.getFieldValue(field); boolean existed = (oldValue != null); if (!existed) { oldValue = dataType.createFieldValue(); } FieldValue newValue = vupd.applyTo(oldValue); if (newValue == null) { if (existed) { doc.removeFieldValue(field); } } else { doc.setFieldValue(field, newValue); } } return this; }
void testIterateMatchSelection(PersistenceProvider spi) throws Exception { Bucket b = new Bucket((short)0, new BucketId(8, 0x1)); spi.createBucket(b); List<DocEntry> docsToVisit = new ArrayList<DocEntry>(); for (int i = 0; i < 99; i++) { Document doc = testDocMan.createRandomDocumentAtLocation(1, 1000 + i, 110, 110); doc.setFieldValue("headerval", new IntegerFieldValue(i)); spi.put(b, 1000 + i, doc); if ((i % 3) == 0) { docsToVisit.add(new DocEntry(1000 + i, doc)); } } spi.flush(b); CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("testdoctype1.headerval % 3 == 0", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY); List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 2048, 0); verifyDocs(docsToVisit, chunks); spi.destroyIterator(iter.getIteratorId()); }
void testIterateAllDocsNewestVersionOnly(PersistenceProvider spi) throws Exception { Bucket b = new Bucket((short)0, new BucketId(8, 0x1)); spi.createBucket(b); List<DocEntry> docs = feedDocs(spi, b, 100, 110, 110); List<DocEntry> newDocs = new ArrayList<DocEntry>(); for (DocEntry e : docs) { Document newDoc = e.getDocument().clone(); newDoc.setFieldValue("headerval", new IntegerFieldValue(5678 + (int)e.getTimestamp())); spi.put(b, 1000 + e.getTimestamp(), newDoc); newDocs.add(new DocEntry(1000 + e.getTimestamp(), newDoc)); } spi.flush(b); CreateIteratorResult iter = spi.createIterator(b, new AllFields(), new Selection("", 0, Long.MAX_VALUE), PersistenceProvider.IncludedVersions.NEWEST_DOCUMENT_ONLY); List<IterateResult> chunks = doIterate(spi, iter.getIteratorId(), 4096, 0); verifyDocs(newDocs, chunks); spi.destroyIterator(iter.getIteratorId()); }
doc2.setFieldValue("content", new StringFieldValue("hiho silver")); spi.createBucket(bucket);
doc2.setFieldValue("content", new StringFieldValue("hiho silver")); spi.createBucket(bucket);