use of org.xmldb.api.base.CompiledExpression in project exist by eXist-db.
the class StoredModuleTest method testQuery.
@Test
public void testQuery() throws Exception {
Collection c = createCollection("test");
writeModule(c, "test.xqm", MODULE);
String query = "import module namespace itg-modules = \"http://localhost:80/itg/xquery\" at " + "\"xmldb:exist://" + XmldbURI.ROOT_COLLECTION + "/test/test.xqm\"; itg-modules:check-coll()";
String[] cols = { "one", "two", "three" };
final XQueryService xqService = (XQueryService) existEmbeddedServer.getRoot().getService("XQueryService", "1.0");
xqService.setNamespace("itg-modules", "http://localhost:80/itg/xquery");
CompiledExpression compiledQuery = xqService.compile(query);
for (int i = 0; i < cols.length; i++) {
xqService.declareVariable("itg-modules:coll", cols[i]);
ResourceSet result = xqService.execute(compiledQuery);
result.getResource(0).getContent();
}
}
use of org.xmldb.api.base.CompiledExpression in project exist by eXist-db.
the class TestDataGenerator method generate.
public Path[] generate(final org.xmldb.api.base.Collection collection, final String xqueryContent) throws SAXException {
final String query = IMPORT + xqueryContent;
try {
final XQueryService service = (XQueryService) collection.getService("XQueryService", "1.0");
service.declareVariable("filename", "");
service.declareVariable("count", "0");
final CompiledExpression compiled = service.compile(query);
for (int i = 0; i < count; i++) {
generatedFiles[i] = Files.createTempFile(prefix, ".xml");
service.declareVariable("filename", generatedFiles[i].getFileName().toString());
service.declareVariable("count", new Integer(i));
final ResourceSet result = service.execute(compiled);
try (final Writer out = Files.newBufferedWriter(generatedFiles[i], StandardCharsets.UTF_8)) {
final SAXSerializer sax = new SAXSerializer(out, outputProps);
for (ResourceIterator iter = result.getIterator(); iter.hasMoreResources(); ) {
XMLResource r = (XMLResource) iter.nextResource();
r.getContentAsSAX(sax);
}
}
}
} catch (final XMLDBException | IOException e) {
LOG.error(e.getMessage(), e);
throw new SAXException(e.getMessage(), e);
}
return generatedFiles;
}
use of org.xmldb.api.base.CompiledExpression in project exist by eXist-db.
the class RemoteQueryTest method resourceSet.
@Test
public void resourceSet() throws XMLDBException {
String query = "//SPEECH[SPEAKER = 'HAMLET']";
XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
service.setProperty("highlight-matches", "none");
CompiledExpression compiled = service.compile(query);
ResourceSet result = service.execute(compiled);
assertEquals(result.getSize(), 359);
for (int i = 0; i < result.getSize(); i++) {
XMLResource r = (XMLResource) result.getResource(i);
Node node = r.getContentAsDOM().getFirstChild();
}
}
use of org.xmldb.api.base.CompiledExpression in project exist by eXist-db.
the class RemoteQueryTest method externalVar.
@Test
public void externalVar() throws XMLDBException {
String query = XmlRpcTest.QUERY_MODULE_DATA;
XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
service.setProperty("highlight-matches", "none");
service.setNamespace("tm", "http://exist-db.org/test/module");
service.setNamespace("tm-query", "http://exist-db.org/test/module/query");
service.declareVariable("tm:imported-external-string", "imported-string-value");
service.declareVariable("tm-query:local-external-string", "local-string-value");
CompiledExpression compiled = service.compile(query);
ResourceSet result = service.execute(compiled);
assertEquals(result.getSize(), 2);
for (int i = 0; i < result.getSize(); i++) {
XMLResource r = (XMLResource) result.getResource(i);
}
}
Aggregations