Search in sources :

Example 6 with EXistXQueryService

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);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) StringSource(org.exist.source.StringSource) Source(org.exist.source.Source) StringSource(org.exist.source.StringSource)

Example 7 with EXistXQueryService

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());
}
Also used : Sequence(org.exist.xquery.value.Sequence) EXistXQueryService(org.exist.xmldb.EXistXQueryService)

Example 8 with EXistXQueryService

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);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) QName(org.exist.dom.QName)

Example 9 with EXistXQueryService

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);
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) QName(org.exist.dom.QName)

Example 10 with EXistXQueryService

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));
    }
}
Also used : EXistXQueryService(org.exist.xmldb.EXistXQueryService) StringSource(org.exist.source.StringSource) Test(org.junit.Test)

Aggregations

EXistXQueryService (org.exist.xmldb.EXistXQueryService)14 StringSource (org.exist.source.StringSource)6 Source (org.exist.source.Source)5 Test (org.junit.Test)4 BuildException (org.apache.tools.ant.BuildException)2 QName (org.exist.dom.QName)2 ResourceSet (org.xmldb.api.base.ResourceSet)2 XMLDBException (org.xmldb.api.base.XMLDBException)2 XMLResource (org.xmldb.api.modules.XMLResource)2 IOException (java.io.IOException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 PropertyHelper (org.apache.tools.ant.PropertyHelper)1 FileSet (org.apache.tools.ant.types.FileSet)1 Sequence (org.exist.xquery.value.Sequence)1 Collection (org.xmldb.api.base.Collection)1 Resource (org.xmldb.api.base.Resource)1 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)1