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