Search in sources :

Example 96 with TransactionManager

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);
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn)

Example 97 with TransactionManager

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);
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn)

Example 98 with TransactionManager

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();
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) XmldbURI(org.exist.xmldb.XmldbURI)

Example 99 with TransactionManager

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);
        }
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) IOException(java.io.IOException) EXistException(org.exist.EXistException) EXistException(org.exist.EXistException) IOException(java.io.IOException) TransactionException(org.exist.storage.txn.TransactionException)

Example 100 with TransactionManager

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);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Aggregations

TransactionManager (org.exist.storage.txn.TransactionManager)131 Txn (org.exist.storage.txn.Txn)128 Collection (org.exist.collections.Collection)86 DBBroker (org.exist.storage.DBBroker)70 BrokerPool (org.exist.storage.BrokerPool)61 StringInputSource (org.exist.util.StringInputSource)27 EXistException (org.exist.EXistException)21 XmldbURI (org.exist.xmldb.XmldbURI)20 Sequence (org.exist.xquery.value.Sequence)20 XQuery (org.exist.xquery.XQuery)18 InputSource (org.xml.sax.InputSource)18 DocumentImpl (org.exist.dom.persistent.DocumentImpl)17 Test (org.junit.Test)16 DefaultDocumentSet (org.exist.dom.persistent.DefaultDocumentSet)15 InputStream (java.io.InputStream)14 StringReader (java.io.StringReader)13 MutableDocumentSet (org.exist.dom.persistent.MutableDocumentSet)13 PermissionDeniedException (org.exist.security.PermissionDeniedException)13 IOException (java.io.IOException)12 Modification (org.exist.xupdate.Modification)12