use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CustomIndexTest method xupdateUpdate.
@Test
public void xupdateUpdate() 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:update select=\"//item[@id = '1']/description\">wardrobe</xu:update>" + XUPDATE_END;
Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "war", 1);
checkIndex(broker, docs, "cha", 0);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:update select=\"//item[@id = '1']/description/text()\">Wheelchair</xu:update>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "whe", 1);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:update select=\"//item[@id = '1']/@attr\">abc</xu:update>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "abc", 1);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CustomIndexTest method xupdateInsert.
@Test
public void xupdateInsert() 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:append select=\"/test\">" + " <item id='4'><description>Armchair</description><price>340</price></item>" + " </xu:append>" + XUPDATE_END;
Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "arm", 1);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:insert-before select=\"//item[@id = '1']\">" + " <item id='0'><description>Wheelchair</description><price>1230</price></item>" + " </xu:insert-before>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "hee", 1);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:insert-after select=\"//item[@id = '1']\">" + " <item id='1.1'><description>refrigerator</description><price>777</price></item>" + " </xu:insert-after>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "ref", 1);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:insert-after select=\"//item[@id = '1']/description\">" + " <price>999</price>" + " </xu:insert-after>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "999", 1);
checkIndex(broker, docs, "cha", 1);
checkIndex(broker, docs, "ir9", 1);
proc.setBroker(broker);
proc.setDocumentSet(docs);
xupdate = XUPDATE_START + " <xu:insert-before select=\"//item[@id = '1']/description\">" + " <price>888</price>" + " </xu:insert-before>" + XUPDATE_END;
modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "999", 1);
checkIndex(broker, docs, "888", 1);
checkIndex(broker, docs, "88c", 1);
checkIndex(broker, docs, "att", 1);
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();
checkIndex(broker, docs, "att", 0);
checkIndex(broker, docs, "abc", 1);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class CustomIndexTest method xupdateReplace.
@Test
public void xupdateReplace() throws LockException, XPathException, PermissionDeniedException, SAXException, EXistException, 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:replace select=\"//item[@id = '1']\">" + " <item id='4'><description>Wheelchair</description><price>809.50</price></item>" + " </xu:replace>" + XUPDATE_END;
Modification[] modifications = proc.parse(new InputSource(new StringReader(xupdate)));
assertNotNull(modifications);
modifications[0].process(transaction);
proc.reset();
checkIndex(broker, docs, "whe", 1);
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(broker, docs, "whe", 0);
checkIndex(broker, docs, "arm", 1);
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class SerializeAttrMatchesTest method cleanup.
@After
public void cleanup() 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 collConfig = broker.getOrCreateCollection(transaction, XmldbURI.create(XmldbURI.CONFIG_COLLECTION + "/db"));
broker.removeCollection(transaction, collConfig);
if (test != null) {
broker.removeCollection(transaction, test);
}
transact.commit(transaction);
}
}
use of org.exist.storage.txn.TransactionManager in project exist by eXist-db.
the class LuceneIndexTest method cleanup.
@After
public void cleanup() 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 collConfig = broker.getOrCreateCollection(transaction, XmldbURI.create(XmldbURI.CONFIG_COLLECTION + "/db"));
assertNotNull(collConfig);
broker.removeCollection(transaction, collConfig);
if (root != null) {
assertNotNull(root);
broker.removeCollection(transaction, root);
}
transact.commit(transaction);
final Configuration config = BrokerPool.getInstance().getConfiguration();
config.setProperty(Indexer.PROPERTY_PRESERVE_WS_MIXED_CONTENT, savedConfig);
}
}
Aggregations