use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class MoveCollectionTest method moveDeepWithSubCollections.
/**
* Test move collection /db/a/b/c/d/e/f/g/h/i/j/k to /db/z/y/x/w/v/u/k
*
* Note that the collection /db/a/b/c/d/e/f/g/h/i/j/k has the sub-collections (sub-1 and sub-2),
* this test checks that the sub-collections are correctly preserved.
*/
@Test
public void moveDeepWithSubCollections() throws EXistException, IOException, PermissionDeniedException, TriggerException, 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 XmldbURI srcUri = XmldbURI.create("/db/a/b/c/d/e/f/g/h/i/j/k");
final XmldbURI srcSubCol1Uri = srcUri.append("sub-1");
final XmldbURI srcSubCol2Uri = srcUri.append("sub-2");
final XmldbURI destUri = XmldbURI.create("/db/z/y/x/w/v/u");
// create src collection
try (final Collection src = broker.getOrCreateCollection(transaction, srcUri)) {
assertNotNull(src);
broker.saveCollection(transaction, src);
}
// create src sub-collections
try (final Collection srcColSubCol1 = broker.getOrCreateCollection(transaction, srcSubCol1Uri)) {
assertNotNull(srcColSubCol1);
broker.saveCollection(transaction, srcColSubCol1);
}
try (final Collection srcColSubCol2 = broker.getOrCreateCollection(transaction, srcSubCol2Uri)) {
assertNotNull(srcColSubCol2);
broker.saveCollection(transaction, srcColSubCol2);
}
// create dst collection
try (final Collection dst = broker.getOrCreateCollection(transaction, destUri)) {
assertNotNull(dst);
broker.saveCollection(transaction, dst);
}
try (final Collection src = broker.openCollection(srcUri, Lock.LockMode.WRITE_LOCK);
final Collection dst = broker.openCollection(destUri, Lock.LockMode.WRITE_LOCK)) {
broker.moveCollection(transaction, src, dst, src.getURI().lastSegment());
}
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class MoveCollectionTest method rename.
/**
* Test rename collection /db/move-collection-test-rename/before to /db/move-collection-test-rename/after
*/
@Test
public void rename() throws EXistException, PermissionDeniedException, IOException, TriggerException, 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 XmldbURI testColUri = XmldbURI.create("/db/move-collection-test-rename");
final XmldbURI srcColUri = testColUri.append("before");
final XmldbURI newName = XmldbURI.create("after");
try (final Collection testCol = broker.getOrCreateCollection(transaction, testColUri)) {
assertNotNull(testCol);
broker.saveCollection(transaction, testCol);
}
try (final Collection srcCol = broker.getOrCreateCollection(transaction, srcColUri)) {
assertNotNull(srcCol);
broker.saveCollection(transaction, srcCol);
}
try (final Collection src = broker.openCollection(srcColUri, Lock.LockMode.WRITE_LOCK);
final Collection testCol = broker.openCollection(testColUri, Lock.LockMode.WRITE_LOCK)) {
broker.moveCollection(transaction, src, testCol, newName);
assertFalse(testCol.hasChildCollection(broker, srcColUri.lastSegment()));
assertTrue(testCol.hasChildCollection(broker, newName));
}
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class MoveCollectionTest method renameWithSubCollections.
/**
* Test rename collection /db/move-collection-test-rename/before to /db/move-collection-test-rename/after
*
* Note that the collection /db/move-collection-test-rename/before has the sub-collections (sub-1 and sub-2),
* this test checks that the sub-collections are correctly preserved.
*/
@Test
public void renameWithSubCollections() throws EXistException, PermissionDeniedException, IOException, TriggerException, 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 XmldbURI testColUri = XmldbURI.create("/db/move-collection-test-rename");
final XmldbURI srcColUri = testColUri.append("before");
final XmldbURI srcColSubCol1Uri = srcColUri.append("sub-1");
final XmldbURI srcColSubCol2Uri = srcColUri.append("sub-2");
final XmldbURI newName = XmldbURI.create("after");
// create test collection
try (final Collection testCol = broker.getOrCreateCollection(transaction, testColUri)) {
assertNotNull(testCol);
broker.saveCollection(transaction, testCol);
}
// create src collection
try (final Collection srcCol = broker.getOrCreateCollection(transaction, srcColUri)) {
assertNotNull(srcCol);
broker.saveCollection(transaction, srcCol);
}
// create src sub-collections
try (final Collection srcColSubCol1 = broker.getOrCreateCollection(transaction, srcColSubCol1Uri)) {
assertNotNull(srcColSubCol1);
broker.saveCollection(transaction, srcColSubCol1);
}
try (final Collection srcColSubCol2 = broker.getOrCreateCollection(transaction, srcColSubCol2Uri)) {
assertNotNull(srcColSubCol2);
broker.saveCollection(transaction, srcColSubCol2);
}
try (final Collection src = broker.openCollection(srcColUri, Lock.LockMode.WRITE_LOCK);
final Collection testCol = broker.openCollection(testColUri, Lock.LockMode.WRITE_LOCK)) {
broker.moveCollection(transaction, src, testCol, newName);
assertFalse(testCol.hasChildCollection(broker, srcColUri.lastSegment()));
assertTrue(testCol.hasChildCollection(broker, newName));
}
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class ResourceTest method read2.
private void read2(final BrokerPool pool) throws EXistException, PermissionDeniedException, IOException, TriggerException {
final TransactionManager transact = pool.getTransactionManager();
byte[] data = null;
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final XmldbURI docPath = TestConstants.TEST_COLLECTION_URI.append(DOCUMENT_NAME_URI);
try (final LockedDocument lockedDoc = broker.getXMLResource(docPath, LockMode.READ_LOCK)) {
// if document is not present, null is returned
if (lockedDoc == null) {
fail("Binary document '" + docPath + " does not exist.");
} else {
final BinaryDocument binDoc = (BinaryDocument) lockedDoc.getDocument();
try (final InputStream is = broker.getBinaryResource(transaction, binDoc)) {
data = new byte[(int) binDoc.getContentLength()];
is.read(data);
}
}
}
try (final Collection collection = broker.openCollection(TestConstants.TEST_COLLECTION_URI, LockMode.WRITE_LOCK)) {
broker.removeCollection(transaction, collection);
}
transact.commit(transaction);
}
assertEquals(0, data.length);
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class StoreBinaryTest method removeTestResources.
@After
public void removeTestResources() throws EXistException, PermissionDeniedException, IOException, TriggerException {
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 testCollection = broker.getCollection(TestConstants.TEST_COLLECTION_URI);
broker.removeCollection(transaction, testCollection);
transaction.commit();
}
}
Aggregations