use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexTest method indexScan.
@Test
public void indexScan() throws XMLDBException, URISyntaxException {
configureCollection(CONFIG_PATH);
String queryBody = "declare namespace f=\'http://exist-db.org/xquery/test\';\n" + "declare namespace mods='http://www.loc.gov/mods/v3';\n" + "import module namespace u=\'http://exist-db.org/xquery/util\';\n" + "\n" + "declare function f:term-callback($term as item(), $data as xs:int+)\n" + "as element()+ {\n" + " <item>\n" + " <term>{$term}</term>\n" + " <frequency>{$data[1]}</frequency>\n" + " </item>\n" + "};\n" + "\n";
XPathQueryService service = storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
String query = queryBody + "u:index-keys(//item/name, \'\', util:function(xs:QName(\'f:term-callback\'), 2), 1000)";
ResourceSet result = service.query(query);
for (ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
i.nextResource().getContent();
}
assertEquals(7, result.getSize());
query = queryBody + "u:index-keys(//item/stock, 0, util:function(xs:QName(\'f:term-callback\'), 2), 1000)";
result = service.query(query);
for (ResourceIterator i = result.getIterator(); i.hasMoreResources(); ) {
i.nextResource().getContent();
}
assertEquals(5, result.getSize());
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexTest method strings.
@Test
public void strings() throws XMLDBException, URISyntaxException {
configureCollection(CONFIG_PATH);
XPathQueryService service = storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
queryResource(service, ITEMS_FILENAME, "//item[@id = 'i2']", 1);
queryResource(service, ITEMS_FILENAME, "//item[name = 'Racing Bicycle']", 1);
queryResource(service, ITEMS_FILENAME, "//item[name > 'Racing Bicycle']", 4);
queryResource(service, ITEMS_FILENAME, "//item[itemno = 3]", 1);
queryResource(service, ITEMS_FILENAME, "//item[itemno eq 3]", 1);
ResourceSet result = queryResource(service, ITEMS_FILENAME, "for $i in //item[stock <= 10] return $i/itemno", 5);
for (long i = 0; i < result.getSize(); i++) {
Resource res = result.getResource(i);
}
queryResource(service, ITEMS_FILENAME, "//item[stock > 20]", 1);
queryResource(service, ITEMS_FILENAME, "declare namespace x=\"http://www.foo.com\"; //item[x:rating > 8.0]", 2);
queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\"; //item[@xx:test = 123]", 1);
queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\"; //item[@xx:test eq 123]", 1);
queryResource(service, ITEMS_FILENAME, "//item[mixed = 'uneven']", 1);
queryResource(service, ITEMS_FILENAME, "//item[mixed eq 'uneven']", 1);
queryResource(service, ITEMS_FILENAME, "//item[mixed = 'external']", 1);
queryResource(service, ITEMS_FILENAME, "//item[fn:matches(mixed, 'un.*')]", 2);
queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice = false()]", 2);
queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice = true()]", 1);
queryResource(service, ITEMS_FILENAME, "//item[price/@specialprice eq true()]", 1);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexTest method qnameIndex.
@Test
public void qnameIndex() throws XMLDBException, URISyntaxException {
configureCollection(CONFIG_QNAME);
XPathQueryService service = storeXMLFileAndGetQueryService(ITEMS_FILENAME, ITEMS_FILE);
queryResource(service, ITEMS_FILENAME, "//((#exist:optimize#) { item[stock = 10] })", 1);
queryResource(service, ITEMS_FILENAME, "//((#exist:optimize#) { item[stock > 20] })", 1);
queryResource(service, ITEMS_FILENAME, "//((#exist:optimize#) { item[stock < 16] })", 6);
queryResource(service, ITEMS_FILENAME, "declare namespace x=\"http://www.foo.com\"; " + "//((#exist:optimize#) { item[x:rating > 8.0] })", 2);
queryResource(service, ITEMS_FILENAME, "//((#exist:optimize#) { item[mixed = 'uneven'] })", 1);
queryResource(service, ITEMS_FILENAME, "//((#exist:optimize#) { item[mixed = 'external'] })", 1);
queryResource(service, ITEMS_FILENAME, "//((#exist:optimize#) { item[@id = 'i1'] })", 1);
queryResource(service, ITEMS_FILENAME, "declare namespace xx=\"http://test.com\";" + "//((#exist:optimize#) { item[@xx:test = 123] })", 1);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexTest method updates.
@Test
public void updates() throws Exception {
configureCollection(CONFIG_PATH);
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, "//item[price = 55.50]", 1);
queryResource(query, ITEMS_FILENAME, "//item[@id = 'i" + i + "']", 1);
mods = update.updateResource(ITEMS_FILENAME, remove);
assertEquals(mods, 1);
queryResource(query, ITEMS_FILENAME, "//item[itemno = " + i + "]", 0);
}
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class ValueIndexTest method pathIndexStringMatchingFunctions.
/*
* Bugfix
*
* These following two tests were put in place to demonstrate bugs in how the index matching functions work,
* as a precursor to a fix, which was committed 2/3/2010. The issue was that the 2nd parameter
* to the string matching functions was incorrectly interpreted as a regex, which causd an exception
* to be thrown if the string included characters that have special meaning in a regex, eg. '*' for contains.
*
* andrzej@chaeron.com
*/
@Test
public void pathIndexStringMatchingFunctions() throws XMLDBException {
configureCollection(CONFIG_PATH);
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);
}
Aggregations