1 package org.simantics.db.impl;
\r
3 import java.util.UUID;
\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
10 abstract public class ClusterBase implements ClusterI, TableSizeListener {
\r
12 protected static boolean DEBUG = false;
\r
13 protected static boolean VERBOSE = false;
\r
14 public static class IdImpl implements ClusteringSupport.Id {
\r
16 public IdImpl(UUID id) {
\r
20 public String toString() {
\r
21 long[] longs = toLong();
\r
22 return String.format("%x.%x", longs[0], longs[1]);
\r
25 public boolean equals(Object o) {
\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
37 return self[1] == other[1];
\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
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
54 protected ClusterBase() {
\r
55 this.clusterUID = null;
\r
57 this.clusterKey = 0;
\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
66 System.out.println("DEBUG: Created cluster " + clusterUID + " id=" + clusterId + " key=" + clusterKey);
\r
68 new Exception().printStackTrace();
\r
72 final public int getClusterKey() {
\r
76 final public long getClusterId() {
\r
81 final public long getImportance() {
\r
86 final public void setImportance(long importance) {
\r
87 this.importance = importance;
\r
91 public ClusterUID getClusterUID() {
\r
96 // public Id getModifiedId() {
\r
97 // return modifiedId;
\r
100 // public void setModifiedId(Id modifiedId) {
\r
101 // this.modifiedId = modifiedId;
\r
104 public abstract ClusterBase toBig(ClusterSupport support) throws DatabaseException;
\r
106 public abstract void checkDirectReference(int dr) throws DatabaseException;
\r
108 public abstract void checkForeingIndex(int fi) throws DatabaseException;
\r
110 public abstract void checkObjectSetReference(int or) throws DatabaseException;
\r
112 public abstract void checkValueInit() throws DatabaseException;
\r
114 public abstract void checkCompleteSetReference(int cr) throws DatabaseException;
\r
116 public abstract void checkPredicateIndex(int pi) throws DatabaseException;
\r
118 public abstract void checkValue(int capacity, int index) throws DatabaseException;
\r
120 public abstract void checkValueFini() throws DatabaseException;
\r
122 public abstract Table<?> getPredicateTable();
\r
124 public abstract Table<?> getForeignTable();
\r
126 public abstract Table<?> getCompleteTable();
\r
128 public abstract Table<?> getValueTable();
\r
130 public abstract Table<?> getObjectTable();
\r
132 public abstract int execute(int p1) throws DatabaseException;
\r
134 public abstract int makeResourceKey(int pRef) throws DatabaseException;
\r
136 public abstract IClusterTable getClusterTable();
\r