use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class DocTypeTest method tearDown.
@AfterClass
public static void tearDown() throws PermissionDeniedException, IOException, TriggerException, EXistException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
root = broker.getOrCreateCollection(transaction, XmldbURI.create(XmldbURI.ROOT_COLLECTION + "/test"));
assertNotNull(root);
broker.removeCollection(transaction, root);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class DOMIndexerTest method store.
@Test
public void store() throws PermissionDeniedException, IOException, EXistException, SAXException, LockException, AuthenticationException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager txnMgr = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate("admin", "")));
final Txn txn = txnMgr.beginTransaction()) {
try (final Collection collection = broker.getOrCreateCollection(txn, TestConstants.TEST_COLLECTION_URI)) {
broker.storeDocument(txn, TestConstants.TEST_XML_URI, new StringInputSource(XML), MimeType.XML_TYPE, collection);
broker.flush();
broker.saveCollection(txn, collection);
}
txnMgr.commit(txn);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class BasicNodeSetTest method tearDown.
@AfterClass
public static void tearDown() throws PermissionDeniedException, IOException, TriggerException, EXistException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
root = broker.getOrCreateCollection(transaction, XmldbURI.create(XmldbURI.ROOT_COLLECTION + "/test"));
broker.removeCollection(transaction, root);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class RecoveryTest method verify.
private void verify(final BrokerPool pool) throws EXistException, PermissionDeniedException, SAXException, XPathException, IOException, BTreeException, LockException {
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Serializer serializer = broker.borrowSerializer();
try {
try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/test2/hamlet.xml"), LockMode.READ_LOCK)) {
assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/hamlet.xml' should not be null", lockedDoc);
final String data = serializer.serialize(lockedDoc.getDocument());
assertNotNull(data);
}
try (final LockedDocument lockedDoc = broker.getXMLResource(XmldbURI.ROOT_COLLECTION_URI.append("test/test2/test_string.xml"), LockMode.READ_LOCK)) {
assertNotNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/test_string.xml' should not be null", lockedDoc);
final String data = serializer.serialize(lockedDoc.getDocument());
assertNotNull(data);
}
final String lastSampleName = SAMPLES.getShakespeareXmlSampleNames()[SAMPLES.getShakespeareXmlSampleNames().length - 1];
try (final LockedDocument lockedDoc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(lastSampleName), LockMode.READ_LOCK)) {
assertNull("Document '" + XmldbURI.ROOT_COLLECTION + "/test/test2/'" + lastSampleName + " should not exist anymore", lockedDoc);
}
final XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
final Sequence seq = xquery.execute(broker, "//SPEECH[contains(LINE, 'king')]", null);
assertNotNull(seq);
for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
final Item next = i.nextItem();
final String value = serializer.serialize((NodeValue) next);
}
} finally {
broker.returnSerializer(serializer);
}
try (final LockedDocument lockedBinDoc = broker.getXMLResource(TestConstants.TEST_COLLECTION_URI2.append(TestConstants.TEST_BINARY_URI), LockMode.READ_LOCK)) {
assertNotNull("Binary document is null", lockedBinDoc);
final BinaryDocument binDoc = (BinaryDocument) lockedBinDoc.getDocument();
try (final InputStream is = broker.getBinaryResource(binDoc)) {
final byte[] bdata = new byte[(int) binDoc.getContentLength()];
is.read(bdata);
final String data = new String(bdata);
assertNotNull(data);
}
}
final DOMFile domDb = ((NativeBroker) broker).getDOMFile();
assertNotNull(domDb);
try (final Writer writer = new StringWriter()) {
domDb.dump(writer);
}
final TransactionManager transact = pool.getTransactionManager();
try (final Txn transaction = transact.beginTransaction()) {
try (final Collection root = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.WRITE_LOCK)) {
assertNotNull(root);
transaction.acquireCollectionLock(() -> broker.getBrokerPool().getLockManager().acquireCollectionWriteLock(root.getURI()));
broker.removeCollection(transaction, root);
}
transact.commit(transaction);
}
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class RecoveryTest3 method store.
@Test
public void store() throws DatabaseConfigurationException, EXistException, PermissionDeniedException, IOException, TriggerException, LockException {
BrokerPool.FORCE_CORRUPTION = true;
final BrokerPool pool = startDb();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
Collection test2 = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI2);
assertNotNull(test2);
broker.saveCollection(transaction, test2);
final List<Path> files = FileUtils.list(dir, XMLFilenameFilter.asPredicate());
assertNotNull(files);
// store some documents.
for (int i = 0; i < files.size() && i < RESOURCE_COUNT; i++) {
final Path f = files.get(i);
try {
broker.storeDocument(transaction, XmldbURI.create(FileUtils.fileName(f)), new InputSource(f.toUri().toASCIIString()), MimeType.XML_TYPE, test2);
} catch (final SAXException e) {
fail("Error found while parsing document: " + FileUtils.fileName(f) + ": " + e.getMessage());
}
}
transact.commit(transaction);
}
}
Aggregations