private void read() {
BrokerPool.FORCE_CORRUPTION = false;
BrokerPool pool = null;
DBBroker broker = null;
TransactionManager transact = null;
Txn transaction = null;
try {
System.out.println("testRead() ...\n");
pool = startDB();
assertNotNull(pool);
broker = pool.get(pool.getSecurityManager().getSystemSubject());
Serializer serializer = broker.getSerializer();
serializer.reset();
DocumentImpl doc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/test2/hamlet.xml"), Lock.READ_LOCK);
assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/hamlet.xml' should not be null", doc);
String data = serializer.serialize(doc);
assertNotNull(data);
//System.out.println(data);
doc.getUpdateLock().release(Lock.READ_LOCK);
doc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/test2/test_string.xml"), Lock.READ_LOCK);
assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/test_string.xml' should not be null", doc);
data = serializer.serialize(doc);
assertNotNull(data);
//System.out.println(data);
doc.getUpdateLock().release(Lock.READ_LOCK);
File files[] = dir.listFiles();
assertNotNull(files);
doc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(files[files.length - 1].getName()), Lock.READ_LOCK);
assertNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/'" + files[files.length - 1].getName() + " should not exist anymore", doc);
XQuery xquery = broker.getXQueryService();
assertNotNull(xquery);
Sequence seq = xquery.execute("//SPEECH[ft:query(LINE, 'king')]", null, AccessContext.TEST);
assertNotNull(seq);
System.out.println("Found: " + seq.getItemCount());
for (SequenceIterator i = seq.iterate(); i.hasNext(); ) {
Item next = i.nextItem();
String value = serializer.serialize((NodeValue) next);
//System.out.println(value);
}
BinaryDocument binDoc = (BinaryDocument) broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(TestConstants.TEST_BINARY_URI), Lock.READ_LOCK);
assertNotNull("Binary document is null", binDoc);
InputStream is = broker.getBinaryResource(binDoc);
byte [] bdata = new byte[(int)broker.getBinaryResourceSize(binDoc)];
is.read(bdata);
is.close();
data = new String(bdata);
assertNotNull(data);
System.out.println(data);
DOMFile domDb = ((NativeBroker)broker).getDOMFile();
assertNotNull(domDb);
Writer writer = new StringWriter();
domDb.dump(writer);
//System.out.println(writer.toString());
transact = pool.getTransactionManager();
assertNotNull(transact);
transaction = transact.beginTransaction();
assertNotNull(transaction);
System.out.println("Transaction started ...");
Collection root = broker.openCollection(TestConstants.TEST_COLLECTION_URI, Lock.WRITE_LOCK);
assertNotNull(root);
transaction.registerLock(root.getLock(), Lock.WRITE_LOCK);
broker.removeCollection(transaction, root);
transact.commit(transaction);
System.out.println("Transaction commited ...");
} catch (Exception e) {