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