Search in sources :

Example 16 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class CopyCollectionRecoveryTest method xmldbRead.

private void xmldbRead() throws XMLDBException {
    final org.xmldb.api.base.Collection test = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/destination/test3", "admin", "");
    assertNotNull(test);
    final Resource res = test.getResource("test_xmldb.xml");
    assertNotNull("Document should not be null", res);
    final org.xmldb.api.base.Collection root = DatabaseManager.getCollection(XmldbURI.LOCAL_DB, "admin", "");
    assertNotNull(root);
    final EXistCollectionManagementService mgr = (EXistCollectionManagementService) root.getService("CollectionManagementService", "1.0");
    assertNotNull(mgr);
    mgr.removeCollection("destination");
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Resource(org.xmldb.api.base.Resource) Database(org.xmldb.api.base.Database)

Example 17 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class UpdateRecoverTest method xmldbRead.

private void xmldbRead(final BrokerPool pool) throws XMLDBException {
    final org.xmldb.api.base.Collection test2 = DatabaseManager.getCollection("xmldb:exist://" + TestConstants.TEST_COLLECTION_URI2, "admin", "");
    assertNotNull(test2);
    final Resource res = test2.getResource("test_xmldb.xml");
    assertNotNull("Document should not be null", res);
    final org.xmldb.api.base.Collection root = DatabaseManager.getCollection(XmldbURI.LOCAL_DB, "admin", "");
    assertNotNull(root);
    final EXistCollectionManagementService mgr = (EXistCollectionManagementService) root.getService("CollectionManagementService", "1.0");
    assertNotNull(mgr);
    mgr.removeCollection("test");
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Resource(org.xmldb.api.base.Resource) Database(org.xmldb.api.base.Database)

Example 18 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class UpdateRecoverTest method xmldbStore.

private void xmldbStore(final BrokerPool pool) throws IllegalAccessException, DatabaseConfigurationException, InstantiationException, ClassNotFoundException, XMLDBException, EXistException {
    final org.xmldb.api.base.Collection root = DatabaseManager.getCollection(XmldbURI.LOCAL_DB, "admin", "");
    assertNotNull(root);
    final EXistCollectionManagementService mgr = (EXistCollectionManagementService) root.getService("CollectionManagementService", "1.0");
    assertNotNull(mgr);
    org.xmldb.api.base.Collection test = root.getChildCollection("test");
    if (test == null) {
        test = mgr.createCollection(TestConstants.TEST_COLLECTION_URI.toString());
    }
    assertNotNull(test);
    org.xmldb.api.base.Collection test2 = test.getChildCollection("test2");
    if (test2 == null) {
        test2 = mgr.createCollection(TestConstants.TEST_COLLECTION_URI2.toString());
    }
    assertNotNull(test2);
    final Resource res = test2.createResource("test_xmldb.xml", "XMLResource");
    assertNotNull(res);
    res.setContent(TEST_XML);
    test2.storeResource(res);
    final XUpdateQueryService service = (XUpdateQueryService) test2.getService("XUpdateQueryService", "1.0");
    assertNotNull(service);
    // insert some nodes
    for (int i = 1; i <= 200; i++) {
        final String xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:insert-before select=\"/products/product[1]\">" + "       <product>" + "           <description>Product " + i + "</description>" + "           <price>" + (i * 2.5) + "</price>" + "           <stock>" + (i * 10) + "</stock>" + "       </product>" + "   </xu:insert-before>" + "</xu:modifications>";
        service.updateResource("test_xmldb.xml", xupdate);
    }
    // add attribute
    for (int i = 1; i <= 200; i++) {
        final String xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:append select=\"/products/product[" + i + "]\">" + "         <xu:attribute name=\"id\">" + i + "</xu:attribute>" + " </xu:append>" + "</xu:modifications>";
        service.updateResource("test_xmldb.xml", xupdate);
    }
    // replace some
    for (int i = 1; i <= 100; i++) {
        final String xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:replace select=\"/products/product[" + i + "]\">" + "     <product id=\"" + i + "\">" + "         <description>Replaced product</description>" + "         <price>" + (i * 0.75) + "</price>" + "     </product>" + " </xu:replace>" + "</xu:modifications>";
        service.updateResource("test_xmldb.xml", xupdate);
    }
    // remove some
    for (int i = 1; i <= 100; i++) {
        final String xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:remove select=\"/products/product[last()]\"/>" + "</xu:modifications>";
        service.updateResource("test_xmldb.xml", xupdate);
    }
    for (int i = 1; i <= 100; i++) {
        final String xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:append select=\"/products\">" + "       <product>" + "           <xu:attribute name=\"id\"><xu:value-of select=\"count(/products/product) + 1\"/></xu:attribute>" + "           <description>Product " + i + "</description>" + "           <price>" + (i * 2.5) + "</price>" + "           <stock>" + (i * 10) + "</stock>" + "       </product>" + "   </xu:append>" + "</xu:modifications>";
        service.updateResource("test_xmldb.xml", xupdate);
    }
    // rename element "description" to "descript"
    String xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:rename select=\"/products/product/description\">descript</xu:rename>" + "</xu:modifications>";
    service.updateResource("test_xmldb.xml", xupdate);
    // update attribute values
    for (int i = 1; i <= 200; i++) {
        xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:update select=\"/products/product[" + i + "]/@id\">" + i + "u</xu:update>" + "</xu:modifications>";
        service.updateResource("test_xmldb.xml", xupdate);
    }
    // append new element to records
    for (int i = 1; i <= 200; i++) {
        xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:append select=\"/products/product[" + i + "]\">" + "       <date><xu:value-of select=\"current-dateTime()\"/></date>" + "   </xu:append>" + "</xu:modifications>";
        service.updateResource("test_xmldb.xml", xupdate);
    }
    // update element content
    for (int i = 1; i <= 200; i++) {
        xupdate = "<xu:modifications version=\"1.0\" xmlns:xu=\"http://www.xmldb.org/xupdate\">" + "   <xu:update select=\"/products/product[" + i + "]/price\">19.99</xu:update>" + "</xu:modifications>";
        service.updateResource("test_xmldb.xml", xupdate);
    }
}
Also used : XUpdateQueryService(org.xmldb.api.modules.XUpdateQueryService) EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Resource(org.xmldb.api.base.Resource) Database(org.xmldb.api.base.Database)

Example 19 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class MoveResourceRecoveryTest method xmldbRead.

private void xmldbRead() throws XMLDBException {
    final org.xmldb.api.base.Collection test = DatabaseManager.getCollection(XmldbURI.LOCAL_DB + "/test", TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
    final Resource res = test.getResource("new_test3.xml");
    assertNotNull("Document should not be null", res);
    final org.xmldb.api.base.Collection root = DatabaseManager.getCollection(XmldbURI.LOCAL_DB, TestUtils.ADMIN_DB_USER, TestUtils.ADMIN_DB_PWD);
    final EXistCollectionManagementService mgr = (EXistCollectionManagementService) root.getService("CollectionManagementService", "1.0");
    mgr.removeCollection(XmldbURI.create("test"));
    mgr.removeCollection(XmldbURI.create("test2"));
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Resource(org.xmldb.api.base.Resource) Database(org.xmldb.api.base.Database)

Example 20 with EXistCollectionManagementService

use of org.exist.xmldb.EXistCollectionManagementService in project exist by eXist-db.

the class CreateCollectionAction method execute.

@Override
public boolean execute() throws XMLDBException, IOException {
    final Collection col = DatabaseManager.getCollection(collectionPath, "admin", "");
    final Collection target = DBUtils.addCollection(col, "C" + ++collectionCnt);
    addFiles(target);
    String[] resources = target.listResources();
    final EXistCollectionManagementService mgt = (EXistCollectionManagementService) col.getService("CollectionManagementService", "1.0");
    final Collection copy = DBUtils.addCollection(col, "CC" + collectionCnt);
    for (int i = 0; i < resources.length; i++) {
        mgt.copyResource(target.getName() + '/' + resources[i], copy.getName(), null);
    }
    resources = copy.listResources();
    return true;
}
Also used : EXistCollectionManagementService(org.exist.xmldb.EXistCollectionManagementService) Collection(org.xmldb.api.base.Collection)

Aggregations

EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)42 Collection (org.xmldb.api.base.Collection)31 Resource (org.xmldb.api.base.Resource)25 BinaryResource (org.xmldb.api.modules.BinaryResource)19 Test (org.junit.Test)18 UserManagementService (org.exist.xmldb.UserManagementService)16 XMLResource (org.xmldb.api.modules.XMLResource)13 XmldbURI (org.exist.xmldb.XmldbURI)12 URISyntaxException (java.net.URISyntaxException)11 Database (org.xmldb.api.base.Database)7 EXistResource (org.exist.xmldb.EXistResource)6 ExtendedResource (org.exist.xmldb.ExtendedResource)6 XMLDBException (org.xmldb.api.base.XMLDBException)5 Path (java.nio.file.Path)3 IndexQueryService (org.exist.xmldb.IndexQueryService)3 XPathException (org.exist.xquery.XPathException)3 InputStream (java.io.InputStream)2 BuildException (org.apache.tools.ant.BuildException)2 AnyURIValue (org.exist.xquery.value.AnyURIValue)2 ResourceSet (org.xmldb.api.base.ResourceSet)2