Search in sources :

Example 91 with BrokerPool

use of org.exist.storage.BrokerPool 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 92 with BrokerPool

use of org.exist.storage.BrokerPool 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 93 with BrokerPool

use of org.exist.storage.BrokerPool 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 94 with BrokerPool

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

the class LuceneIndexTest method MultiTermQueryRewriteMethod.

@Test
public void MultiTermQueryRewriteMethod() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException, XPathException {
    configureAndStore(COLLECTION_CONFIG8, XML9, "test.xml");
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final XQuery xquery = pool.getXQueryService();
        assertNotNull(xquery);
        Sequence seq = xquery.execute(broker, "declare namespace tei=\"http://www.tei-c.org/ns/1.0\";" + " for $expr in (\"au*\", \"ha*\", \"ma*\", \"za*\", \"ya*\", \"ra*\", \"qa*\")" + " let $query := <query><wildcard>{$expr}</wildcard></query>" + " return for $hit in //tei:p[ft:query(., $query)]" + " return util:expand($hit)//exist:match", null);
        assertNotNull(seq);
        assertEquals(10, seq.getItemCount());
        assertEquals("aus", seq.itemAt(0).getStringValue());
        seq = xquery.execute(broker, "declare namespace tei=\"http://www.tei-c.org/ns/1.0\";" + " for $expr in (\"ha*\", \"ma*\")" + " let $query := <query><wildcard>{$expr}</wildcard></query>" + " return for $hit in //tei:p[ft:query(., $query)]" + " return util:expand($hit)//exist:match", null);
        assertNotNull(seq);
        assertEquals(2, seq.getItemCount());
        assertEquals("haus", seq.itemAt(0).getStringValue());
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) XQuery(org.exist.xquery.XQuery) CompiledXQuery(org.exist.xquery.CompiledXQuery) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool)

Example 95 with BrokerPool

use of org.exist.storage.BrokerPool 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

BrokerPool (org.exist.storage.BrokerPool)381 DBBroker (org.exist.storage.DBBroker)300 Txn (org.exist.storage.txn.Txn)180 Sequence (org.exist.xquery.value.Sequence)157 Test (org.junit.Test)115 XQuery (org.exist.xquery.XQuery)105 Collection (org.exist.collections.Collection)71 StringInputSource (org.exist.util.StringInputSource)66 TransactionManager (org.exist.storage.txn.TransactionManager)61 Source (org.exist.source.Source)43 StringSource (org.exist.source.StringSource)40 CompiledXQuery (org.exist.xquery.CompiledXQuery)38 Path (java.nio.file.Path)22 XmldbURI (org.exist.xmldb.XmldbURI)21 XPathException (org.exist.xquery.XPathException)21 Properties (java.util.Properties)20 LockedDocument (org.exist.dom.persistent.LockedDocument)20 InputSource (org.xml.sax.InputSource)20 IOException (java.io.IOException)19 XQueryContext (org.exist.xquery.XQueryContext)19