Search in sources :

Example 66 with TransactionManager

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

the class LuceneIndexTest method dropDocuments.

@Test
public void dropDocuments() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException, XPathException {
    configureAndStore(COLLECTION_CONFIG1, SAMPLES.getShakespeareXmlSampleNames());
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final TransactionManager transact = pool.getTransactionManager();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final XQuery xquery = pool.getXQueryService();
        assertNotNull(xquery);
        try (final Txn transaction = transact.beginTransaction()) {
            Sequence seq = xquery.execute(broker, "//LINE[ft:query(., 'bark')]", null);
            assertNotNull(seq);
            assertEquals(6, seq.getItemCount());
            root.removeXMLResource(transaction, broker, XmldbURI.create("r_and_j.xml"));
            transact.commit(transaction);
            seq = xquery.execute(broker, "//LINE[ft:query(., 'bark')]", null);
            assertNotNull(seq);
            assertEquals(3, seq.getItemCount());
        }
        try (final Txn transaction = transact.beginTransaction()) {
            root.removeXMLResource(transaction, broker, XmldbURI.create("hamlet.xml"));
            transact.commit(transaction);
            Sequence seq = xquery.execute(broker, "//LINE[ft:query(., 'bark')]", null);
            assertNotNull(seq);
            assertEquals(1, seq.getItemCount());
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) XQuery(org.exist.xquery.XQuery) CompiledXQuery(org.exist.xquery.CompiledXQuery) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool)

Example 67 with TransactionManager

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

the class LuceneIndexTest method xupdateRemove.

/**
 * Remove nodes from different levels of the tree and check if the index is
 * correctly updated.
 */
@Test
public void xupdateRemove() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, LockException, IOException, XPathException, ParserConfigurationException, QName.IllegalQNameException {
    final DocumentSet docs = configureAndStore(COLLECTION_CONFIG2, XML2, "xupdate.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()) {
        checkIndex(docs, broker, new QName[] { new QName("description") }, "chair", 1);
        checkIndex(docs, broker, new QName[] { new QName("item") }, null, 5);
        checkIndex(docs, broker, new QName[] { new QName("condition") }, null, 2);
        final XQuery xquery = pool.getXQueryService();
        assertNotNull(xquery);
        Sequence seq = xquery.execute(broker, "//item[ft:query(description, 'chair')]", null);
        assertNotNull(seq);
        assertEquals(1, seq.getItemCount());
        final XUpdateProcessor proc = new XUpdateProcessor(broker, docs);
        assertNotNull(proc);
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        String xupdate = XUPDATE_START + "   <xu:remove select=\"//item[@id='2']/condition\"/>" + XUPDATE_END;
        Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        checkIndex(docs, broker, new QName[] { new QName("condition") }, null, 1);
        checkIndex(docs, broker, new QName[] { new QName("item") }, null, 4);
        checkIndex(docs, broker, new QName[] { new QName("condition") }, "good", 0);
        checkIndex(docs, broker, new QName[] { new QName("item") }, "good", 0);
        Occurrences[] o = checkIndex(docs, broker, new QName[] { new QName("description") }, "table", 1);
        assertEquals("table", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("description") }, "cabinet", 1);
        assertEquals("cabinet", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "table", 1);
        assertEquals("table", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "cabinet", 1);
        assertEquals("cabinet", o[0].getTerm());
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        xupdate = XUPDATE_START + "   <xu:remove select=\"//item[@id='3']/description/text()\"/>" + XUPDATE_END;
        modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        xupdate = XUPDATE_START + "   <xu:remove select=\"//item[@id='1']\"/>" + XUPDATE_END;
        modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        o = checkIndex(docs, broker, new QName[] { new QName("description") }, null, 1);
        assertEquals("table", o[0].getTerm());
        checkIndex(docs, broker, new QName[] { new QName("description") }, "chair", 0);
        checkIndex(docs, broker, new QName[] { new QName("item") }, "chair", 0);
        transact.commit(transaction);
    }
}
Also used : XUpdateProcessor(org.exist.xupdate.XUpdateProcessor) Modification(org.exist.xupdate.Modification) InputSource(org.xml.sax.InputSource) QName(org.exist.dom.QName) XQuery(org.exist.xquery.XQuery) CompiledXQuery(org.exist.xquery.CompiledXQuery) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) StringReader(java.io.StringReader) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) DocumentSet(org.exist.dom.persistent.DocumentSet) MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) BrokerPool(org.exist.storage.BrokerPool)

Example 68 with TransactionManager

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

the class LuceneIndexTest method xupdateInsert.

/**
 * Remove nodes from different levels of the tree and check if the index is
 * correctly updated.
 */
@Test
public void xupdateInsert() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, LockException, IOException, XPathException, ParserConfigurationException, QName.IllegalQNameException {
    final DocumentSet docs = configureAndStore(COLLECTION_CONFIG2, XML2, "xupdate.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()) {
        final Occurrences[] occur = checkIndex(docs, broker, new QName[] { new QName("description") }, "chair", 1);
        assertEquals("chair", occur[0].getTerm());
        checkIndex(docs, broker, new QName[] { new QName("item") }, null, 5);
        final XQuery xquery = pool.getXQueryService();
        assertNotNull(xquery);
        Sequence seq = xquery.execute(broker, "//item[ft:query(description, 'chair')]", null);
        assertNotNull(seq);
        assertEquals(1, seq.getItemCount());
        // Append to root node
        final XUpdateProcessor proc = new XUpdateProcessor(broker, docs);
        assertNotNull(proc);
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        String xupdate = XUPDATE_START + "   <xu:append select=\"/test\">" + "       <item id='4'><description>Armchair</description> <condition>bad</condition></item>" + "   </xu:append>" + XUPDATE_END;
        Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        Occurrences[] o = checkIndex(docs, broker, new QName[] { new QName("condition") }, null, 2);
        checkIndex(docs, broker, new QName[] { new QName("description") }, null, 4);
        checkIndex(docs, broker, new QName[] { new QName("item") }, null, 6);
        o = checkIndex(docs, broker, new QName[] { new QName("condition") }, "bad", 1);
        assertEquals("bad", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("description") }, "armchair", 1);
        assertEquals("armchair", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "bad", 1);
        assertEquals("bad", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "armchair", 1);
        assertEquals("armchair", o[0].getTerm());
        // Insert before top element
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        xupdate = XUPDATE_START + "       <xu:insert-before select=\"//item[@id = '1']\">" + "           <item id='0'><description>Wheelchair</description> <condition>poor</condition></item>" + "       </xu:insert-before>" + XUPDATE_END;
        modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        checkIndex(docs, broker, new QName[] { new QName("condition") }, null, 3);
        checkIndex(docs, broker, new QName[] { new QName("description") }, null, 5);
        checkIndex(docs, broker, new QName[] { new QName("item") }, null, 8);
        o = checkIndex(docs, broker, new QName[] { new QName("condition") }, "poor", 1);
        assertEquals("poor", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("description") }, "wheelchair", 1);
        assertEquals("wheelchair", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "poor", 1);
        assertEquals("poor", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "wheelchair", 1);
        assertEquals("wheelchair", o[0].getTerm());
        // Insert after element
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        xupdate = XUPDATE_START + "       <xu:insert-after select=\"//item[@id = '1']\">" + "           <item id='1.1'><description>refrigerator</description> <condition>perfect</condition></item>" + "       </xu:insert-after>" + XUPDATE_END;
        modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        checkIndex(docs, broker, new QName[] { new QName("condition") }, null, 4);
        checkIndex(docs, broker, new QName[] { new QName("description") }, null, 6);
        checkIndex(docs, broker, new QName[] { new QName("item") }, null, 10);
        o = checkIndex(docs, broker, new QName[] { new QName("condition") }, "perfect", 1);
        assertEquals("perfect", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("description") }, "refrigerator", 1);
        assertEquals("refrigerator", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "perfect", 1);
        assertEquals("perfect", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "refrigerator", 1);
        assertEquals("refrigerator", o[0].getTerm());
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        xupdate = XUPDATE_START + "       <xu:insert-after select=\"//item[@id = '1']/description\">" + "           <condition>average</condition>" + "       </xu:insert-after>" + XUPDATE_END;
        modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        checkIndex(docs, broker, new QName[] { new QName("condition") }, null, 5);
        checkIndex(docs, broker, new QName[] { new QName("item") }, null, 11);
        o = checkIndex(docs, broker, new QName[] { new QName("condition") }, "average", 1);
        assertEquals("average", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "average", 1);
        assertEquals("average", o[0].getTerm());
        // Insert before nested element
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        xupdate = XUPDATE_START + "       <xu:insert-before select=\"//item[@id = '1']/description\">" + "           <condition>awesome</condition>" + "       </xu:insert-before>" + XUPDATE_END;
        modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        checkIndex(docs, broker, new QName[] { new QName("condition") }, null, 6);
        checkIndex(docs, broker, new QName[] { new QName("item") }, null, 12);
        o = checkIndex(docs, broker, new QName[] { new QName("condition") }, "awesome", 1);
        assertEquals("awesome", o[0].getTerm());
        o = checkIndex(docs, broker, new QName[] { new QName("item") }, "awesome", 1);
        assertEquals("awesome", o[0].getTerm());
        // Overwrite attribute
        proc.setBroker(broker);
        proc.setDocumentSet(docs);
        xupdate = XUPDATE_START + "       <xu:append select=\"//item[@id = '1']\">" + "           <xu:attribute name=\"attr\">abc</xu:attribute>" + "       </xu:append>" + XUPDATE_END;
        modifications = proc.parse(new InputSource(new StringReader(xupdate)));
        assertNotNull(modifications);
        modifications[0].process(transaction);
        proc.reset();
        QName[] qnattr = { new QName("attr", XMLConstants.NULL_NS_URI, XMLConstants.DEFAULT_NS_PREFIX, ElementValue.ATTRIBUTE) };
        o = checkIndex(docs, broker, qnattr, null, 1);
        assertEquals("abc", o[0].getTerm());
        checkIndex(docs, broker, qnattr, "attribute", 0);
        transact.commit(transaction);
    }
}
Also used : XUpdateProcessor(org.exist.xupdate.XUpdateProcessor) Modification(org.exist.xupdate.Modification) InputSource(org.xml.sax.InputSource) QName(org.exist.dom.QName) XQuery(org.exist.xquery.XQuery) CompiledXQuery(org.exist.xquery.CompiledXQuery) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) StringReader(java.io.StringReader) DefaultDocumentSet(org.exist.dom.persistent.DefaultDocumentSet) DocumentSet(org.exist.dom.persistent.DocumentSet) MutableDocumentSet(org.exist.dom.persistent.MutableDocumentSet) BrokerPool(org.exist.storage.BrokerPool)

Example 69 with TransactionManager

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

the class LuceneIndexTest 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()) {
        root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
        assertNotNull(root);
        broker.saveCollection(transaction, root);
        transact.commit(transaction);
        final Configuration config = BrokerPool.getInstance().getConfiguration();
        savedConfig = (Boolean) config.getProperty(Indexer.PROPERTY_PRESERVE_WS_MIXED_CONTENT);
        config.setProperty(Indexer.PROPERTY_PRESERVE_WS_MIXED_CONTENT, Boolean.TRUE);
    }
}
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 70 with TransactionManager

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

the class LuceneIndexTest method dropSingleDoc.

@Test
public void dropSingleDoc() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException {
    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()) {
        root.removeXMLResource(transaction, broker, XmldbURI.create("dropDocument.xml"));
        transact.commit(transaction);
        checkIndex(docs, broker, null, null, 0);
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) TransactionManager(org.exist.storage.txn.TransactionManager) 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