X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2FClusterI.java;fp=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2FClusterI.java;h=d0d5d6b70cc707da1bd254b533541f8e3333e002;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java new file mode 100644 index 000000000..d0d5d6b70 --- /dev/null +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ClusterI.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * 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 org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.impl.graph.ReadGraphImpl; +import org.simantics.db.procedure.AsyncMultiProcedure; +import org.simantics.db.service.ClusterUID; +import org.simantics.utils.datastructures.Callback; + +public interface ClusterI { + public enum TypeEnum { + Small, Big + } + public interface Procedure { + + } + public interface PredicateProcedure 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 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 boolean forPredicates(int resourceKey, PredicateProcedure procedure, Context context, ClusterSupport support) + throws DatabaseException; + + public boolean forObjects(int resourceKey, int predicateKey, int objectIndex, ObjectProcedure procedure, Context context, ClusterSupport support) + throws DatabaseException; + + public boolean forObjects(int resourceKey, int predicateKey, ObjectProcedure procedure, Context context, ClusterSupport support) + throws DatabaseException; + + public int getSingleObject(int resourceKey, int predicateKey, ClusterSupport support) + throws DatabaseException; + + public int getSingleObject(int resourceKey, ForPossibleRelatedValueProcedure procedure, ClusterSupport support) + throws DatabaseException; + + public int getSingleObject(int resourceKey, ForPossibleRelatedValueContextProcedure procedure, ClusterSupport support) + throws DatabaseException; + + public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey, AsyncMultiProcedure procedure) + throws DatabaseException; + + public void forObjects(ReadGraphImpl graph, int resourceKey, ForEachObjectProcedure procedure) + throws DatabaseException; + + public void forObjects(ReadGraphImpl graph, int resourceKey, C context, ForEachObjectContextProcedure 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(Callback 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(); + +}