--- /dev/null
+package org.simantics.db.impl;\r
+\r
+import java.util.UUID;\r
+\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.service.ClusterUID;\r
+import org.simantics.db.service.ClusteringSupport;\r
+import org.simantics.db.service.ClusteringSupport.Id;\r
+\r
+abstract public class ClusterBase implements ClusterI, TableSizeListener {\r
+ \r
+ protected static boolean DEBUG = false;\r
+ protected static boolean VERBOSE = false;\r
+ public static class IdImpl implements ClusteringSupport.Id {\r
+ private UUID id;\r
+ public IdImpl(UUID id) {\r
+ this.id = id;\r
+ }\r
+ @Override\r
+ public String toString() {\r
+ long[] longs = toLong();\r
+ return String.format("%x.%x", longs[0], longs[1]);\r
+ }\r
+ @Override\r
+ public boolean equals(Object o) {\r
+ if (null == o)\r
+ return false;\r
+ else if (this == o)\r
+ return true;\r
+ else if (o instanceof IdImpl)\r
+ return this.id.equals(((IdImpl)o).id);\r
+ else if (o instanceof Id) {\r
+ long[] self = toLong();\r
+ long[] other = ((Id)o).toLong();\r
+ if (self[0] != other[0])\r
+ return false;\r
+ return self[1] == other[1];\r
+ } else\r
+ return false;\r
+ }\r
+ public long[] toLong() {\r
+ long[] longs = new long[2];\r
+ longs[0] = id.getMostSignificantBits();\r
+ longs[1] = id.getLeastSignificantBits();\r
+ return longs;\r
+ }\r
+ }\r
+ public final ClusterUID clusterUID; // unique identifier for this cluster with all servers, persistent\r
+ public final long clusterId; // unique identifier for this cluster with this server, persistent\r
+ public final int clusterKey; // unique identifier for this cluster with this process, transient\r
+// private Id modifiedId;\r
+ protected long importance;\r
+\r
+ protected ClusterBase() {\r
+ this.clusterUID = null;\r
+ this.clusterId = 0;\r
+ this.clusterKey = 0;\r
+ }\r
+ \r
+ public ClusterBase(ClusterSupport support, ClusterUID clusterUID, int clusterKey) {\r
+ this.clusterUID = clusterUID;\r
+ this.clusterId = support.getClusterIdOrCreate(clusterUID);\r
+ this.clusterKey = 0 != clusterKey ? clusterKey : support.createClusterKeyByClusterUID(this.clusterUID, this.clusterId);\r
+// this.modifiedId = new IdImpl(UUID.randomUUID()); // kraa666\r
+ if (DEBUG) {\r
+ System.out.println("DEBUG: Created cluster " + clusterUID + " id=" + clusterId + " key=" + clusterKey);\r
+ if (VERBOSE)\r
+ new Exception().printStackTrace();\r
+ }\r
+ }\r
+\r
+ final public int getClusterKey() {\r
+ return clusterKey;\r
+ }\r
+\r
+ final public long getClusterId() {\r
+ return clusterId;\r
+ }\r
+\r
+ @Override\r
+ final public long getImportance() {\r
+ return importance;\r
+ }\r
+\r
+ @Override\r
+ final public void setImportance(long importance) {\r
+ this.importance = importance;\r
+ }\r
+\r
+ @Override\r
+ public ClusterUID getClusterUID() {\r
+ return clusterUID;\r
+ }\r
+\r
+// @Override\r
+// public Id getModifiedId() {\r
+// return modifiedId;\r
+// }\r
+//\r
+// public void setModifiedId(Id modifiedId) {\r
+// this.modifiedId = modifiedId;\r
+// }\r
+\r
+ public abstract ClusterBase toBig(ClusterSupport support) throws DatabaseException;\r
+ \r
+ public abstract void checkDirectReference(int dr) throws DatabaseException;\r
+\r
+ public abstract void checkForeingIndex(int fi) throws DatabaseException;\r
+\r
+ public abstract void checkObjectSetReference(int or) throws DatabaseException;\r
+\r
+ public abstract void checkValueInit() throws DatabaseException;\r
+\r
+ public abstract void checkCompleteSetReference(int cr) throws DatabaseException;\r
+\r
+ public abstract void checkPredicateIndex(int pi) throws DatabaseException;\r
+\r
+ public abstract void checkValue(int capacity, int index) throws DatabaseException;\r
+\r
+ public abstract void checkValueFini() throws DatabaseException;\r
+ \r
+ public abstract Table<?> getPredicateTable();\r
+\r
+ public abstract Table<?> getForeignTable();\r
+ \r
+ public abstract Table<?> getCompleteTable();\r
+\r
+ public abstract Table<?> getValueTable();\r
+\r
+ public abstract Table<?> getObjectTable();\r
+\r
+ public abstract int execute(int p1) throws DatabaseException;\r
+\r
+ public abstract int makeResourceKey(int pRef) throws DatabaseException;\r
+\r
+ public abstract IClusterTable getClusterTable();\r
+\r
+}\r