From da731d2bb81666b9c697d9099da632e7dfcdc0f7 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Tue, 9 Sep 2014 12:13:21 +0200 Subject: 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. --- .../c2kernel/persistency/XMLClusterStorage.java | 31 +++++++++++----------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/main/java/com/c2kernel/persistency/XMLClusterStorage.java') 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 paths = FileStringUtility.listDir( filePath, true, false ); if (paths == null) return result; // dir doesn't exist yet ArrayList contents = new ArrayList(); @@ -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; } -- cgit v1.2.3