From b086f57f56bf0eb9dab9cf321a0f69aaaae84347 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Wed, 30 May 2012 08:37:45 +0200 Subject: Initial Maven Conversion --- .../com/c2kernel/persistency/ClusterStorage.java | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/main/java/com/c2kernel/persistency/ClusterStorage.java (limited to 'src/main/java/com/c2kernel/persistency/ClusterStorage.java') diff --git a/src/main/java/com/c2kernel/persistency/ClusterStorage.java b/src/main/java/com/c2kernel/persistency/ClusterStorage.java new file mode 100644 index 0000000..80fd86d --- /dev/null +++ b/src/main/java/com/c2kernel/persistency/ClusterStorage.java @@ -0,0 +1,104 @@ + +package com.c2kernel.persistency; +import com.c2kernel.entity.C2KLocalObject; +import com.c2kernel.persistency.outcome.Outcome; +import com.c2kernel.persistency.outcome.Viewpoint; +import com.c2kernel.utils.Logger; + +/** Interface for persistency managers of entities. + A Cluster is defined as a path under the item + Each ClusterStorage must support get() and getClusterContents() for clusters they return READ and READWRITE from queryClusterSupport + and put() and delete() for clusters they return WRITE and READWRITE from queryClusterSupport(). + Unsupported operations should throw a ClusterStorageException. + If a cluster does not exist, get should return null, and delete should return + @version $Revision: 1.22 $ $Date: 2006/02/01 13:27:47 $ + @author $Author: abranson $ +*/ +public abstract class ClusterStorage { + + public static final short NONE = 0; + public static final short READ = 1; + public static final short WRITE = 2; + public static final short READWRITE = 3; + + // Cluster types + public static final String ROOT = ""; + public static final String PROPERTY = "Property"; + public static final String COLLECTION = "Collection"; + public static final String LIFECYCLE = "LifeCycle"; + public static final String OUTCOME = "Outcome"; + public static final String HISTORY = "AuditTrail"; + public static final String VIEWPOINT = "ViewPoint"; + public static final String JOB = "Job"; + + // connection maintenance + public abstract void open() + throws ClusterStorageException; + public abstract void close() + throws ClusterStorageException; + + // introspection + public abstract short queryClusterSupport(String clusterType); + public abstract String getName(); + // for addressing queries + public abstract String getId(); + + + /** Quickly gets the first string of the slashed path */ + public static String getClusterType(String path) { + try { + if (path == null || path.length() == 0) return ClusterStorage.ROOT; + int start = path.charAt(0) == '/' ? 1 : 0; + int end = path.indexOf('/', start + 1); + if (end == -1) end = path.length(); + return path.substring(start, end); + } catch (Exception ex) { + Logger.error(ex); + return ClusterStorage.ROOT; + } + } + + public static String getPath(C2KLocalObject obj) { + String root = obj.getClusterType(); + if (root == null) return null; // no storage allowed + if (obj instanceof Outcome) { + Outcome oc = (Outcome)obj; + return root+"/"+oc.getSchemaType()+"/"+oc.getSchemaVersion()+"/"+oc.getName(); + } + else if (obj instanceof Viewpoint) { + Viewpoint vp = (Viewpoint)obj; + return root+"/"+vp.getSchemaName()+"/"+vp.getName(); + } + else + return root+"/"+obj.getName(); + } + + /* object manipulation */ + + // retrieve object by path + public abstract C2KLocalObject get(Integer sysKey, String path) + throws ClusterStorageException; + // store object by path + public abstract void put(Integer sysKey, C2KLocalObject obj) + throws ClusterStorageException; + // delete cluster + public abstract void delete(Integer sysKey, String path) + throws ClusterStorageException; + + // db specific queries + public Object query(Object query) + throws ClusterStorageException { + throw new ClusterStorageException("Query not supported on this storage"); + } + + public String queryToXML(String query, boolean genericFormat) + throws ClusterStorageException { + throw new ClusterStorageException("Query not supported on this storage"); + } + + + // directory listing + public abstract String[] getClusterContents(Integer sysKey, String path) + throws ClusterStorageException; + +} -- cgit v1.2.3