Search in sources :

Example 16 with TransactionManager

use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.

the class LuceneMatchListenerTest method configureAndStore.

private void configureAndStore(final String config, final String data) throws EXistException, PermissionDeniedException, IOException, SAXException, CollectionConfigurationException, 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);
        assertNotNull(root);
        final CollectionConfigurationManager mgr = pool.getConfigurationManager();
        mgr.addConfiguration(transaction, broker, root, config);
        broker.storeDocument(transaction, XmldbURI.create("test_matches.xml"), new StringInputSource(data), MimeType.XML_TYPE, root);
        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) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 17 with TransactionManager

use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.

the class SerializeAttrMatchesTest method configureAndStore.

private DocumentSet configureAndStore(final String configuration, final String data, final String docName) throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException {
    final MutableDocumentSet docs = new DefaultDocumentSet();
    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()) {
        if (configuration != null) {
            final CollectionConfigurationManager mgr = pool.getConfigurationManager();
            mgr.addConfiguration(transaction, broker, test, configuration);
        }
        broker.storeDocument(transaction, XmldbURI.create(docName), new StringInputSource(data), MimeType.XML_TYPE, test);
        docs.add(test.getDocument(broker, XmldbURI.create(docName)));
        transact.commit(transaction);
    }
    return docs;
}
Also used : MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) DBBroker(org.exist.storage.DBBroker) StringInputSource(org.exist.util.StringInputSource) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) TransactionManager(org.exist.storage.txn.TransactionManager) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 18 with TransactionManager

use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.

the class SerializeAttrMatchesTest method setup.

@Before
public void setup() 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()) {
        test = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        broker.saveCollection(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)

Example 19 with TransactionManager

use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.

the class LuceneIndexTest method configureAndStore.

private DocumentSet configureAndStore(final String configuration, final String data, final String docName) throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException {
    final MutableDocumentSet docs = new DefaultDocumentSet();
    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()) {
        if (configuration != null) {
            final CollectionConfigurationManager mgr = pool.getConfigurationManager();
            mgr.addConfiguration(transaction, broker, root, configuration);
        }
        broker.storeDocument(transaction, XmldbURI.create(docName), new StringInputSource(data), MimeType.XML_TYPE, root);
        docs.add(root.getDocument(broker, XmldbURI.create(docName)));
        transact.commit(transaction);
    }
    return docs;
}
Also used : MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) DBBroker(org.exist.storage.DBBroker) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) TransactionManager(org.exist.storage.txn.TransactionManager) Txn(org.exist.storage.txn.Txn) CollectionConfigurationManager(org.exist.collections.CollectionConfigurationManager) BrokerPool(org.exist.storage.BrokerPool)

Example 20 with TransactionManager

use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.

the class LuceneIndexTest method reindex.

@Test
public void reindex() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, LockException, IOException, QName.IllegalQNameException {
    final DocumentSet docs = configureAndStore(COLLECTION_CONFIG1, XML1, "dropDocument.xml");
    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()) {
        broker.reindexCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        checkIndex(docs, broker, new QName[] { new QName("head") }, "title", 1);
        final Occurrences[] o = checkIndex(docs, broker, new QName[] { new QName("p") }, "with", 1);
        assertEquals(2, o[0].getOccurrences());
        checkIndex(docs, broker, new QName[] { new QName("hi") }, "just", 1);
        checkIndex(docs, broker, null, "in", 1);
        final QName attrQN = new QName("rend", XMLConstants.NULL_NS_URI, ElementValue.ATTRIBUTE);
        checkIndex(docs, broker, new QName[] { attrQN }, null, 2);
        checkIndex(docs, broker, new QName[] { attrQN }, "center", 1);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) QName(org.exist.dom.QName) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) DocumentSet(org.exist.dom.persistent.DocumentSet) MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) 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