--- /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 fi.vtt.simantics.procore.internal;\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.ClusterI;\r
+import org.simantics.db.impl.ClusterSupport;\r
+import org.simantics.db.impl.ClusterTraitsBase;\r
+import org.simantics.db.impl.ForEachObjectContextProcedure;\r
+import org.simantics.db.impl.ForEachObjectProcedure;\r
+import org.simantics.db.impl.ForPossibleRelatedValueContextProcedure;\r
+import org.simantics.db.impl.ForPossibleRelatedValueProcedure;\r
+import org.simantics.db.impl.Table;\r
+import org.simantics.db.impl.graph.ReadGraphImpl;\r
+import org.simantics.db.procedure.AsyncMultiProcedure;\r
+import org.simantics.db.procore.cluster.ClusterBig;\r
+import org.simantics.db.procore.cluster.ClusterImpl;\r
+import org.simantics.db.procore.cluster.ClusterTraits;\r
+import org.simantics.db.service.ClusterUID;\r
+import org.simantics.utils.datastructures.Callback;\r
+\r
+import fi.vtt.simantics.procore.DebugPolicy;\r
+\r
+final public class ClusterWriteOnly extends ClusterImpl {\r
+\r
+ final SessionImplSocket sessionImpl;\r
+ final ClusterTable clusterTable;\r
+ private final int clusterKeyHigh;\r
+ private short currentIndex;\r
+\r
+ ClusterWriteOnly(ClusterUID clusterUID, int clusterKey, SessionImplSocket sessionImpl) {\r
+ super(clusterUID , clusterKey, sessionImpl.clusterTranslator);\r
+ if(DebugPolicy.REPORT_CLUSTER_EVENTS)\r
+ new Exception(clusterUID.toString()).printStackTrace();\r
+ assert(sessionImpl != null);\r
+ this.sessionImpl = sessionImpl;\r
+ this.clusterKeyHigh = ClusterTraits.getClusterBits(clusterKey);\r
+ this.cc = new ClusterChange(sessionImpl.clusterStream, this);\r
+ clusterTable = sessionImpl.clusterTable;\r
+ currentIndex = 1;\r
+ setImportance(Long.MAX_VALUE);\r
+ }\r
+ boolean isNew() {\r
+ return true;\r
+ }\r
+ @Override\r
+ public void releaseMemory() {\r
+ }\r
+ @Override\r
+ public void compact() {\r
+ }\r
+ @Override\r
+ public boolean isLoaded() {\r
+ return true; // write only cluster is never loaded\r
+ }\r
+ @Override\r
+ public boolean isWriteOnly() {\r
+ return true;\r
+ }\r
+ @Override\r
+ public int createResource(ClusterSupport support) throws DatabaseException {\r
+ cc.createResource(currentIndex);\r
+// System.err.println("write only resource [" + clusterId + "] " + currentIndex);\r
+ if(DebugPolicy.REPORT_RESOURCE_ID_ALLOCATION)\r
+ System.out.println("[RID_ALLOCATION]: ClusterWriteOnly[" + clusterId + "] allocates " + currentIndex);\r
+ return clusterKeyHigh + currentIndex++;\r
+ }\r
+ @Override\r
+ public boolean hasResource(int r, ClusterSupport support)\r
+ throws DatabaseException {\r
+ int resourceIndex = ClusterTraits.getResourceIndexFromResourceKey(r);\r
+ if (ClusterTraits.getClusterKeyFromResourceKey(r) != this.clusterKey)\r
+ return false;\r
+ if (resourceIndex > 0 && resourceIndex <= currentIndex)\r
+ return true;\r
+ else\r
+ return false;\r
+ }\r
+ private void addChange(int s, int p, int o, ClusterSupport a, byte operation) throws DatabaseException {\r
+\r
+ change.op0 = operation;\r
+ change.key0 = s;\r
+ change.key1 = p;\r
+ change.key2 = o;\r
+\r
+ if(ClusterTraits.isCluster(clusterKeyHigh, p)) {\r
+ change.clusterUID1 = getClusterUID();\r
+ } else {\r
+ change.clusterUID1 = clusterTable.getClusterUIDByResourceKey(p);\r
+ }\r
+\r
+ if(ClusterTraits.isCluster(clusterKeyHigh, o)) {\r
+ change.clusterUID2 = getClusterUID();\r
+ } else {\r
+ change.clusterUID2 = clusterTable.getClusterUIDByResourceKey(o);\r
+ }\r
+\r
+ cc.addChange(change);\r
+ }\r
+ @Override\r
+ public ClusterI addRelation(int s, int p, int o, ClusterSupport a) throws DatabaseException {\r
+ addChange(s, p, o, a, ClusterChange.ADD_OPERATION);\r
+ return this;\r
+ }\r
+ @Override\r
+ synchronized public boolean removeRelation(int s, int p, int o, ClusterSupport a) throws DatabaseException {\r
+ addChange(s, p, o, a, ClusterChange.REMOVE_OPERATION);\r
+ return true;\r
+ }\r
+ @Override\r
+ synchronized public void denyRelation(int s, int p, int o, ClusterSupport a) throws DatabaseException {\r
+ addChange(s, p, o, a, ClusterChange.REMOVE_OPERATION);\r
+ }\r
+ @Override\r
+ synchronized public ClusterI setValue(int s, byte[] value, int length, ClusterSupport a)\r
+ throws DatabaseException {\r
+ sessionImpl.clusterTranslator.addStatementIndex(this, s, getClusterUID(), ClusterStream.SET_OPERATION);\r
+ sessionImpl.clusterTranslator.setValue(this, clusterId, value, length);\r
+ return this;\r
+ }\r
+ @Override\r
+ public ClusterI modiValueEx(int s, long voffset, int length, byte[] value, int offset, ClusterSupport support)\r
+ throws DatabaseException {\r
+ sessionImpl.clusterTranslator.addStatementIndex(this, s, getClusterUID(), ClusterStream.MODI_OPERATION);\r
+ support.modiValue(this, getClusterId(), voffset, length, value, offset);\r
+ return this;\r
+ }\r
+ @Override\r
+ public byte[] readValueEx(int s, long voffset, int length, ClusterSupport support)\r
+ throws DatabaseException {\r
+ throw new Error("Not implemented");\r
+ }\r
+ @Override\r
+ public long getValueSizeEx(int rResourceId, ClusterSupport support)\r
+ throws DatabaseException {\r
+ throw new Error("Not implemented");\r
+ }\r
+ @Override\r
+ synchronized public void setValueEx(int s)\r
+ throws DatabaseException {\r
+ }\r
+ @Override\r
+ synchronized public boolean removeValue(int s, ClusterSupport a) {\r
+ throw new Error("Not implemented");\r
+ }\r
+ @Override\r
+ synchronized public ClusterI getClusterByResourceKey(int resourceKey, ClusterSupport support) {\r
+ int clusterShortId = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(resourceKey);\r
+ if (this.clusterKey == clusterShortId)\r
+ return this;\r
+ return support.getClusterByResourceKey(resourceKey);\r
+ }\r
+ @Override\r
+ synchronized public int getNumberOfResources(ClusterSupport support) {\r
+ return currentIndex - 1;\r
+ }\r
+ @Override\r
+ public boolean isEmpty() {\r
+ return true;\r
+ }\r
+ @Override\r
+ public long getUsedSpace()\r
+ throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public void decreaseReferenceCount(int amount) {\r
+ }\r
+ @Override\r
+ public void increaseReferenceCount(int amount) {\r
+ }\r
+ @Override\r
+ public int getReferenceCount() {\r
+ return 1;\r
+ }\r
+ @Override\r
+ public byte[] getValue(int sr, ClusterSupport a) {\r
+ throw new Error("Not implemented.");\r
+ }\r
+ @Override\r
+ public InputStream getValueStream(int resourceKey, ClusterSupport support) throws DatabaseException {\r
+ throw new Error("Not implemented.");\r
+ }\r
+ @Override\r
+ public boolean hasValue(int r, ClusterSupport a) {\r
+ throw new Error("Not implemented.");\r
+ }\r
+ @Override\r
+ public void printDebugInfo(String message, ClusterSupport support) {\r
+ throw new Error("Not implemented.");\r
+ }\r
+ @Override\r
+ public void load() {\r
+ }\r
+ @Override\r
+ public void load(Callback<DatabaseException> r) {\r
+ }\r
+\r
+ @Override\r
+ public int getSingleObject(int resourceKey, int predicateKey, ClusterSupport support) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public <T> int getSingleObject(int resourceKey,\r
+ ForPossibleRelatedValueProcedure<T> procedure,\r
+ ClusterSupport support) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public <C, T> int getSingleObject(int resourceKey,\r
+ ForPossibleRelatedValueContextProcedure<C, T> procedure,\r
+ ClusterSupport support) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey,\r
+ AsyncMultiProcedure<Resource> procedure) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public <Context> boolean forObjects(int resourceKey, int predicateKey, int objectIndex,\r
+ ObjectProcedure<Context> procedure, Context context, ClusterSupport support) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public void forObjects(ReadGraphImpl graph, int resourceKey,\r
+ ForEachObjectProcedure procedure) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public <C> void forObjects(ReadGraphImpl graph, int resourceKey, C context,\r
+ ForEachObjectContextProcedure<C> procedure) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public <Context> boolean forObjects(int resourceKey, int predicateKey,\r
+ ObjectProcedure<Context> procedure, Context context, ClusterSupport support) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public <Context> boolean forPredicates(int resourceKey,\r
+ PredicateProcedure<Context> procedure, Context context, ClusterSupport support) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public int getCompleteObjectKey(int resourceKey, ClusterSupport support) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public CompleteTypeEnum getCompleteType(int resourceKey, ClusterSupport support)\r
+ throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public boolean isComplete(int resourceKey, ClusterSupport support) throws DatabaseException {\r
+ throw new DatabaseException("Not implemented.");\r
+ }\r
+ @Override\r
+ public boolean hasVirtual() {\r
+ return false;\r
+ }\r
+ @Override\r
+ public void markVirtual() {\r
+ }\r
+ @Override\r
+ public void load(ClusterSupport session, Runnable callback) {\r
+ throw new Error();\r
+ }\r
+ @Override\r
+ public boolean contains(int resource) {\r
+ throw new Error();\r
+ }\r
+\r
+ @Override\r
+ public ClusterTypeEnum getType() {\r
+ return ClusterTypeEnum.WRITEONLY;\r
+ }\r
+ @Override\r
+ public int execute(int valueToModify) throws DatabaseException {\r
+ throw new Error("Not supported");\r
+ }\r
+ @Override\r
+ public ClusterBig toBig(ClusterSupport support) throws DatabaseException {\r
+ throw new Error("Not supported");\r
+ }\r
+ @Override\r
+ public void checkDirectReference(int dr) throws DatabaseException {\r
+ throw new Error("Not supported");\r
+ }\r
+ @Override\r
+ public void checkForeingIndex(int fi) throws DatabaseException {\r
+ throw new Error("Not supported");\r
+ }\r
+ @Override\r
+ public void checkObjectSetReference(int or) throws DatabaseException {\r
+ throw new Error("Not supported");\r
+ }\r
+ @Override\r
+ public boolean getImmutable() {\r
+ return false;\r
+ }\r
+ @Override\r
+ public void setImmutable(boolean immutable, ClusterSupport support) {\r
+ sessionImpl.clusterTranslator.setImmutable(this, immutable);\r
+ }\r
+ @Override\r
+ public boolean getDeleted() {\r
+ return false;\r
+ }\r
+ @Override\r
+ public void setDeleted(boolean deleted, ClusterSupport support) {\r
+ sessionImpl.clusterTranslator.setDeleted(this, deleted);\r
+ }\r
+ @Override\r
+ public void checkValueInit() throws DatabaseException {\r
+ throw new UnsupportedOperationException();\r
+ \r
+ }\r
+ @Override\r
+ public void checkCompleteSetReference(int cr) throws DatabaseException {\r
+ throw new UnsupportedOperationException();\r
+ \r
+ }\r
+ @Override\r
+ public void checkPredicateIndex(int pi) throws DatabaseException {\r
+ throw new UnsupportedOperationException();\r
+ \r
+ }\r
+ @Override\r
+ public void checkValue(int capacity, int index) throws DatabaseException {\r
+ throw new UnsupportedOperationException();\r
+ \r
+ }\r
+ @Override\r
+ public void checkValueFini() throws DatabaseException {\r
+ throw new UnsupportedOperationException();\r
+ \r
+ }\r
+ @Override\r
+ public Table<?> getPredicateTable() {\r
+ throw new UnsupportedOperationException();\r
+ }\r
+ @Override\r
+ public Table<?> getForeignTable() {\r
+ throw new UnsupportedOperationException();\r
+ }\r
+ @Override\r
+ public Table<?> getCompleteTable() {\r
+ throw new UnsupportedOperationException();\r
+ }\r
+ @Override\r
+ public Table<?> getValueTable() {\r
+ throw new UnsupportedOperationException();\r
+ }\r
+ @Override\r
+ public int makeResourceKey(int pRef) throws DatabaseException {\r
+ throw new UnsupportedOperationException();\r
+ }\r
+ @Override\r
+ public Table<?> getObjectTable() {\r
+ throw new UnsupportedOperationException();\r
+ }\r
+}\r
+\r