use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class RemoveCollectionTest method removeResources.
public void removeResources(final BrokerPool pool) throws PermissionDeniedException, IOException, SAXException, EXistException, LockException, CollectionConfigurationException, DatabaseConfigurationException {
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
final Collection test = storeDocs(broker, transact);
try (final Txn transaction = transact.beginTransaction()) {
for (final Iterator<DocumentImpl> i = test.iterator(broker); i.hasNext(); ) {
final DocumentImpl doc = i.next();
broker.removeXMLResource(transaction, doc);
}
broker.saveCollection(transaction, test);
transact.commit(transaction);
}
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class ShutdownTest method storeAndShutdown.
public void storeAndShutdown() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException, XPathException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
Collection test;
try (final Txn transaction = transact.beginTransaction()) {
test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(test);
broker.saveCollection(transaction, test);
// store some documents.
for (final String sampleName : SAMPLES.getShakespeareXmlSampleNames()) {
broker.storeDocument(transaction, XmldbURI.create(sampleName), new InputStreamSupplierInputSource(() -> SAMPLES.getShakespeareSample(sampleName)), MimeType.XML_TYPE, test);
}
final XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
final Sequence result = xquery.execute(broker, "//SPEECH[contains(LINE, 'love')]", null);
assertNotNull(result);
assertEquals(187, result.getItemCount());
transact.commit(transaction);
}
try (final Txn transaction = transact.beginTransaction()) {
broker.removeCollection(transaction, test);
transact.commit(transaction);
}
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CopyCollectionRecoveryTest method store.
private void store() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
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()) {
final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
broker.saveCollection(transaction, root);
final Collection test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI.append("test2"));
broker.saveCollection(transaction, test);
final String sample = getSampleData();
broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(sample), MimeType.XML_TYPE, test);
final Collection dest = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI.append("destination"));
broker.saveCollection(transaction, dest);
broker.copyCollection(transaction, test, dest, XmldbURI.create("test3"));
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CopyCollectionRecoveryTest method storeAborted.
private void storeAborted() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
Collection test2;
try (final Txn transaction = transact.beginTransaction()) {
final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
test2 = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI.append("test2"));
assertNotNull(test2);
broker.saveCollection(transaction, test2);
final String sample = getSampleData();
broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(sample), MimeType.XML_TYPE, test2);
transact.commit(transaction);
}
final Txn transaction = transact.beginTransaction();
final Collection dest = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI.append("destination"));
assertNotNull(dest);
broker.saveCollection(transaction, dest);
broker.copyCollection(transaction, test2, dest, XmldbURI.create("test3"));
// DO NOT COMMIT TRANSACTION
pool.getJournalManager().get().flush(true, false);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CopyResourceRecoveryTest method store.
private void store(final String testCollectionName, final String subCollection) throws EXistException, PermissionDeniedException, IOException, SAXException, LockException, URISyntaxException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
Collection testCollection;
DocumentImpl doc;
try (final Txn transaction = transact.beginTransaction()) {
final Collection root = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI.append("test"));
assertNotNull(root);
broker.saveCollection(transaction, root);
testCollection = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName));
assertNotNull(testCollection);
broker.saveCollection(transaction, testCollection);
final Collection subTestCollection = broker.getOrCreateCollection(transaction, XmldbURI.ROOT_COLLECTION_URI.append("test").append(testCollectionName).append(subCollection));
assertNotNull(subTestCollection);
broker.saveCollection(transaction, subTestCollection);
final String sample;
try (final InputStream is = SAMPLES.getRomeoAndJulietSample()) {
assertNotNull(is);
sample = InputStreamUtil.readString(is, UTF_8);
}
broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(sample), MimeType.XML_TYPE, subTestCollection);
doc = subTestCollection.getDocument(broker, XmldbURI.create("test.xml"));
transact.commit(transaction);
}
try (final Txn transaction = transact.beginTransaction()) {
broker.copyResource(transaction, doc, testCollection, XmldbURI.create("new_test.xml"));
broker.saveCollection(transaction, testCollection);
transact.commit(transaction);
}
}
}
Aggregations