--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.impl;\r
+\r
+import java.io.InputStream;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.impl.graph.ReadGraphImpl;\r
+import org.simantics.db.procedure.AsyncMultiProcedure;\r
+import org.simantics.db.service.ClusterUID;\r
+import org.simantics.utils.datastructures.Callback;\r
+\r
+public interface ClusterI {\r
+ public enum TypeEnum {\r
+ Small, Big\r
+ }\r
+ public interface Procedure {\r
+ \r
+ }\r
+ public interface PredicateProcedure<Context> extends Procedure {\r
+ /**\r
+ * @param context is whatever you want.\r
+ * @param resourceKey is either subject, predicate or object resource key.\r
+ * @return true if you want to break loop.\r
+ */\r
+ boolean execute(Context context, int resourceKey, int objectIndex);\r
+ }\r
+ public interface ObjectProcedure<Context> extends Procedure {\r
+ /**\r
+ * @param context is whatever you want.\r
+ * @param resourceKey is either subject, predicate or object resource key.\r
+ * @return true if you want to break loop.\r
+ */\r
+ boolean execute(Context context, int resourceKey) throws DatabaseException;\r
+ //boolean found();\r
+\r
+ }\r
+\r
+ /**\r
+ * Resource is complete if it has exactly one IIS statement. If resource has\r
+ * multiple IIS statements it's complete reference is index to complete\r
+ * table (and not zero).\r
+ */\r
+ enum CompleteTypeEnum {\r
+ NotComplete(0),\r
+ InstanceOf(1),\r
+ Inherits(2),\r
+ SubrelationOf(3);\r
+ public static final CompleteTypeEnum make(int value) {\r
+ switch (value) {\r
+ default:\r
+ throw new Error("Internal error. Illegal complete type=" + value + ".");\r
+ case 0:\r
+ assert(0 == ClusterI.CompleteTypeEnum.NotComplete.getValue());\r
+ return ClusterI.CompleteTypeEnum.NotComplete;\r
+ case 1:\r
+ assert(1 == ClusterI.CompleteTypeEnum.InstanceOf.getValue());\r
+ return ClusterI.CompleteTypeEnum.InstanceOf;\r
+ case 2:\r
+ assert(2 == ClusterI.CompleteTypeEnum.Inherits.getValue());\r
+ return ClusterI.CompleteTypeEnum.Inherits;\r
+ case 3:\r
+ assert(3 == ClusterI.CompleteTypeEnum.SubrelationOf.getValue());\r
+ return ClusterI.CompleteTypeEnum.SubrelationOf;\r
+ }\r
+ }\r
+ public final byte getValue() {\r
+ return value;\r
+ }\r
+ private CompleteTypeEnum(int value) {\r
+ this.value = (byte)value;\r
+ }\r
+ private byte value;\r
+ }\r
+\r
+ enum ClusterTypeEnum {\r
+ SMALL, BIG, WRITEONLY\r
+ }\r
+\r
+ public CompleteTypeEnum getCompleteType(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public int getCompleteObjectKey(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public boolean isComplete(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public <Context> boolean forPredicates(int resourceKey, PredicateProcedure<Context> procedure, Context context, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public <Context> boolean forObjects(int resourceKey, int predicateKey, int objectIndex, ObjectProcedure<Context> procedure, Context context, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public <Context> boolean forObjects(int resourceKey, int predicateKey, ObjectProcedure<Context> procedure, Context context, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public int getSingleObject(int resourceKey, int predicateKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public <T> int getSingleObject(int resourceKey, ForPossibleRelatedValueProcedure<T> procedure, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public <C, T> int getSingleObject(int resourceKey, ForPossibleRelatedValueContextProcedure<C, T> procedure, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, AsyncMultiProcedure<Resource> procedure)\r
+ throws DatabaseException;\r
+\r
+ public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure)\r
+ throws DatabaseException;\r
+\r
+ public <C> void forObjects(ReadGraphImpl graph, int resourceKey, C context, ForEachObjectContextProcedure<C> procedure)\r
+ throws DatabaseException;\r
+\r
+ /**\r
+ * @param callerThread\r
+ * @param resourceKey\r
+ * @param predicateKey\r
+ * @param objectKey\r
+ * @param support\r
+ * @return null if relation already existed. Otherwise an old or new instance of ClusterI.\r
+ * @throws DatabaseException\r
+ */\r
+ public ClusterI addRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public boolean removeRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public void denyRelation(int resourceKey, int predicateKey, int objectKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ /**\r
+ * @param callerThread\r
+ * @param resourceKey\r
+ * @param support\r
+ * @return null if no value\r
+ * @throws DatabaseException\r
+ */\r
+ public byte[] getValue(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public InputStream getValueStream(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public boolean hasValue(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public boolean removeValue(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ /**\r
+ * @param callerThread\r
+ * @param resourceKey\r
+ * @param value\r
+ * @param support\r
+ * @return An old or new instance of ClusterI.\r
+ * @throws DatabaseException\r
+ */\r
+ public ClusterI setValue(int resourceKey, byte[] value, int length, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public ClusterI modiValueEx(int resourceKey, long voffset, int length, byte[] value, int offset, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public byte[] readValueEx(int resourceKey, long voffset, int length, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public long getValueSizeEx(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public void setValueEx(int resourceKey)\r
+ throws DatabaseException;\r
+\r
+ public int createResource(ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public boolean hasResource(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public int getNumberOfResources(ClusterSupport support) throws DatabaseException;\r
+\r
+ public long getCachedSize();\r
+\r
+ public long getUsedSpace()\r
+ throws DatabaseException;\r
+\r
+ public boolean isEmpty();\r
+\r
+ public void printDebugInfo(String message, ClusterSupport support)\r
+ throws DatabaseException;\r
+\r
+ public long getClusterId();\r
+\r
+ public int getClusterKey();\r
+\r
+ public boolean isWriteOnly();\r
+\r
+ public void load()\r
+ throws DatabaseException;\r
+\r
+ public void load(Callback<DatabaseException> callback);\r
+ public void load(ClusterSupport session, Runnable callback);\r
+\r
+\r
+ public boolean hasVirtual();\r
+ public void markVirtual();\r
+\r
+ public ClusterI getClusterByResourceKey(int resourceKey, ClusterSupport support);\r
+ public boolean isLoaded();\r
+ public void increaseReferenceCount(int amount);\r
+ public void decreaseReferenceCount(int amount);\r
+ public int getReferenceCount();\r
+ public long getImportance();\r
+ public void setImportance(long i);\r
+ public void releaseMemory();\r
+ public void compact();\r
+\r
+ public boolean contains(int resource);\r
+\r
+ public ClusterTypeEnum getType();\r
+ public boolean getImmutable();\r
+ public void setImmutable(boolean immutable, ClusterSupport support);\r
+ public boolean getDeleted();\r
+ public void setDeleted(boolean deleted, ClusterSupport support);\r
+\r
+ public ClusterUID getClusterUID();\r
+// public Id getModifiedId();\r
+\r
+}\r