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