use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class DLNStorageTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
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()) {
Collection test = broker.getOrCreateCollection(transaction, TEST_COLLECTION);
broker.saveCollection(transaction, test);
broker.storeDocument(transaction, XmldbURI.create("test_string.xml"), new StringInputSource(TEST_XML), MimeType.XML_TYPE, test);
// TODO : unlock the collection here ?
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class NativeBroker method cleanUpTempResources.
/**
* remove all documents from temporary collection
*
* @param forceRemoval Should temporary resources be forcefully removed
*/
@Override
public void cleanUpTempResources(final boolean forceRemoval) throws PermissionDeniedException {
try (final Collection temp = openCollection(XmldbURI.TEMP_COLLECTION_URI, LockMode.WRITE_LOCK)) {
if (temp == null) {
return;
}
final TransactionManager transact = pool.getTransactionManager();
try (final Txn transaction = transact.beginTransaction()) {
removeCollection(transaction, temp);
transact.commit(transaction);
} catch (final Exception e) {
LOG.error("Failed to remove temp collection: {}", e.getMessage(), e);
}
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class DOMFileRecoverTest method get.
@Test
public void get() throws EXistException, IOException, BTreeException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
// Recover and read the data
assertNotNull(broker);
TransactionManager mgr = pool.getTransactionManager();
assertNotNull(mgr);
DOMFile domDb = ((NativeBroker) broker).getDOMFile();
assertNotNull(domDb);
domDb.setOwnerObject(this);
IndexQuery query = new IndexQuery(IndexQuery.GT, new NativeBroker.NodeRef(500));
assertNotNull(query);
List<?> keys = domDb.findKeys(query);
assertNotNull(keys);
int count = 0;
for (Iterator<?> i = keys.iterator(); i.hasNext(); count++) {
Value key = (Value) i.next();
assertNotNull(key);
Value value = domDb.get(key);
assertNotNull(value);
}
Writer writer = new StringWriter();
domDb.dump(writer);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class DirtyShutdownTest method storeRepeatedly.
public void storeRepeatedly() {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
Collection root;
try (final Txn transaction = transact.beginTransaction()) {
root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
transact.commit(transaction);
}
final String data;
try (final UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
final InputStream is = SAMPLES.getMacbethSample()) {
os.write(is);
data = new String(os.toByteArray(), UTF_8);
}
for (int i = 0; i < 50; i++) {
try (final Txn transaction = transact.beginTransaction()) {
broker.storeDocument(transaction, XmldbURI.create("test.xml"), new StringInputSource(data), MimeType.XML_TYPE, root);
transact.commit(transaction);
}
}
} catch (final PermissionDeniedException | EXistException | SAXException | LockException | IOException e) {
LOG.error(e.getMessage(), e);
fail(e.getMessage());
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class MoveCollectionRecoveryTest 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_URI2);
assertNotNull(test2);
broker.saveCollection(transaction, test2);
final String sample;
try (final InputStream is = SAMPLES.getBiblioSample()) {
assertNotNull(is);
sample = InputStreamUtil.readString(is, UTF_8);
}
broker.storeDocument(transaction, TestConstants.TEST_XML_URI, new StringInputSource(sample), MimeType.XML_TYPE, test2);
transact.commit(transaction);
}
final Txn transaction = transact.beginTransaction();
assertNotNull(transaction);
final Collection dest = broker.getOrCreateCollection(transaction, TestConstants.DESTINATION_COLLECTION_URI2);
assertNotNull(dest);
broker.saveCollection(transaction, dest);
broker.moveCollection(transaction, test2, dest, XmldbURI.create("test3"));
// Don't commit...
pool.getJournalManager().get().flush(true, false);
}
}
Aggregations