Search in sources :

Example 31 with TransactionManager

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

Example 32 with TransactionManager

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

Example 33 with TransactionManager

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

Example 34 with TransactionManager

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

Example 35 with TransactionManager

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);
        }
    }
}
Also used : StringInputSource(org.exist.util.StringInputSource) TransactionManager(org.exist.storage.txn.TransactionManager) InputStream(java.io.InputStream) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) DocumentImpl(org.exist.dom.persistent.DocumentImpl)

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