use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CollectionTest method store.
private void store(final BrokerPool pool) throws DatabaseConfigurationException, EXistException, PermissionDeniedException, IOException, TriggerException {
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, TEST_COLLECTION_URI);
broker.saveCollection(transaction, root);
Collection test = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI.append("test2"));
broker.saveCollection(transaction, test);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class ConcurrentStoreTest method setupCollections.
protected void setupCollections(final BrokerPool pool) throws EXistException, PermissionDeniedException, IOException, TriggerException {
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, TEST_COLLECTION_URI);
broker.saveCollection(transaction, root);
test = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI.append("test1"));
broker.saveCollection(transaction, test);
test2 = broker.getOrCreateCollection(transaction, TEST_COLLECTION_URI.append("test2"));
broker.saveCollection(transaction, test2);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CopyCollectionTest method copyDeep.
/**
* Test copy collection /db/a/b/c/d/e/f/g/h/i/j/k to /db/z/y/x/w/v/u/k
*/
@Test
public void copyDeep() throws EXistException, IOException, PermissionDeniedException, TriggerException, LockException {
final XmldbURI srcUri = XmldbURI.create("/db/a/b/c/d/e/f/g/h/i/j/k");
final XmldbURI destUri = XmldbURI.create("/db/z/y/x/w/v/u");
final XmldbURI newName = srcUri.lastSegment();
final BrokerPool pool = existWebServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
try (final Collection src = broker.getOrCreateCollection(transaction, srcUri)) {
assertNotNull(src);
broker.saveCollection(transaction, src);
}
try (final Collection dst = broker.getOrCreateCollection(transaction, destUri)) {
assertNotNull(dst);
broker.saveCollection(transaction, dst);
}
try (final Collection src = broker.openCollection(srcUri, LockMode.WRITE_LOCK);
final Collection dst = broker.openCollection(destUri, LockMode.WRITE_LOCK)) {
broker.copyCollection(transaction, src, dst, newName);
}
transact.commit(transaction);
}
// check that the source still exists
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
try (final Collection src = broker.openCollection(srcUri, LockMode.READ_LOCK)) {
assertNotNull(src);
}
transaction.commit();
}
// check that the new copy exists
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
final Txn transaction = transact.beginTransaction()) {
final XmldbURI copyUri = destUri.append(newName);
try (final Collection copy = broker.openCollection(copyUri, LockMode.READ_LOCK)) {
assertNotNull(copy);
}
transaction.commit();
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class BrokerPool method initialiseSystemCollection.
/**
* Initialise system collections, if it doesn't exist yet
*
* @param sysBroker The system broker from before the brokerpool is populated
* @param sysCollectionUri XmldbURI of the collection to create
* @param permissions The permissions to set on the created collection
*/
private void initialiseSystemCollection(final DBBroker sysBroker, final XmldbURI sysCollectionUri, final int permissions) throws EXistException, PermissionDeniedException {
Collection collection = sysBroker.getCollection(sysCollectionUri);
if (collection == null) {
final TransactionManager transact = getTransactionManager();
try (final Txn txn = transact.beginTransaction()) {
collection = sysBroker.getOrCreateCollection(txn, sysCollectionUri);
if (collection == null) {
throw new IOException("Could not create system collection: " + sysCollectionUri);
}
collection.setPermissions(sysBroker, permissions);
sysBroker.saveCollection(txn, collection);
transact.commit(txn);
} catch (final Exception e) {
e.printStackTrace();
final String msg = "Initialisation of system collections failed: " + e.getMessage();
LOG.error(msg, e);
throw new EXistException(msg, e);
}
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CollectionRemovalTest method removeCollection.
private void removeCollection(final String user, final String password, final XmldbURI uri) throws AuthenticationException, EXistException, PermissionDeniedException, IOException, TriggerException {
final BrokerPool pool = existEmbeddedServer.getBrokerPool();
final TransactionManager transact = pool.getTransactionManager();
try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().authenticate(user, password)));
final Txn transaction = transact.beginTransaction();
final Collection test = broker.openCollection(uri, LockMode.WRITE_LOCK)) {
broker.removeCollection(transaction, test);
transact.commit(transaction);
}
}
Aggregations