use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexTest method updatesQName.
@Test
public void updatesQName() throws Exception {
configureCollection(CONFIG_QNAME);
storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
for (int i = 100; i <= 150; i++) {
String append = "<xu:modifications xmlns:xu=\"http://www.xmldb.org/xupdate\" version=\"1.0\">" + " <xu:append select=\"/items\">" + " <item id=\"i" + i + "\">" + " <itemno>" + i + "</itemno>" + " <name>New Item</name>" + " <price>55.50</price>" + " </item>" + " </xu:append>" + "</xu:modifications>";
String remove = "<xu:modifications xmlns:xu=\"http://www.xmldb.org/xupdate\" version=\"1.0\">" + " <xu:remove select=\"/items/item[itemno=" + i + "]\"/>" + "</xu:modifications>";
XPathQueryService query = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
XUpdateQueryService update = (XUpdateQueryService) testCollection.getService("XUpdateQueryService", "1.0");
long mods = update.updateResource(ITEMS_FILENAME, append);
assertEquals(mods, 1);
queryResource(query, ITEMS_FILENAME, "//((#exist:optimize#) { item[price = 55.50] })", 1);
queryResource(query, ITEMS_FILENAME, "//((#exist:optimize#) { item[@id = 'i" + i + "']})", 1);
queryResource(query, ITEMS_FILENAME, "//((#exist:optimize#) { item[itemno = " + i + "] })", 1);
mods = update.updateResource(ITEMS_FILENAME, remove);
assertEquals(mods, 1);
queryResource(query, ITEMS_FILENAME, "//((#exist:optimize#) { item[itemno = " + i + "] })", 0);
}
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexTest method strFunctionsQName.
@Test
public void strFunctionsQName() throws XMLDBException {
configureCollection(CONFIG_QNAME);
XMLResource resource = (XMLResource) testCollection.createResource("mondial-test.xml", "XMLResource");
resource.setContent(CITY);
testCollection.storeResource(resource);
XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
queryResource(service, "mondial-test.xml", "//city[starts-with(name, 'Berl')]", 1);
queryResource(service, "mondial-test.xml", "//city[starts-with(name, 'Berlin')]", 1);
queryResource(service, "mondial-test.xml", "//city[starts-with(name, 'erlin')]", 0);
queryResource(service, "mondial-test.xml", "//city[starts-with(name, 'Erl')]", 1);
queryResource(service, "mondial-test.xml", "//city[contains(name, 'erl')]", 1);
queryResource(service, "mondial-test.xml", "//city[contains(name, 'Berlin')]", 1);
queryResource(service, "mondial-test.xml", "//city[contains(name, 'Erl')]", 1);
queryResource(service, "mondial-test.xml", "//city[ends-with(name, 'Berlin')]", 1);
queryResource(service, "mondial-test.xml", "//city[ends-with(name, 'erlin')]", 1);
queryResource(service, "mondial-test.xml", "//city[ends-with(name, 'Ber')]", 0);
queryResource(service, "mondial-test.xml", "//city[matches(name, 'erl', 'i')]", 2);
queryResource(service, "mondial-test.xml", "//city[matches(name, 'Erl')]", 1);
queryResource(service, "mondial-test.xml", "//city[matches(name, 'Berlin', 'i')]", 1);
queryResource(service, "mondial-test.xml", "//city[matches(name, 'berlin', 'i')]", 1);
queryResource(service, "mondial-test.xml", "//city[matches(name, 'berlin')]", 0);
queryResource(service, "mondial-test.xml", "//city[matches(name, '^Berlin$')]", 1);
queryResource(service, "mondial-test.xml", "//city[matches(name, 'lin$', 'i')]", 1);
queryResource(service, "mondial-test.xml", "//city[matches(name, '.*lin$', 'i')]", 1);
queryResource(service, "mondial-test.xml", "//city[matches(name, '^lin$', 'i')]", 0);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexTest method qnameIndexStringMatchingFunctions2.
@Test
public void qnameIndexStringMatchingFunctions2() throws XMLDBException {
configureCollection(CONFIG_QNAME);
XMLResource resource = (XMLResource) testCollection.createResource("mondial-test.xml", "XMLResource");
resource.setContent(CITY);
testCollection.storeResource(resource);
XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
queryResource(service, "mondial-test.xml", "//city[ starts-with( name, '(*' ) ]", 0);
queryResource(service, "mondial-test.xml", "//city[ contains( name, '*' ) ]", 0);
queryResource(service, "mondial-test.xml", "//city[ ends-with( name, '(*' ) ]", 0);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XPathQueryTest method staticVariables.
@Test
public void staticVariables() throws XMLDBException {
final XMLResource doc = (XMLResource) testCollection.createResource("numbers.xml", "XMLResource");
doc.setContent(numbers);
testCollection.storeResource(doc);
XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
final EXistXPathQueryService service2 = (EXistXPathQueryService) service;
service2.declareVariable("name", "MONTAGUE");
service2.declareVariable("name", "43");
// ResourceSet result = service.query("//SPEECH[SPEAKER=$name]");
ResourceSet result = service2.query(doc, "//item[stock=$name]");
result = service2.query("$name");
assertEquals(1, result.getSize());
result = service2.query(doc, "//item[stock=43]");
assertEquals(1, result.getSize());
result = service2.query(doc, "//item");
assertEquals(4, result.getSize());
// assertEquals(10, result.getSize());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class XPathQueryTest method queryResource.
@Test
public void queryResource() throws XMLDBException {
XMLResource doc = (XMLResource) testCollection.createResource("strings.xml", "XMLResource");
doc.setContent(strings);
testCollection.storeResource(doc);
doc = (XMLResource) testCollection.createResource("strings2.xml", "XMLResource");
doc.setContent(strings);
testCollection.storeResource(doc);
final XPathQueryService query = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
ResourceSet result = query.queryResource("strings2.xml", "/test/string[. = 'Hello World!']");
assertEquals(1, result.getSize());
result = query.query("/test/string[. = 'Hello World!']");
assertEquals(2, result.getSize());
}
Aggregations