use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class StressTest method insertTags.
private void insertTags() throws XMLDBException {
final XUpdateQueryService service = (XUpdateQueryService) testCol.getService("XUpdateQueryService", "1.0");
final XPathQueryService xquery = (XPathQueryService) testCol.getService("XPathQueryService", "1.0");
final String[] tagsWritten = new String[RUNS];
for (int i = 0; i < RUNS; i++) {
final String tag = tags[i];
final String parent;
if (i > 0 && rand.nextInt(100) < 70) {
parent = "//" + tagsWritten[rand.nextInt(i) / 2];
} else {
parent = "/root";
}
final String xupdate = "<xupdate:modifications version=\"1.0\" xmlns:xupdate=\"http://www.xmldb.org/xupdate\">" + "<xupdate:append select=\"" + parent + "\">" + "<xupdate:element name=\"" + tag + "\"/>" + "</xupdate:append>" + "</xupdate:modifications>";
final long mods = service.updateResource("test.xml", xupdate);
assertEquals(mods, 1);
tagsWritten[i] = tag;
final String query = "//" + tagsWritten[rand.nextInt(i + 1)];
final ResourceSet result = xquery.query(query);
assertEquals(result.getSize(), 1);
}
final XMLResource res = (XMLResource) testCol.getResource("test.xml");
assertNotNull(res);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class StressTest method fetchDb.
private void fetchDb() throws XMLDBException {
final XPathQueryService xquery = (XPathQueryService) testCol.getService("XPathQueryService", "1.0");
final ResourceSet result = xquery.query("for $n in collection('" + XmldbURI.ROOT_COLLECTION + "/test')//* return local-name($n)");
for (int i = 0; i < result.getSize(); i++) {
final Resource r = result.getResource(i);
final String tag = r.getContent().toString();
final ResourceSet result2 = xquery.query("//" + tag);
assertEquals(result2.getSize(), 1);
}
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class AnnotationsTest method annotationInXQueryOptionsNamespaceFails.
@Test(expected = XMLDBException.class)
public void annotationInXQueryOptionsNamespaceFails() throws XMLDBException {
final String TEST_VALUE_CONSTANT = "hello world";
final String query = "declare namespace hello = 'http://www.w3.org/2011/xquery-options';\n" + "declare\n" + "%hello:world\n" + "function local:hello() {\n" + "'" + TEST_VALUE_CONSTANT + "'\n" + "};\n" + "local:hello()";
final XPathQueryService service = getQueryService();
service.query(query);
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class AnnotationsTest method getQueryService.
private XPathQueryService getQueryService() throws XMLDBException {
Collection testCollection = getTestCollection();
XPathQueryService service = (XPathQueryService) testCollection.getService("XPathQueryService", "1.0");
return service;
}
use of org.xmldb.api.modules.XPathQueryService in project exist by eXist-db.
the class AnnotationsTest method annotation.
@Test
public void annotation() throws XMLDBException {
final String TEST_VALUE_CONSTANT = "hello world";
final String query = "declare namespace hello = 'http://world.com';\n" + "declare\n" + "%hello:world\n" + "function local:hello() {\n" + "'" + TEST_VALUE_CONSTANT + "'\n" + "};\n" + "local:hello()";
final XPathQueryService service = getQueryService();
final ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
Resource res = result.getIterator().nextResource();
assertEquals(TEST_VALUE_CONSTANT, res.getContent());
}
Aggregations