summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-09-09 12:13:21 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-09-09 12:13:21 +0200
commitda731d2bb81666b9c697d9099da632e7dfcdc0f7 (patch)
tree567693c3c48f3d15ecbb2dac4f9db03bb6e58c72 /src/main/java/com/c2kernel/persistency/XMLClusterStorage.java
parentae1e79e33fd30e3d8bcedbef8891a14a048276d7 (diff)
Replaced int sysKey Item identifier with UUID, which is now portable.
ItemPath objects are now used to identify Items throughout the kernel, replacing ints and Integers.
Diffstat (limited to 'src/main/java/com/c2kernel/persistency/XMLClusterStorage.java')
-rw-r--r--src/main/java/com/c2kernel/persistency/XMLClusterStorage.java31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java b/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java
index e6c6e9f..8f01d8e 100644
--- a/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java
+++ b/src/main/java/com/c2kernel/persistency/XMLClusterStorage.java
@@ -57,10 +57,10 @@ public class XMLClusterStorage extends ClusterStorage {
// retrieve object by path
@Override
- public C2KLocalObject get(Integer sysKey, String path) throws ClusterStorageException {
+ public C2KLocalObject get(ItemPath itemPath, String path) throws ClusterStorageException {
try {
String type = ClusterStorage.getClusterType(path);
- String filePath = getFilePath(sysKey, path)+".xml";
+ String filePath = getFilePath(itemPath, path)+".xml";
String objString = FileStringUtility.file2String(filePath);
if (objString.length() == 0) return null;
Logger.debug(9, objString);
@@ -72,16 +72,16 @@ public class XMLClusterStorage extends ClusterStorage {
}
} catch (Exception e) {
- Logger.msg(3,"XMLClusterStorage.get() - The path "+path+" from "+sysKey+" does not exist.: "+e.getMessage());
+ Logger.msg(3,"XMLClusterStorage.get() - The path "+path+" from "+itemPath+" does not exist.: "+e.getMessage());
}
return null;
}
// store object by path
@Override
- public void put(Integer sysKey, C2KLocalObject obj) throws ClusterStorageException {
+ public void put(ItemPath itemPath, C2KLocalObject obj) throws ClusterStorageException {
try {
- String filePath = getFilePath(sysKey, getPath(obj)+".xml");
+ String filePath = getFilePath(itemPath, getPath(obj)+".xml");
Logger.msg(7, "Writing "+filePath);
String data = Gateway.getMarshaller().marshall(obj);
@@ -93,32 +93,32 @@ public class XMLClusterStorage extends ClusterStorage {
FileStringUtility.string2File(filePath, data);
} catch (Exception e) {
Logger.error(e);
- throw new ClusterStorageException("XMLClusterStorage.put() - Could not write "+getPath(obj)+" to "+sysKey);
+ throw new ClusterStorageException("XMLClusterStorage.put() - Could not write "+getPath(obj)+" to "+itemPath);
}
}
// delete cluster
@Override
- public void delete(Integer sysKey, String path) throws ClusterStorageException {
+ public void delete(ItemPath itemPath, String path) throws ClusterStorageException {
try {
- String filePath = getFilePath(sysKey, path+".xml");
+ String filePath = getFilePath(itemPath, path+".xml");
boolean success = FileStringUtility.deleteDir(filePath, true, true);
if (success) return;
- filePath = getFilePath(sysKey, path);
+ filePath = getFilePath(itemPath, path);
success = FileStringUtility.deleteDir(filePath, true, true);
if (success) return;
} catch(Exception e) { }
- throw new ClusterStorageException("XMLClusterStorage.delete() - Failure deleting path "+path+" in "+sysKey);
+ throw new ClusterStorageException("XMLClusterStorage.delete() - Failure deleting path "+path+" in "+itemPath);
}
/* navigation */
// directory listing
@Override
- public String[] getClusterContents(Integer sysKey, String path) throws ClusterStorageException {
+ public String[] getClusterContents(ItemPath itemPath, String path) throws ClusterStorageException {
String[] result = new String[0];
try {
- String filePath = getFilePath(sysKey, path);
+ String filePath = getFilePath(itemPath, path);
ArrayList<String> paths = FileStringUtility.listDir( filePath, true, false );
if (paths == null) return result; // dir doesn't exist yet
ArrayList<String> contents = new ArrayList<String>();
@@ -142,14 +142,13 @@ public class XMLClusterStorage extends ClusterStorage {
return result;
} catch (Exception e) {
Logger.error(e);
- throw new ClusterStorageException("XMLClusterStorage.getClusterContents() - Could not get contents of "+path+" from "+sysKey+": "+e.getMessage());
+ throw new ClusterStorageException("XMLClusterStorage.getClusterContents() - Could not get contents of "+path+" from "+itemPath+": "+e.getMessage());
}
}
- protected String getFilePath(Integer sysKey, String path) throws InvalidItemPathException {
- ItemPath thisEntity = new ItemPath(sysKey.intValue());
+ protected String getFilePath(ItemPath itemPath, String path) throws InvalidItemPathException {
if (path.length() == 0 || path.charAt(0) != '/') path = "/"+path;
- String filePath = rootDir+thisEntity.toString()+path;
+ String filePath = rootDir+itemPath.toString()+path;
Logger.msg(8, "XMLClusterStorage.getFilePath() - "+filePath);
return filePath;
}