Search in sources :

Example 86 with TransactionManager

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

Example 87 with TransactionManager

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);
        }
    }
}
Also used : TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) TerminatedException(org.exist.xquery.TerminatedException) XMLStreamException(javax.xml.stream.XMLStreamException) SAXException(org.xml.sax.SAXException) EXistException(org.exist.EXistException) TransactionException(org.exist.storage.txn.TransactionException)

Example 88 with TransactionManager

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);
    }
}
Also used : IndexQuery(org.exist.storage.btree.IndexQuery) DOMFile(org.exist.storage.dom.DOMFile) StringWriter(java.io.StringWriter) TransactionManager(org.exist.storage.txn.TransactionManager) Value(org.exist.storage.btree.Value) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Test(org.junit.Test)

Example 89 with TransactionManager

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());
    }
}
Also used : InputStream(java.io.InputStream) Txn(org.exist.storage.txn.Txn) EXistException(org.exist.EXistException) IOException(java.io.IOException) UnsynchronizedByteArrayOutputStream(org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream) SAXException(org.xml.sax.SAXException) StringInputSource(org.exist.util.StringInputSource) LockException(org.exist.util.LockException) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) PermissionDeniedException(org.exist.security.PermissionDeniedException)

Example 90 with TransactionManager

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);
    }
}
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)

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