1 package org.simantics.db.impl;
5 import org.simantics.db.exception.DatabaseException;
6 import org.simantics.db.service.ClusterUID;
7 import org.simantics.db.service.ClusteringSupport;
8 import org.simantics.db.service.ClusteringSupport.Id;
10 abstract public class ClusterBase implements ClusterI, TableSizeListener {
12 protected static boolean DEBUG = false;
13 protected static boolean VERBOSE = false;
14 public static class IdImpl implements ClusteringSupport.Id {
16 public IdImpl(UUID id) {
20 public String toString() {
21 long[] longs = toLong();
22 return String.format("%x.%x", longs[0], longs[1]);
25 public boolean equals(Object o) {
30 else if (o instanceof IdImpl)
31 return this.id.equals(((IdImpl)o).id);
32 else if (o instanceof Id) {
33 long[] self = toLong();
34 long[] other = ((Id)o).toLong();
35 if (self[0] != other[0])
37 return self[1] == other[1];
41 public long[] toLong() {
42 long[] longs = new long[2];
43 longs[0] = id.getMostSignificantBits();
44 longs[1] = id.getLeastSignificantBits();
48 public final ClusterUID clusterUID; // unique identifier for this cluster with all servers, persistent
49 public final long clusterId; // unique identifier for this cluster with this server, persistent
50 public final int clusterKey; // unique identifier for this cluster with this process, transient
51 // private Id modifiedId;
52 protected long importance;
54 protected ClusterBase() {
55 this.clusterUID = null;
60 public ClusterBase(ClusterSupport support, ClusterUID clusterUID, int clusterKey) {
61 this.clusterUID = clusterUID;
62 this.clusterId = support.getClusterIdOrCreate(clusterUID);
63 this.clusterKey = 0 != clusterKey ? clusterKey : support.createClusterKeyByClusterUID(this.clusterUID, this.clusterId);
64 // this.modifiedId = new IdImpl(UUID.randomUUID()); // kraa666
66 System.out.println("DEBUG: Created cluster " + clusterUID + " id=" + clusterId + " key=" + clusterKey);
68 new Exception().printStackTrace();
72 final public int getClusterKey() {
76 final public long getClusterId() {
81 final public long getImportance() {
86 final public void setImportance(long importance) {
87 this.importance = importance;
91 public ClusterUID getClusterUID() {
96 // public Id getModifiedId() {
100 // public void setModifiedId(Id modifiedId) {
101 // this.modifiedId = modifiedId;
104 public abstract ClusterBase toBig(ClusterSupport support) throws DatabaseException;
106 public abstract void checkDirectReference(int dr) throws DatabaseException;
108 public abstract void checkForeingIndex(int fi) throws DatabaseException;
110 public abstract void checkObjectSetReference(int or) throws DatabaseException;
112 public abstract void checkValueInit() throws DatabaseException;
114 public abstract void checkCompleteSetReference(int cr) throws DatabaseException;
116 public abstract void checkPredicateIndex(int pi) throws DatabaseException;
118 public abstract void checkValue(int capacity, int index) throws DatabaseException;
120 public abstract void checkValueFini() throws DatabaseException;
122 public abstract Table<?> getPredicateTable();
124 public abstract Table<?> getForeignTable();
126 public abstract Table<?> getCompleteTable();
128 public abstract Table<?> getValueTable();
130 public abstract Table<?> getObjectTable();
132 public abstract int execute(int p1) throws DatabaseException;
134 public abstract int makeResourceKey(int pRef) throws DatabaseException;
136 public abstract IClusterTable getClusterTable();