Search in sources :

Example 1 with Database

use of org.xmldb.api.base.Database in project exist by eXist-db.

the class AbstractXMLDBTask method registerDatabase.

protected void registerDatabase() throws BuildException {
    try {
        log("Registering database", Project.MSG_DEBUG);
        final Database[] allDataBases = DatabaseManager.getDatabases();
        for (final Database database : allDataBases) {
            if (database.acceptsURI(uri)) {
                return;
            }
        }
        final Class<?> clazz = Class.forName(driver);
        final Database database = (Database) clazz.newInstance();
        database.setProperty("create-database", createDatabase ? "true" : "false");
        database.setProperty("ssl-enable", ssl ? "true" : "false");
        if (configuration != null) {
            database.setProperty("configuration", configuration);
        }
        DatabaseManager.registerDatabase(database);
        log("Database driver registered.");
    } catch (final Exception e) {
        throw new BuildException("failed to initialize XMLDB database driver", e);
    }
}
Also used : Database(org.xmldb.api.base.Database) BuildException(org.apache.tools.ant.BuildException) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException) StartException(org.exist.start.StartException) SyntaxException(org.exist.util.SyntaxException)

Example 2 with Database

use of org.xmldb.api.base.Database in project exist by eXist-db.

the class ServerShutdown method process.

private static void process(final ParsedArguments arguments) {
    final Properties properties = loadProperties();
    final String user = arguments.get(userArg);
    final String passwd = arguments.get(passwordArg);
    String uri = getOpt(arguments, uriArg).orElseGet(() -> properties.getProperty("uri", "xmldb:exist://localhost:8080/exist/xmlrpc"));
    try {
        // initialize database drivers
        final Class<?> cl = Class.forName("org.exist.xmldb.DatabaseImpl");
        // create the default database
        final Database database = (Database) cl.newInstance();
        DatabaseManager.registerDatabase(database);
        if (!uri.endsWith(XmldbURI.ROOT_COLLECTION)) {
            uri = uri + XmldbURI.ROOT_COLLECTION;
        }
        final Collection root = DatabaseManager.getCollection(uri, user, passwd);
        final DatabaseInstanceManager manager = (DatabaseInstanceManager) root.getService("DatabaseInstanceManager", "1.0");
        System.out.println("Shutting down database instance at ");
        System.out.println('\t' + uri);
        manager.shutdown();
    } catch (final XMLDBException e) {
        System.err.println("ERROR: " + e.getMessage());
        final Throwable t = e.getCause();
        if (t != null && t instanceof XmlRpcException) {
            System.err.println("CAUSE: " + t.getMessage());
        } else {
            e.printStackTrace();
        }
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : Database(org.xmldb.api.base.Database) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) Properties(java.util.Properties) DatabaseInstanceManager(org.exist.xmldb.DatabaseInstanceManager) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XMLDBException(org.xmldb.api.base.XMLDBException) ArgumentException(se.softhouse.jargo.ArgumentException) IOException(java.io.IOException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) StartException(org.exist.start.StartException)

Example 3 with Database

use of org.xmldb.api.base.Database in project exist by eXist-db.

the class AbstractExistHttpServlet method doDatabaseStartup.

private void doDatabaseStartup(Configuration configuration) throws ServletException {
    if (configuration == null) {
        throw new ServletException("Database has not been " + "configured");
    }
    getLog().info("Configuring eXist instance");
    try {
        if (!BrokerPool.isConfigured()) {
            BrokerPool.configure(1, 5, configuration);
        }
    } catch (final EXistException | DatabaseConfigurationException e) {
        throw new ServletException(e.getMessage(), e);
    }
    try {
        getLog().info("Registering XMLDB driver");
        final Class<?> clazz = Class.forName("org.exist.xmldb.DatabaseImpl");
        final Database database = (Database) clazz.newInstance();
        DatabaseManager.registerDatabase(database);
    } catch (final ClassNotFoundException | XMLDBException | IllegalAccessException | InstantiationException e) {
        getLog().info("ERROR", e);
    }
}
Also used : ServletException(javax.servlet.ServletException) DatabaseConfigurationException(org.exist.util.DatabaseConfigurationException) Database(org.xmldb.api.base.Database) XMLDBException(org.xmldb.api.base.XMLDBException) EXistException(org.exist.EXistException)

Example 4 with Database

use of org.xmldb.api.base.Database in project exist by eXist-db.

the class IndexingTest method irregularilyStructured.

private void irregularilyStructured(boolean getContentAsDOM) throws XMLDBException, ParserConfigurationException, SAXException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    Database database = null;
    final String testName = "IrregularilyStructured";
    startTime = System.currentTimeMillis();
    Collection coll = DatabaseManager.getCollection(baseURI, username, password);
    XMLResource resource = (XMLResource) coll.createResource(name, XMLResource.RESOURCE_TYPE);
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    effectiveSiblingCount = populate(doc);
    resource.setContentAsDOM(doc);
    coll.storeResource(resource);
    coll.close();
    coll = DatabaseManager.getCollection(baseURI, username, password);
    resource = (XMLResource) coll.getResource(name);
    Node n;
    if (getContentAsDOM) {
        n = resource.getContentAsDOM();
    } else {
        String s = (String) resource.getContent();
        byte[] bytes = s.getBytes(UTF_8);
        UnsynchronizedByteArrayInputStream bais = new UnsynchronizedByteArrayInputStream(bytes);
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        n = db.parse(bais);
    }
    Element documentElement = null;
    if (n instanceof Element) {
        documentElement = (Element) n;
    } else if (n instanceof Document) {
        documentElement = ((Document) n).getDocumentElement();
    }
    assertions(documentElement);
    coll.removeResource(resource);
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Database(org.xmldb.api.base.Database) Collection(org.xmldb.api.base.Collection) UnsynchronizedByteArrayInputStream(org.apache.commons.io.input.UnsynchronizedByteArrayInputStream) Document(org.w3c.dom.Document) XMLResource(org.xmldb.api.modules.XMLResource)

Example 5 with Database

use of org.xmldb.api.base.Database in project exist by eXist-db.

the class RemoteDBTest method setUpRemoteDatabase.

protected void setUpRemoteDatabase() throws ClassNotFoundException, IllegalAccessException, InstantiationException, XMLDBException {
    // Connect to the DB
    Class<?> cl = Class.forName(DB_DRIVER);
    Database database = (Database) cl.newInstance();
    assertNotNull(database);
    DatabaseManager.registerDatabase(database);
    // Get the root collection...
    Collection rootCollection = DatabaseManager.getCollection(getUri() + XmldbURI.ROOT_COLLECTION, "admin", "");
    assertNotNull(rootCollection);
    CollectionManagementService cms = (CollectionManagementService) rootCollection.getService("CollectionManagementService", "1.0");
    // Creates the child collection
    Collection childCollection = cms.createCollection(CHILD_COLLECTION);
    assertNotNull(childCollection);
    // ... and work from it
    setCollection((RemoteCollection) childCollection);
    assertNotNull(childCollection);
}
Also used : CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) Database(org.xmldb.api.base.Database) Collection(org.xmldb.api.base.Collection)

Aggregations

Database (org.xmldb.api.base.Database)20 Collection (org.xmldb.api.base.Collection)8 XMLDBException (org.xmldb.api.base.XMLDBException)6 DatabaseImpl (org.exist.xmldb.DatabaseImpl)5 IOException (java.io.IOException)4 StartException (org.exist.start.StartException)4 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)4 XMLResource (org.xmldb.api.modules.XMLResource)4 InputStream (java.io.InputStream)3 Path (java.nio.file.Path)3 EXistException (org.exist.EXistException)3 Test (org.junit.Test)3 Properties (java.util.Properties)2 ServletException (javax.servlet.ServletException)2 AuthenticationException (org.exist.security.AuthenticationException)2 Subject (org.exist.security.Subject)2 BrokerPool (org.exist.storage.BrokerPool)2 DatabaseConfigurationException (org.exist.util.DatabaseConfigurationException)2 Resource (org.xmldb.api.base.Resource)2 File (java.io.File)1