]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / ClusterI.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.impl;
13
14 import java.io.InputStream;
15 import java.util.function.Consumer;
16
17 import org.simantics.db.Resource;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.impl.graph.ReadGraphImpl;
20 import org.simantics.db.procedure.SyncMultiProcedure;
21 import org.simantics.db.service.ClusterUID;
22
23 public interface ClusterI {
24     public enum TypeEnum {
25         Small, Big
26     }
27     public interface Procedure {
28         
29     }
30     public interface PredicateProcedure<Context> extends Procedure {
31         /**
32          * @param context is whatever you want.
33          * @param resourceKey is either subject, predicate or object resource key.
34          * @return true if you want to break loop.
35          */
36         boolean execute(Context context, int resourceKey, int objectIndex);
37     }
38     public interface ObjectProcedure<Context> extends Procedure {
39         /**
40          * @param context is whatever you want.
41          * @param resourceKey is either subject, predicate or object resource key.
42          * @return true if you want to break loop.
43          */
44         boolean execute(Context context, int resourceKey) throws DatabaseException;
45         //boolean found();
46
47     }
48
49     /**
50      * Resource is complete if it has exactly one IIS statement. If resource has
51      * multiple IIS statements it's complete reference is index to complete
52      * table (and not zero).
53      */
54     enum CompleteTypeEnum {
55         NotComplete(0),
56         InstanceOf(1),
57         Inherits(2),
58         SubrelationOf(3);
59         public static final CompleteTypeEnum make(int value) {
60             switch (value) {
61             default:
62                 throw new Error("Internal error. Illegal complete type=" + value + ".");
63             case 0:
64                 assert(0 == ClusterI.CompleteTypeEnum.NotComplete.getValue());
65                 return ClusterI.CompleteTypeEnum.NotComplete;
66             case 1:
67                 assert(1 == ClusterI.CompleteTypeEnum.InstanceOf.getValue());
68                 return ClusterI.CompleteTypeEnum.InstanceOf;
69             case 2:
70                 assert(2 == ClusterI.CompleteTypeEnum.Inherits.getValue());
71                 return ClusterI.CompleteTypeEnum.Inherits;
72             case 3:
73                 assert(3 == ClusterI.CompleteTypeEnum.SubrelationOf.getValue());
74                 return ClusterI.CompleteTypeEnum.SubrelationOf;
75             }
76         }
77         public final byte getValue() {
78             return value;
79         }
80         private CompleteTypeEnum(int value) {
81             this.value = (byte)value;
82         }
83         private byte value;
84     }
85
86     enum ClusterTypeEnum {
87         SMALL, BIG, WRITEONLY
88     }
89
90     public CompleteTypeEnum getCompleteType(int resourceKey, ClusterSupport support)
91     throws DatabaseException;
92
93     public int getCompleteObjectKey(int resourceKey, ClusterSupport support)
94     throws DatabaseException;
95
96     public boolean isComplete(int resourceKey, ClusterSupport support)
97     throws DatabaseException;
98
99     public <Context> boolean forPredicates(int resourceKey, PredicateProcedure<Context> procedure, Context context, ClusterSupport support)
100     throws DatabaseException;
101
102     public <Context> boolean forObjects(int resourceKey, int predicateKey, int objectIndex, ObjectProcedure<Context> procedure, Context context, ClusterSupport support)
103     throws DatabaseException;
104
105     public <Context> boolean forObjects(int resourceKey, int predicateKey, ObjectProcedure<Context> procedure, Context context, ClusterSupport support)
106     throws DatabaseException;
107
108     public int getSingleObject(int resourceKey, int predicateKey, ClusterSupport support)
109     throws DatabaseException;
110
111     public <T> int getSingleObject(int resourceKey, ForPossibleRelatedValueProcedure<T> procedure, ClusterSupport support)
112     throws DatabaseException;
113
114     public <C, T> int getSingleObject(int resourceKey, ForPossibleRelatedValueContextProcedure<C, T> procedure, ClusterSupport support)
115     throws DatabaseException;
116
117     public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, SyncMultiProcedure<Resource> procedure)
118     throws DatabaseException;
119
120     public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure)
121     throws DatabaseException;
122
123     public <C> void forObjects(ReadGraphImpl graph, int resourceKey, C context, ForEachObjectContextProcedure<C> procedure)
124     throws DatabaseException;
125
126     /**
127      * @param callerThread
128      * @param resourceKey
129      * @param predicateKey
130      * @param objectKey
131      * @param support
132      * @return null if relation already existed. Otherwise an old or new instance of ClusterI.
133      * @throws DatabaseException
134      */
135     public ClusterI addRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)
136     throws DatabaseException;
137
138     public boolean removeRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)
139     throws DatabaseException;
140
141     public void denyRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)
142     throws DatabaseException;
143
144     /**
145      * @param callerThread
146      * @param resourceKey
147      * @param support
148      * @return null if no value
149      * @throws DatabaseException
150      */
151     public byte[] getValue(int resourceKey, ClusterSupport support)
152     throws DatabaseException;
153
154     public InputStream getValueStream(int resourceKey, ClusterSupport support)
155     throws DatabaseException;
156
157     public boolean hasValue(int resourceKey, ClusterSupport support)
158     throws DatabaseException;
159
160     public boolean removeValue(int resourceKey, ClusterSupport support)
161     throws DatabaseException;
162
163     /**
164      * @param callerThread
165      * @param resourceKey
166      * @param value
167      * @param support
168      * @return An old or new instance of ClusterI.
169      * @throws DatabaseException
170      */
171     public ClusterI setValue(int resourceKey, byte[] value, int length, ClusterSupport support)
172     throws DatabaseException;
173
174     public ClusterI modiValueEx(int resourceKey, long voffset, int length, byte[] value, int offset, ClusterSupport support)
175     throws DatabaseException;
176
177     public byte[] readValueEx(int resourceKey, long voffset, int length, ClusterSupport support)
178     throws DatabaseException;
179
180     public long getValueSizeEx(int resourceKey, ClusterSupport support)
181     throws DatabaseException;
182
183     public void setValueEx(int resourceKey)
184     throws DatabaseException;
185
186     public int createResource(ClusterSupport support)
187     throws DatabaseException;
188
189     public boolean hasResource(int resourceKey, ClusterSupport support)
190     throws DatabaseException;
191
192     public int getNumberOfResources(ClusterSupport support) throws DatabaseException;
193
194     public long getCachedSize();
195
196     public long getUsedSpace()
197     throws DatabaseException;
198
199     public boolean isEmpty();
200
201     public void printDebugInfo(String message, ClusterSupport support)
202     throws DatabaseException;
203
204     public long getClusterId();
205
206     public int getClusterKey();
207
208     public boolean isWriteOnly();
209
210     public void load()
211     throws DatabaseException;
212
213     public void load(Consumer<DatabaseException> callback);
214     public void load(ClusterSupport session, Runnable callback);
215
216
217     public boolean hasVirtual();
218     public void markVirtual();
219
220     public ClusterI getClusterByResourceKey(int resourceKey, ClusterSupport support);
221     public boolean isLoaded();
222     public void increaseReferenceCount(int amount);
223     public void decreaseReferenceCount(int amount);
224     public int getReferenceCount();
225     public long getImportance();
226     public void setImportance(long i);
227     public void releaseMemory();
228     public void compact();
229
230     public boolean contains(int resource);
231
232     public ClusterTypeEnum getType();
233     public boolean getImmutable();
234     public void setImmutable(boolean immutable, ClusterSupport support);
235     public boolean getDeleted();
236     public void setDeleted(boolean deleted, ClusterSupport support);
237
238     public ClusterUID getClusterUID();
239 //    public Id getModifiedId();
240
241 }