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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.impl;
\r
14 import java.io.InputStream;
\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
23 public interface ClusterI {
\r
24 public enum TypeEnum {
\r
27 public interface Procedure {
\r
30 public interface PredicateProcedure<Context> extends Procedure {
\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
36 boolean execute(Context context, int resourceKey, int objectIndex);
\r
38 public interface ObjectProcedure<Context> extends Procedure {
\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
44 boolean execute(Context context, int resourceKey) throws DatabaseException;
\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
54 enum CompleteTypeEnum {
\r
59 public static final CompleteTypeEnum make(int value) {
\r
62 throw new Error("Internal error. Illegal complete type=" + value + ".");
\r
64 assert(0 == ClusterI.CompleteTypeEnum.NotComplete.getValue());
\r
65 return ClusterI.CompleteTypeEnum.NotComplete;
\r
67 assert(1 == ClusterI.CompleteTypeEnum.InstanceOf.getValue());
\r
68 return ClusterI.CompleteTypeEnum.InstanceOf;
\r
70 assert(2 == ClusterI.CompleteTypeEnum.Inherits.getValue());
\r
71 return ClusterI.CompleteTypeEnum.Inherits;
\r
73 assert(3 == ClusterI.CompleteTypeEnum.SubrelationOf.getValue());
\r
74 return ClusterI.CompleteTypeEnum.SubrelationOf;
\r
77 public final byte getValue() {
\r
80 private CompleteTypeEnum(int value) {
\r
81 this.value = (byte)value;
\r
86 enum ClusterTypeEnum {
\r
87 SMALL, BIG, WRITEONLY
\r
90 public CompleteTypeEnum getCompleteType(int resourceKey, ClusterSupport support)
\r
91 throws DatabaseException;
\r
93 public int getCompleteObjectKey(int resourceKey, ClusterSupport support)
\r
94 throws DatabaseException;
\r
96 public boolean isComplete(int resourceKey, ClusterSupport support)
\r
97 throws DatabaseException;
\r
99 public <Context> boolean forPredicates(int resourceKey, PredicateProcedure<Context> procedure, Context context, ClusterSupport support)
\r
100 throws DatabaseException;
\r
102 public <Context> boolean forObjects(int resourceKey, int predicateKey, int objectIndex, ObjectProcedure<Context> procedure, Context context, ClusterSupport support)
\r
103 throws DatabaseException;
\r
105 public <Context> boolean forObjects(int resourceKey, int predicateKey, ObjectProcedure<Context> procedure, Context context, ClusterSupport support)
\r
106 throws DatabaseException;
\r
108 public int getSingleObject(int resourceKey, int predicateKey, ClusterSupport support)
\r
109 throws DatabaseException;
\r
111 public <T> int getSingleObject(int resourceKey, ForPossibleRelatedValueProcedure<T> procedure, ClusterSupport support)
\r
112 throws DatabaseException;
\r
114 public <C, T> int getSingleObject(int resourceKey, ForPossibleRelatedValueContextProcedure<C, T> procedure, ClusterSupport support)
\r
115 throws DatabaseException;
\r
117 public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, AsyncMultiProcedure<Resource> procedure)
\r
118 throws DatabaseException;
\r
120 public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure)
\r
121 throws DatabaseException;
\r
123 public <C> void forObjects(ReadGraphImpl graph, int resourceKey, C context, ForEachObjectContextProcedure<C> procedure)
\r
124 throws DatabaseException;
\r
127 * @param callerThread
\r
128 * @param resourceKey
\r
129 * @param predicateKey
\r
132 * @return null if relation already existed. Otherwise an old or new instance of ClusterI.
\r
133 * @throws DatabaseException
\r
135 public ClusterI addRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)
\r
136 throws DatabaseException;
\r
138 public boolean removeRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)
\r
139 throws DatabaseException;
\r
141 public void denyRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)
\r
142 throws DatabaseException;
\r
145 * @param callerThread
\r
146 * @param resourceKey
\r
148 * @return null if no value
\r
149 * @throws DatabaseException
\r
151 public byte[] getValue(int resourceKey, ClusterSupport support)
\r
152 throws DatabaseException;
\r
154 public InputStream getValueStream(int resourceKey, ClusterSupport support)
\r
155 throws DatabaseException;
\r
157 public boolean hasValue(int resourceKey, ClusterSupport support)
\r
158 throws DatabaseException;
\r
160 public boolean removeValue(int resourceKey, ClusterSupport support)
\r
161 throws DatabaseException;
\r
164 * @param callerThread
\r
165 * @param resourceKey
\r
168 * @return An old or new instance of ClusterI.
\r
169 * @throws DatabaseException
\r
171 public ClusterI setValue(int resourceKey, byte[] value, int length, ClusterSupport support)
\r
172 throws DatabaseException;
\r
174 public ClusterI modiValueEx(int resourceKey, long voffset, int length, byte[] value, int offset, ClusterSupport support)
\r
175 throws DatabaseException;
\r
177 public byte[] readValueEx(int resourceKey, long voffset, int length, ClusterSupport support)
\r
178 throws DatabaseException;
\r
180 public long getValueSizeEx(int resourceKey, ClusterSupport support)
\r
181 throws DatabaseException;
\r
183 public void setValueEx(int resourceKey)
\r
184 throws DatabaseException;
\r
186 public int createResource(ClusterSupport support)
\r
187 throws DatabaseException;
\r
189 public boolean hasResource(int resourceKey, ClusterSupport support)
\r
190 throws DatabaseException;
\r
192 public int getNumberOfResources(ClusterSupport support) throws DatabaseException;
\r
194 public long getCachedSize();
\r
196 public long getUsedSpace()
\r
197 throws DatabaseException;
\r
199 public boolean isEmpty();
\r
201 public void printDebugInfo(String message, ClusterSupport support)
\r
202 throws DatabaseException;
\r
204 public long getClusterId();
\r
206 public int getClusterKey();
\r
208 public boolean isWriteOnly();
\r
211 throws DatabaseException;
\r
213 public void load(Callback<DatabaseException> callback);
\r
214 public void load(ClusterSupport session, Runnable callback);
\r
217 public boolean hasVirtual();
\r
218 public void markVirtual();
\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
230 public boolean contains(int resource);
\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
238 public ClusterUID getClusterUID();
\r
239 // public Id getModifiedId();
\r