summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/persistency/ClusterStorage.java
blob: f0d28a4af6a7864e47c3749c795d53ce42919595 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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;

}