From 44dfa449789df7a85b7687f29a3b123ed9d01cce Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 4 Feb 2013 22:22:30 +0100 Subject: Added XMLDB.root property. Specifies the root collection in eXist that cristal should create for itself if it doesn't exist. --- .../c2kernel/persistency/XMLDBClusterStorage.java | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/main/java/com/c2kernel/persistency/XMLDBClusterStorage.java') 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 contents = new ArrayList(); -- cgit v1.2.3