use of org.exist.storage.txn.Txn 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);
}
}
use of org.exist.storage.txn.Txn 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;
}
use of org.exist.storage.txn.Txn 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();
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class LuceneIndexTest method removeCollection.
@Test
public void removeCollection() throws EXistException, CollectionConfigurationException, PermissionDeniedException, SAXException, TriggerException, LockException, IOException, XPathException {
final DocumentSet docs = 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 Txn transaction = transact.beginTransaction()) {
final XQuery xquery = pool.getXQueryService();
assertNotNull(xquery);
Sequence seq = xquery.execute(broker, "//SPEECH[ft:query(LINE, 'love')]", null);
assertNotNull(seq);
assertEquals(166, seq.getItemCount());
broker.removeCollection(transaction, root);
root = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
assertNotNull(root);
broker.saveCollection(transaction, root);
transact.commit(transaction);
root = null;
checkIndex(docs, broker, null, null, 0);
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class LuceneIndexTest method xupdateReplace.
@Test
public void xupdateReplace() 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());
final XUpdateProcessor proc = new XUpdateProcessor(broker, docs);
assertNotNull(proc);
proc.setBroker(broker);
proc.setDocumentSet(docs);
String xupdate = XUPDATE_START + "<xu:replace select=\"//item[@id = '1']\">" + "<item id='4'><description>Wheelchair</description> <condition>poor</condition></item>" + "</xu:replace>" + 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("description") }, null, 3);
checkIndex(docs, broker, new QName[] { new QName("condition") }, null, 3);
checkIndex(docs, broker, new QName[] { new QName("item") }, null, 6);
checkIndex(docs, broker, new QName[] { new QName("description") }, "chair", 0);
checkIndex(docs, broker, new QName[] { new QName("item") }, "chair", 0);
Occurrences[] o = checkIndex(docs, broker, new QName[] { new QName("description") }, "wheelchair", 1);
assertEquals("wheelchair", o[0].getTerm());
o = checkIndex(docs, broker, new QName[] { new QName("condition") }, "poor", 1);
assertEquals("poor", o[0].getTerm());
o = checkIndex(docs, broker, new QName[] { new QName("item") }, "wheelchair", 1);
assertEquals("wheelchair", o[0].getTerm());
o = checkIndex(docs, broker, new QName[] { new QName("item") }, "poor", 1);
assertEquals("poor", o[0].getTerm());
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + "<xu:replace select=\"//item[@id = '4']/description\">" + "<description>Armchair</description>" + "</xu:replace>" + 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("description") }, null, 3);
checkIndex(docs, broker, new QName[] { new QName("item") }, null, 6);
checkIndex(docs, broker, new QName[] { new QName("description") }, "wheelchair", 0);
checkIndex(docs, broker, new QName[] { new QName("item") }, "wheelchair", 0);
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") }, "armchair", 1);
assertEquals("armchair", o[0].getTerm());
transact.commit(transaction);
}
}
Aggregations