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);
}
}
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();
}
}
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);
}
}
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);
}
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);
}
Aggregations