use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.
the class DBUtils method xquery.
public static ResourceSet xquery(final Collection collection, final String xquery) throws XMLDBException {
final EXistXQueryService service = getXQueryService(collection);
final Source source = new StringSource(xquery);
return service.execute(source);
}
use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.
the class CleanupTest method resetStateOfModuleVars.
@Test
public void resetStateOfModuleVars() throws XMLDBException, XPathException {
final EXistXQueryService service = (EXistXQueryService) collection.getService("XQueryService", "1.0");
final CompiledExpression compiled = service.compile(TEST_QUERY);
final Module[] modules = ((PathExpr) compiled).getContext().getModules(MODULE_NS);
assertEquals(1, modules.length);
final Module module = modules[0];
final java.util.Collection<VariableDeclaration> varDecls = ((ExternalModule) module).getVariableDeclarations();
final Iterator<VariableDeclaration> vi = varDecls.iterator();
final VariableDeclaration var1 = vi.next();
final VariableDeclaration var2 = vi.next();
final FunctionCall root = (FunctionCall) ((PathExpr) compiled).getFirst();
final UserDefinedFunction calledFunc = root.getFunction();
final Expression calledBody = calledFunc.getFunctionBody();
// set some property so we can test if it gets cleared
calledFunc.setContextDocSet(DocumentSet.EMPTY_DOCUMENT_SET);
calledBody.setContextDocSet(DocumentSet.EMPTY_DOCUMENT_SET);
var1.setContextDocSet(DocumentSet.EMPTY_DOCUMENT_SET);
var2.setContextDocSet(DocumentSet.EMPTY_DOCUMENT_SET);
// execute query and check result
final ResourceSet result = service.execute(compiled);
assertEquals(result.getSize(), 1);
assertEquals(result.getResource(0).getContent(), "Hello world123");
Sequence[] args = calledFunc.getCurrentArguments();
assertNull(args);
assertNull(calledFunc.getContextDocSet());
assertNull(calledBody.getContextDocSet());
assertNull(var1.getContextDocSet());
assertNull(var2.getContextDocSet());
}
use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.
the class CleanupTest method resetStateofInternalModule.
@Test
public void resetStateofInternalModule() throws XMLDBException, XPathException {
final EXistXQueryService service = (EXistXQueryService) collection.getService("XQueryService", "1.0");
final CompiledExpression compiled = service.compile(INTERNAL_MODULE_TEST);
final Module[] modules = ((PathExpr) compiled).getContext().getModules(MODULE_NS);
assertEquals(1, modules.length);
final Module module = modules[0];
module.declareVariable(new QName("VAR", MODULE_NS, "t"), "TEST");
final InternalFunctionCall root = (InternalFunctionCall) ((PathExpr) compiled).getFirst();
final TestModule.TestFunction func = (TestModule.TestFunction) root.getFunction();
final ResourceSet result = service.execute(compiled);
assertEquals(result.getSize(), 1);
assertEquals(result.getResource(0).getContent(), "TEST");
assertFalse(func.dummyProperty);
}
use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.
the class CleanupTest method preserveExternalVariable.
@Test
public void preserveExternalVariable() throws XMLDBException, XPathException {
// see https://github.com/eXist-db/exist/pull/1512 and use of util:eval
final EXistXQueryService service = (EXistXQueryService) collection.getService("XQueryService", "1.0");
final CompiledExpression compiled = service.compile(INTERNAL_MODULE_EVAL_TEST);
final Module[] modules = ((PathExpr) compiled).getContext().getModules(MODULE_NS);
assertEquals(1, modules.length);
final Module module = modules[0];
module.declareVariable(new QName("VAR", MODULE_NS, "t"), "TEST");
final ResourceSet result = service.execute(compiled);
assertEquals(result.getSize(), 2);
assertEquals(result.getResource(1).getContent(), "TEST");
final Variable var = module.resolveVariable(new QName("VAR", MODULE_NS, "t"));
assertNull(var);
}
use of org.exist.xmldb.EXistXQueryService in project exist by eXist-db.
the class QueryPoolTest method differentQueries.
@Test
public void differentQueries() throws XMLDBException {
EXistXQueryService service = (EXistXQueryService) testCollection.getService("XQueryService", "1.0");
for (int i = 0; i < 1000; i++) {
String query = "update insert <node id='id" + Integer.toHexString(i) + "'>" + "Some longer text <b>content</b> in this node. Some longer text <b>content</b> in this node. " + "Some longer text <b>content</b> in this node. Some longer text <b>content</b> in this node." + "</node> " + "into //test[@id = 't1']";
service.execute(new StringSource(query));
}
}
Aggregations