try {
pool = startDB();
assertNotNull(pool);
broker = pool.get(pool.getSecurityManager().getSystemSubject());
assertNotNull(broker);
TransactionManager transact = pool.getTransactionManager();
assertNotNull(transact);
Txn transaction = transact.beginTransaction();
assertNotNull(transaction);
System.out.println("Transaction started ...");
Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
Collection test2 = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
broker.saveCollection(transaction, test2);
File files[] = dir.listFiles();
assertNotNull(files);
File f;
IndexInfo info;
BinaryDocument doc = test2.addBinaryResource(transaction, broker, TestConstants.TEST_BINARY_URI, "Some text data".getBytes(), null);
assertNotNull(doc);
// store some documents. Will be replaced below
for (int i = 0; i < files.length; i++) {
f = files[i];
try {
info = test2.validateXMLResource(transaction, broker, XmldbURI.create(f.getName()), new InputSource(f.toURI().toASCIIString()));
assertNotNull(info);
test2.store(transaction, broker, info, new InputSource(f.toURI().toASCIIString()), false);
} catch (SAXException e) {
// TODO : why pass invalid couments ?
System.err.println("Error found while parsing document: " + f.getName() + ": " + e.getMessage());
}
}
// replace some documents
for (int i = 0; i < files.length; i++) {
f = files[i];
try {
info = test2.validateXMLResource(transaction, broker, XmldbURI.create(f.getName()), new InputSource(f.toURI().toASCIIString()));
assertNotNull(info);
test2.store(transaction, broker, info, new InputSource(f.toURI().toASCIIString()), false);
} catch (SAXException e) {
// TODO : why pass invalid couments ?
System.err.println("Error found while parsing document: " + f.getName() + ": " + e.getMessage());
}
}
info = test2.validateXMLResource(transaction, broker, XmldbURI.create("test_string.xml"), TEST_XML);
assertNotNull(info);
//TODO : unlock the collection here ?
test2.store(transaction, broker, info, TEST_XML, false);
// remove last document
test2.removeXMLResource(transaction, broker, XmldbURI.create(files[files.length - 1].getName()));
transact.commit(transaction);
System.out.println("Transaction commited ...");
// the following transaction will not be committed. It will thus be rolled back by recovery
transaction = transact.beginTransaction();
System.out.println("Transaction started ...");
test2.removeXMLResource(transaction, broker, XmldbURI.create(files[0].getName()));
test2.removeBinaryResource(transaction, broker, doc);
// Don't commit...
transact.getJournal().flushToLog(true);
System.out.println("Transaction interrupted ...");
//DOMFile domDb = ((NativeBroker)broker).getDOMFile();
//assertNotNull(domDb);
//Writer writer = new StringWriter();