Search in sources :

Example 91 with XPathQueryService

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);
}
Also used : XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) XMLResource(org.xmldb.api.modules.XMLResource)

Example 92 with XPathQueryService

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);
    }
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 93 with XPathQueryService

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);
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Test(org.junit.Test)

Example 94 with XPathQueryService

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;
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Collection(org.xmldb.api.base.Collection)

Example 95 with XPathQueryService

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());
}
Also used : XPathQueryService(org.xmldb.api.modules.XPathQueryService) Resource(org.xmldb.api.base.Resource) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Aggregations

XPathQueryService (org.xmldb.api.modules.XPathQueryService)148 ResourceSet (org.xmldb.api.base.ResourceSet)123 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)92 XMLResource (org.xmldb.api.modules.XMLResource)60 Collection (org.xmldb.api.base.Collection)31 Test (org.junit.Test)22 Resource (org.xmldb.api.base.Resource)18 XMLDBException (org.xmldb.api.base.XMLDBException)14 EXistResource (org.exist.xmldb.EXistResource)10 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)9 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)8 IndexQueryService (org.exist.xmldb.IndexQueryService)6 IOException (java.io.IOException)3 ResourceIterator (org.xmldb.api.base.ResourceIterator)3 BinaryResource (org.xmldb.api.modules.BinaryResource)3 MalformedURLException (java.net.MalformedURLException)2 Path (java.nio.file.Path)2 Node (org.w3c.dom.Node)2 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1