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