]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterBase.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / ClusterBase.java
1 package org.simantics.db.impl;\r
2 \r
3 import java.util.UUID;\r
4 \r
5 import org.simantics.db.exception.DatabaseException;\r
6 import org.simantics.db.service.ClusterUID;\r
7 import org.simantics.db.service.ClusteringSupport;\r
8 import org.simantics.db.service.ClusteringSupport.Id;\r
9 \r
10 abstract public class ClusterBase implements ClusterI, TableSizeListener {\r
11     \r
12     protected static boolean DEBUG = false;\r
13     protected static boolean VERBOSE = false;\r
14     public static class IdImpl implements ClusteringSupport.Id {\r
15         private UUID id;\r
16         public IdImpl(UUID id) {\r
17             this.id = id;\r
18         }\r
19         @Override\r
20         public String toString() {\r
21             long[] longs = toLong();\r
22             return String.format("%x.%x", longs[0], longs[1]);\r
23         }\r
24         @Override\r
25         public boolean equals(Object o) {\r
26             if (null == o)\r
27                 return false;\r
28             else if (this == o)\r
29                 return true;\r
30             else if (o instanceof IdImpl)\r
31                 return this.id.equals(((IdImpl)o).id);\r
32             else if (o instanceof Id) {\r
33                 long[] self = toLong();\r
34                 long[] other = ((Id)o).toLong();\r
35                 if (self[0] != other[0])\r
36                     return false;\r
37                 return self[1] == other[1];\r
38             } else\r
39                 return false;\r
40         }\r
41         public long[] toLong() {\r
42             long[] longs = new long[2];\r
43             longs[0] = id.getMostSignificantBits();\r
44             longs[1] = id.getLeastSignificantBits();\r
45             return longs;\r
46         }\r
47     }\r
48     public final ClusterUID clusterUID; // unique identifier for this cluster with all servers, persistent\r
49     public final long clusterId; // unique identifier for this cluster with this server, persistent\r
50     public final int clusterKey; // unique identifier for this cluster with this process, transient\r
51 //    private Id modifiedId;\r
52     protected long importance;\r
53 \r
54     protected ClusterBase() {\r
55         this.clusterUID = null;\r
56         this.clusterId = 0;\r
57         this.clusterKey = 0;\r
58     }\r
59     \r
60     public ClusterBase(ClusterSupport support, ClusterUID clusterUID, int clusterKey) {\r
61         this.clusterUID = clusterUID;\r
62         this.clusterId = support.getClusterIdOrCreate(clusterUID);\r
63         this.clusterKey = 0 != clusterKey ? clusterKey : support.createClusterKeyByClusterUID(this.clusterUID, this.clusterId);\r
64 //        this.modifiedId = new IdImpl(UUID.randomUUID()); // kraa666\r
65         if (DEBUG) {\r
66             System.out.println("DEBUG: Created cluster " + clusterUID + " id=" + clusterId + " key=" + clusterKey);\r
67             if (VERBOSE)\r
68                 new Exception().printStackTrace();\r
69         }\r
70     }\r
71 \r
72     final public int getClusterKey() {\r
73         return clusterKey;\r
74     }\r
75 \r
76     final public long getClusterId() {\r
77         return clusterId;\r
78     }\r
79 \r
80     @Override\r
81     final public long getImportance() {\r
82         return importance;\r
83     }\r
84 \r
85     @Override\r
86     final public void setImportance(long importance) {\r
87         this.importance = importance;\r
88     }\r
89 \r
90     @Override\r
91     public ClusterUID getClusterUID() {\r
92         return clusterUID;\r
93     }\r
94 \r
95 //    @Override\r
96 //    public Id getModifiedId() {\r
97 //        return modifiedId;\r
98 //    }\r
99 //\r
100 //    public void setModifiedId(Id modifiedId) {\r
101 //        this.modifiedId = modifiedId;\r
102 //    }\r
103 \r
104     public abstract ClusterBase toBig(ClusterSupport support) throws DatabaseException;\r
105     \r
106     public abstract void checkDirectReference(int dr) throws DatabaseException;\r
107 \r
108     public abstract void checkForeingIndex(int fi) throws DatabaseException;\r
109 \r
110     public abstract void checkObjectSetReference(int or) throws DatabaseException;\r
111 \r
112     public abstract void checkValueInit() throws DatabaseException;\r
113 \r
114     public abstract void checkCompleteSetReference(int cr) throws DatabaseException;\r
115 \r
116     public abstract void checkPredicateIndex(int pi) throws DatabaseException;\r
117 \r
118     public abstract void checkValue(int capacity, int index) throws DatabaseException;\r
119 \r
120     public abstract void checkValueFini() throws DatabaseException;\r
121     \r
122     public abstract Table<?> getPredicateTable();\r
123 \r
124     public abstract Table<?> getForeignTable();\r
125     \r
126     public abstract Table<?> getCompleteTable();\r
127 \r
128     public abstract Table<?> getValueTable();\r
129 \r
130     public abstract Table<?> getObjectTable();\r
131 \r
132     public abstract int execute(int p1) throws DatabaseException;\r
133 \r
134     public abstract int makeResourceKey(int pRef) throws DatabaseException;\r
135 \r
136     public abstract IClusterTable getClusterTable();\r
137 \r
138 }\r