public DocumentId getId() { return document.getId(); }
@Override public DocumentId getId() { return doc.getId(); }
public DocEntry(long timestamp, Document doc) { this(timestamp, doc, Type.PUT_ENTRY, doc.getId()); }
/** * Creates a document that is a shallow copy of another. * * @param doc The document to copy. */ public Document(Document doc) { this(doc.getDataType(), doc.getId()); header = doc.header; body = doc.body; lastModified = doc.lastModified; }
public SimpleDocumentAdapter(Document input) { this(input, new Document(input.getDataType(), input.getId())); }
private void verifyType(Document doc) { if (!documentType.equals(doc.getDataType())) { throw new IllegalArgumentException( "Document " + doc.getId() + " with type " + doc.getDataType() + " must have same type as update, which is type " + documentType); } } /**
@Override public int compareTo(FieldValue fieldValue) { int comp = super.compareTo(fieldValue); if (comp != 0) { return comp; } //types are equal, this must be of this type Document otherValue = (Document) fieldValue; comp = getId().compareTo(otherValue.getId()); if (comp != 0) { return comp; } comp = header.compareTo(otherValue.header); if (comp != 0) { return comp; } comp = body.compareTo(otherValue.body); return comp; }
@Override public DocumentUpdate getOutput() { Document doc = adapter.getFullOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); createUpdatesAt(new ArrayList<>(), adapter.getUpdatableOutput(), 0, upd); return upd; }
@Override public DocumentUpdate getOutput() { Document doc = fwdAdapter.getFullOutput(); DocumentUpdate upd = new DocumentUpdate(doc.getDataType(), doc.getId()); upd.addFieldPathUpdate(update); return upd; }
private Document createConcreteDocument(Document document, ContainerDocumentConfig.Doctype typeConfig) { String componentId = typeConfig.factorycomponent(); // Class name of the factory AbstractConcreteDocumentFactory cdf = docFactoryRegistry.getComponent(new ComponentId(componentId)); if (cdf == null) { log.fine("Unable to get document factory component '" + componentId + "' from document factory registry."); return document; } return cdf.getDocumentCopy(document.getDataType().getName(), document, document.getId()); }
@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; }
void testJoinOneBucketPostCondition(PersistenceProvider spi, Bucket bucketA, Bucket bucketC) { assertEquals(10, spi.getBucketInfo(bucketC).getBucketInfo(). getDocumentCount()); FieldSet fs = new AllFields(); for (int i = 0; i < 10; ++i) { Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i); assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument()); } }
void testJoinNormalCasePostCondition(PersistenceProvider spi, Bucket bucketA, Bucket bucketB, Bucket bucketC) { assertEquals(20, spi.getBucketInfo(bucketC). getBucketInfo().getDocumentCount()); FieldSet fs = new AllFields(); for (int i = 0; i < 10; ++i) { Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i); assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument()); } for (int i = 10; i < 20; ++i) { Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i); assertTrue(spi.get(bucketC, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketB, fs, doc1.getId()).hasDocument()); } }
void testSplitNormalCasePostCondition(PersistenceProvider spi, Bucket bucketA, Bucket bucketB, Bucket bucketC) { assertEquals(10, spi.getBucketInfo(bucketA).getBucketInfo(). getDocumentCount()); assertEquals(10, spi.getBucketInfo(bucketB).getBucketInfo(). getDocumentCount()); FieldSet fs = new AllFields(); for (int i = 0; i < 10; ++i) { Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i); assertTrue(spi.get(bucketA, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketC, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketB, fs, doc1.getId()).hasDocument()); } for (int i = 10; i < 20; ++i) { Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i); assertTrue(spi.get(bucketB, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketC, fs, doc1.getId()).hasDocument()); } }
void testSplitTargetExistsPostCondition(PersistenceProvider spi, Bucket bucketA, Bucket bucketB, Bucket bucketC) { assertEquals(10, spi.getBucketInfo(bucketA).getBucketInfo(). getDocumentCount()); assertEquals(15, spi.getBucketInfo(bucketB).getBucketInfo(). getDocumentCount()); FieldSet fs = new AllFields(); for (int i = 0; i < 10; ++i) { Document doc1 = testDocMan.createRandomDocumentAtLocation(0x02, i); assertTrue(spi.get(bucketA, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketC, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketB, fs, doc1.getId()).hasDocument()); } for (int i = 10; i < 25; ++i) { Document doc1 = testDocMan.createRandomDocumentAtLocation(0x06, i); assertTrue(spi.get(bucketB, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketA, fs, doc1.getId()).hasDocument()); assertTrue(!spi.get(bucketC, fs, doc1.getId()).hasDocument()); } }
@SuppressWarnings("deprecation") private BucketId getBucketId(Message msg) { switch (msg.getType()) { case DocumentProtocol.MESSAGE_PUTDOCUMENT: return factory.getBucketId(((PutDocumentMessage)msg).getDocumentPut().getDocument().getId()); case DocumentProtocol.MESSAGE_GETDOCUMENT: return factory.getBucketId(((GetDocumentMessage)msg).getDocumentId()); case DocumentProtocol.MESSAGE_REMOVEDOCUMENT: return factory.getBucketId(((RemoveDocumentMessage)msg).getDocumentId()); case DocumentProtocol.MESSAGE_UPDATEDOCUMENT: return factory.getBucketId(((UpdateDocumentMessage)msg).getDocumentUpdate().getId()); case DocumentProtocol.MESSAGE_GETBUCKETLIST: return ((GetBucketListMessage)msg).getBucketId(); case DocumentProtocol.MESSAGE_STATBUCKET: return ((StatBucketMessage)msg).getBucketId(); case DocumentProtocol.MESSAGE_CREATEVISITOR: return ((CreateVisitorMessage)msg).getBuckets().get(0); case DocumentProtocol.MESSAGE_REMOVELOCATION: return ((RemoveLocationMessage)msg).getBucketId(); default: log.log(LogLevel.ERROR, "Message type '" + msg.getType() + "' not supported."); return null; } }
@SuppressWarnings("deprecation") public static void printDocumentXml(Document doc, XmlStream xml) { xml.addAttribute("documenttype", doc.getDataType().getName()); xml.addAttribute("documentid", doc.getId()); final java.lang.Long lastModified = doc.getLastModified(); if (lastModified != null) { xml.addAttribute("lastmodifiedtime", lastModified); } doc.getHeader().printXml(xml); doc.getBody().printXml(xml); }
@Override public void write(FieldBase field, Document value) { buffer.beginTag("document"); buffer.addAttribute("documenttype", value.getDataType().getName()); buffer.addAttribute("documentid", value.getId()); final java.lang.Long lastModified = value.getLastModified(); if (lastModified != null) { buffer.addAttribute("lastmodifiedtime", lastModified); } write(null, value.getHeader()); write(null, value.getBody()); buffer.endTag(); }
void testDeleteBucket(PersistenceProvider spi) throws Exception { Bucket b = new Bucket((short)0, new BucketId(8, 0x1)); spi.createBucket(b); Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1); spi.put(b, 3, doc1); spi.flush(b); spi.deleteBucket(b); GetResult result = spi.get(b, new AllFields(), doc1.getId()); assertEquals(Result.ErrorType.NONE, result.getErrorType()); assertEquals(0, result.getLastModifiedTimestamp()); }
void testBasics(PersistenceProvider provider) throws Exception { Bucket bucket = new Bucket((short)0, new BucketId(8, 0x01)); Document doc1 = testDocMan.createRandomDocumentAtLocation(0x01, 1); Document doc2 = testDocMan.createRandomDocumentAtLocation(0x01, 2); assertEquals(new Result(), provider.createBucket(bucket)); assertEquals(new Result(), provider.put(bucket, 1, doc1)); assertEquals(new Result(), provider.put(bucket, 2, doc2)); assertEquals(new RemoveResult(true), provider.remove(bucket, 3, doc1.getId())); assertEquals(new Result(), provider.flush(bucket)); testBasicsIteration(provider, bucket, doc1, doc2, false); testBasicsIteration(provider, bucket, doc1, doc2, true); }