Search in sources :

Example 71 with TransactionManager

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

the class MatchListenerTest method configureAndStore.

private void configureAndStore(String config, String xml) throws PermissionDeniedException, IOException, SAXException, EXistException, LockException, CollectionConfigurationException {
    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(xml), 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 72 with TransactionManager

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

the class MatchListenerTest method startDB.

@BeforeClass
public static void startDB() throws EXistException, DatabaseConfigurationException, 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()) {
        final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(root);
        broker.saveCollection(transaction, root);
        transact.commit(transaction);
    }
    final HashMap<String, String> m = new HashMap<String, String>();
    m.put("tei", "http://www.tei-c.org/ns/1.0");
    m.put("exist", "http://exist.sourceforge.net/NS/exist");
    final NamespaceContext ctx = new SimpleNamespaceContext(m);
    XMLUnit.setXpathNamespaceContext(ctx);
}
Also used : DBBroker(org.exist.storage.DBBroker) HashMap(java.util.HashMap) TransactionManager(org.exist.storage.txn.TransactionManager) NamespaceContext(org.custommonkey.xmlunit.NamespaceContext) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) SimpleNamespaceContext(org.custommonkey.xmlunit.SimpleNamespaceContext) BrokerPool(org.exist.storage.BrokerPool) BeforeClass(org.junit.BeforeClass)

Example 73 with TransactionManager

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

the class MatchListenerTest method closeDB.

@AfterClass
public static void closeDB() 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()) {
        final Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(root);
        broker.removeCollection(transaction, root);
        final Collection config = broker.getOrCreateCollection(transaction, XmldbURI.create(CollectionConfigurationManager.CONFIG_COLLECTION + "/db"));
        assertNotNull(config);
        broker.removeCollection(transaction, config);
        transact.commit(transaction);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) Collection(org.exist.collections.Collection) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) AfterClass(org.junit.AfterClass)

Example 74 with TransactionManager

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

the class CustomIndexTest method xupdateRename.

@Test
public void xupdateRename() throws EXistException, LockException, XPathException, PermissionDeniedException, SAXException, IOException, ParserConfigurationException {
    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()) {
        checkIndex(broker, docs, "cha", 1);
        checkIndex(broker, docs, "le8", 1);
        XQuery xquery = pool.getXQueryService();
        assertNotNull(xquery);
        Sequence seq = xquery.execute(broker, "//item[ngram:contains(., 'cha')]", null);
        assertNotNull(seq);
        assertEquals(1, seq.getItemCount());
        XUpdateProcessor proc = new XUpdateProcessor(broker, docs);
        assertNotNull(proc);
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        String xupdate = XUPDATE_START + "   <xu:rename select=\"//item[@id='2']\">renamed</xu:rename>" + XUPDATE_END;
        Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        checkIndex(broker, docs, "tab", 0);
        transact.commit(transaction);
    }
}
Also used : XUpdateProcessor(org.exist.xupdate.XUpdateProcessor) Modification(org.exist.xupdate.Modification) DBBroker(org.exist.storage.DBBroker) InputSource(org.xml.sax.InputSource) TransactionManager(org.exist.storage.txn.TransactionManager) XQuery(org.exist.xquery.XQuery) StringReader(java.io.StringReader) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool)

Example 75 with TransactionManager

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

the class CustomIndexTest method setUp.

@Before
public void setUp() throws DatabaseConfigurationException, 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()) {
        Collection root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(root);
        broker.saveCollection(transaction, root);
        CollectionConfigurationManager mgr = pool.getConfigurationManager();
        mgr.addConfiguration(transaction, broker, root, COLLECTION_CONFIG);
        docs = new DefaultDocumentSet();
        broker.storeDocument(transaction, XmldbURI.create("test_string.xml"), new StringInputSource(XML), MimeType.XML_TYPE, root);
        docs.add(root.getDocument(broker, XmldbURI.create("test_string.xml")));
        broker.storeDocument(transaction, XmldbURI.create("test_string2.xml"), new StringInputSource(XML2), MimeType.XML_TYPE, root);
        docs.add(root.getDocument(broker, XmldbURI.create("test_string2.xml")));
        transact.commit(transaction);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) 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)

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