summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2013-02-04 22:22:30 +0100
committerAndrew Branson <andrew.branson@cern.ch>2013-02-04 22:22:30 +0100
commit44dfa449789df7a85b7687f29a3b123ed9d01cce (patch)
treee0d044fcd41799ab2bf0de9a5d78cd71b91e5a96
parentbd561aef7d69bf44f206db2e4fcddbb8e59f99d6 (diff)
Added XMLDB.root property. Specifies the root collection in eXist that
cristal should create for itself if it doesn't exist.
-rw-r--r--src/main/java/com/c2kernel/persistency/XMLDBClusterStorage.java26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/main/java/com/c2kernel/persistency/XMLDBClusterStorage.java b/src/main/java/com/c2kernel/persistency/XMLDBClusterStorage.java
index 8521a17..7531106 100644
--- a/src/main/java/com/c2kernel/persistency/XMLDBClusterStorage.java
+++ b/src/main/java/com/c2kernel/persistency/XMLDBClusterStorage.java
@@ -38,7 +38,7 @@ import com.c2kernel.utils.Logger;
public class XMLDBClusterStorage extends ClusterStorage {
Database database;
- Collection db;
+ Collection root;
public XMLDBClusterStorage() throws Exception {
@@ -86,13 +86,21 @@ public class XMLDBClusterStorage extends ClusterStorage {
database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);
- db = DatabaseManager.getCollection(Gateway.getProperty("XMLDB.URI"), Gateway.getProperty("XMLDB.user"), Gateway.getProperty("XMLDB.password"));
+ Collection db = DatabaseManager.getCollection(Gateway.getProperty("XMLDB.URI"), Gateway.getProperty("XMLDB.user"), Gateway.getProperty("XMLDB.password"));
+ String rootColl = Gateway.getProperty("XMLDB.root");
+ if (rootColl != null && rootColl.length()>0) {
+ root = verifyCollection(db, rootColl, true);
+ db.close();
+ }
+ else
+ root = db;
+
} catch (Exception ex) {
Logger.error(ex);
throw new ClusterStorageException("Error initializing XMLDB");
}
- if (db == null)
+ if (root == null)
throw new ClusterStorageException("Root collection is null. Problem connecting to XMLDB.");
}
@@ -102,7 +110,7 @@ public class XMLDBClusterStorage extends ClusterStorage {
@Override
public void close() throws ClusterStorageException {
try {
- db.close();
+ root.close();
//DatabaseInstanceManager manager = (DatabaseInstanceManager)db.getService("DatabaseInstanceManager", "1.0");
//manager.shutdown();
} catch (XMLDBException e) {
@@ -126,7 +134,6 @@ public class XMLDBClusterStorage extends ClusterStorage {
*/
@Override
public String getName() {
- // TODO Auto-generated method stub
return "XMLDB";
}
@@ -135,7 +142,6 @@ public class XMLDBClusterStorage extends ClusterStorage {
*/
@Override
public String getId() {
- // TODO Auto-generated method stub
return "XMLDB";
}
@@ -148,7 +154,7 @@ public class XMLDBClusterStorage extends ClusterStorage {
String type = ClusterStorage.getClusterType(path);
// Get item collection
String strSysKey = String.valueOf(sysKey);
- Collection itemColl = verifyCollection(db, strSysKey, false);
+ Collection itemColl = verifyCollection(root, strSysKey, false);
if (itemColl == null) return null; // doesn't exist
try {
@@ -181,7 +187,7 @@ public class XMLDBClusterStorage extends ClusterStorage {
String resName = getPath(obj);
String strSysKey = String.valueOf(sysKey);
- Collection itemColl = verifyCollection(db, strSysKey, true);
+ Collection itemColl = verifyCollection(root, strSysKey, true);
try {
resName = resName.replace('/', '.');
@@ -205,7 +211,7 @@ public class XMLDBClusterStorage extends ClusterStorage {
public void delete(Integer sysKey, String path)
throws ClusterStorageException {
String strSysKey = String.valueOf(sysKey);
- Collection itemColl = verifyCollection(db, strSysKey, false);
+ Collection itemColl = verifyCollection(root, strSysKey, false);
if (itemColl == null) return;
@@ -227,7 +233,7 @@ public class XMLDBClusterStorage extends ClusterStorage {
public String[] getClusterContents(Integer sysKey, String path)
throws ClusterStorageException {
String strSysKey = String.valueOf(sysKey);
- Collection coll = verifyCollection(db, strSysKey, false);
+ Collection coll = verifyCollection(root, strSysKey, false);
if (coll == null) return new String[0];
ArrayList<String> contents = new ArrayList<String>();