use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class SerializationTest method xqueryUpdateNsTest.
@Test
public void xqueryUpdateNsTest() throws XMLDBException {
final XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
final ResourceSet result = service.query("xquery version \"1.0\";" + EOL + "declare namespace foo=\"http://foo.com\";" + EOL + "let $in-memory :=" + EOL + XML + EOL + "let $on-disk := doc('/db/" + TEST_COLLECTION_NAME + '/' + XML_DOC_NAME + "')" + EOL + "let $new-node := <entry xml:id='aargh'/>" + EOL + "let $update := update insert $new-node into $on-disk/foo:root" + EOL + "return" + EOL + " (" + EOL + " $in-memory," + EOL + " $on-disk" + EOL + " )" + EOL);
assertEquals(2, result.getSize());
final Resource inMemoryResource = result.getResource(0);
assertXMLEquals(XML, inMemoryResource);
final Resource onDiskResource = result.getResource(1);
assertXMLEquals(XML_UPDATED_EXPECTED, onDiskResource);
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class AbstractTestUpdate method storeXMLStringAndGetQueryService.
/**
* stores XML String and get Query Service
* @param documentName to be stored in the DB
* @param content to be stored in the DB
* @return the XQuery Service
* @throws XMLDBException
*/
protected XQueryService storeXMLStringAndGetQueryService(final String documentName, final String content) throws XMLDBException {
final XMLResource doc = (XMLResource) testCollection.createResource(documentName, "XMLResource");
doc.setContent(content);
testCollection.storeResource(doc);
final XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
return service;
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class TriggerConfigTest method updateTriggers.
@Test
public void updateTriggers() {
try {
Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
iqs.configureCollection(EMPTY_COLLECTION_CONFIG);
Collection configCol = DatabaseManager.getCollection(BASE_URI + "/db/system/config" + testCollection, "admin", "");
Resource resource = configCol.createResource(DEFAULT_COLLECTION_CONFIG_FILE, "XMLResource");
resource.setContent(COLLECTION_CONFIG);
configCol.storeResource(resource);
resource = root.createResource("data.xml", "XMLResource");
resource.setContent(DOCUMENT_CONTENT);
root.storeResource(resource);
XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
ResourceSet result = qs.query("if (doc-available('" + testCollection + "/messages.xml')) then doc('" + testCollection + "/messages.xml')/events/event[@id = 'STORE-DOCUMENT']/string(@collection) else ()");
assertEquals(1, result.getSize());
assertEquals(testCollection, result.getResource(0).getContent());
} catch (XMLDBException e) {
LOG.error(e.getMessage(), e);
fail(e.getMessage());
}
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class TriggerConfigTest method storeDocument.
@Test
public void storeDocument() {
try {
Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
iqs.configureCollection(COLLECTION_CONFIG);
Resource resource = root.createResource("data.xml", "XMLResource");
resource.setContent(DOCUMENT_CONTENT);
root.storeResource(resource);
XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
ResourceSet result = qs.queryResource("messages.xml", "string(//event[last()]/@collection)");
assertEquals(1, result.getSize());
assertEquals(testCollection, result.getResource(0).getContent());
} catch (XMLDBException e) {
LOG.error(e.getMessage(), e);
fail(e.getMessage());
}
}
use of org.xmldb.api.modules.XQueryService in project exist by eXist-db.
the class TriggerConfigTest method removeDocument.
@Test
public void removeDocument() {
try {
Collection root = DatabaseManager.getCollection(BASE_URI + testCollection, "admin", "");
IndexQueryService iqs = (IndexQueryService) root.getService("IndexQueryService", "1.0");
iqs.configureCollection(COLLECTION_CONFIG);
Resource resource = root.createResource("data.xml", "XMLResource");
resource.setContent(DOCUMENT_CONTENT);
root.storeResource(resource);
root.removeResource(resource);
XQueryService qs = (XQueryService) root.getService("XQueryService", "1.0");
ResourceSet result = qs.queryResource("messages.xml", "string(//event[last()]/@collection)");
assertEquals(1, result.getSize());
assertEquals(testCollection, result.getResource(0).getContent());
} catch (XMLDBException e) {
LOG.error(e.getMessage(), e);
fail(e.getMessage());
}
}
Aggregations