1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package fi.vtt.simantics.procore.internal;
\r
14 import java.io.InputStream;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
18 import org.simantics.db.impl.ClusterI;
\r
19 import org.simantics.db.impl.ClusterSupport;
\r
20 import org.simantics.db.impl.ClusterTraitsBase;
\r
21 import org.simantics.db.impl.ForEachObjectContextProcedure;
\r
22 import org.simantics.db.impl.ForEachObjectProcedure;
\r
23 import org.simantics.db.impl.ForPossibleRelatedValueContextProcedure;
\r
24 import org.simantics.db.impl.ForPossibleRelatedValueProcedure;
\r
25 import org.simantics.db.impl.Table;
\r
26 import org.simantics.db.impl.graph.ReadGraphImpl;
\r
27 import org.simantics.db.procedure.AsyncMultiProcedure;
\r
28 import org.simantics.db.procore.cluster.ClusterBig;
\r
29 import org.simantics.db.procore.cluster.ClusterImpl;
\r
30 import org.simantics.db.procore.cluster.ClusterTraits;
\r
31 import org.simantics.db.service.ClusterUID;
\r
32 import org.simantics.utils.datastructures.Callback;
\r
34 import fi.vtt.simantics.procore.DebugPolicy;
\r
36 final public class ClusterWriteOnly extends ClusterImpl {
\r
38 final SessionImplSocket sessionImpl;
\r
39 final ClusterTable clusterTable;
\r
40 private final int clusterKeyHigh;
\r
41 private short currentIndex;
\r
43 ClusterWriteOnly(ClusterUID clusterUID, int clusterKey, SessionImplSocket sessionImpl) {
\r
44 super(clusterUID , clusterKey, sessionImpl.clusterTranslator);
\r
45 if(DebugPolicy.REPORT_CLUSTER_EVENTS)
\r
46 new Exception(clusterUID.toString()).printStackTrace();
\r
47 assert(sessionImpl != null);
\r
48 this.sessionImpl = sessionImpl;
\r
49 this.clusterKeyHigh = ClusterTraits.getClusterBits(clusterKey);
\r
50 this.cc = new ClusterChange(sessionImpl.clusterStream, this);
\r
51 clusterTable = sessionImpl.clusterTable;
\r
53 setImportance(Long.MAX_VALUE);
\r
59 public void releaseMemory() {
\r
62 public void compact() {
\r
65 public boolean isLoaded() {
\r
66 return true; // write only cluster is never loaded
\r
69 public boolean isWriteOnly() {
\r
73 public int createResource(ClusterSupport support) throws DatabaseException {
\r
74 cc.createResource(currentIndex);
\r
75 // System.err.println("write only resource [" + clusterId + "] " + currentIndex);
\r
76 if(DebugPolicy.REPORT_RESOURCE_ID_ALLOCATION)
\r
77 System.out.println("[RID_ALLOCATION]: ClusterWriteOnly[" + clusterId + "] allocates " + currentIndex);
\r
78 return clusterKeyHigh + currentIndex++;
\r
81 public boolean hasResource(int r, ClusterSupport support)
\r
82 throws DatabaseException {
\r
83 int resourceIndex = ClusterTraits.getResourceIndexFromResourceKey(r);
\r
84 if (ClusterTraits.getClusterKeyFromResourceKey(r) != this.clusterKey)
\r
86 if (resourceIndex > 0 && resourceIndex <= currentIndex)
\r
91 private void addChange(int s, int p, int o, ClusterSupport a, byte operation) throws DatabaseException {
\r
93 change.op0 = operation;
\r
98 if(ClusterTraits.isCluster(clusterKeyHigh, p)) {
\r
99 change.clusterUID1 = getClusterUID();
\r
101 change.clusterUID1 = clusterTable.getClusterUIDByResourceKey(p);
\r
104 if(ClusterTraits.isCluster(clusterKeyHigh, o)) {
\r
105 change.clusterUID2 = getClusterUID();
\r
107 change.clusterUID2 = clusterTable.getClusterUIDByResourceKey(o);
\r
110 cc.addChange(change);
\r
113 public ClusterI addRelation(int s, int p, int o, ClusterSupport a) throws DatabaseException {
\r
114 addChange(s, p, o, a, ClusterChange.ADD_OPERATION);
\r
118 synchronized public boolean removeRelation(int s, int p, int o, ClusterSupport a) throws DatabaseException {
\r
119 addChange(s, p, o, a, ClusterChange.REMOVE_OPERATION);
\r
123 synchronized public void denyRelation(int s, int p, int o, ClusterSupport a) throws DatabaseException {
\r
124 addChange(s, p, o, a, ClusterChange.REMOVE_OPERATION);
\r
127 synchronized public ClusterI setValue(int s, byte[] value, int length, ClusterSupport a)
\r
128 throws DatabaseException {
\r
129 sessionImpl.clusterTranslator.addStatementIndex(this, s, getClusterUID(), ClusterStream.SET_OPERATION);
\r
130 sessionImpl.clusterTranslator.setValue(this, clusterId, value, length);
\r
134 public ClusterI modiValueEx(int s, long voffset, int length, byte[] value, int offset, ClusterSupport support)
\r
135 throws DatabaseException {
\r
136 sessionImpl.clusterTranslator.addStatementIndex(this, s, getClusterUID(), ClusterStream.MODI_OPERATION);
\r
137 support.modiValue(this, getClusterId(), voffset, length, value, offset);
\r
141 public byte[] readValueEx(int s, long voffset, int length, ClusterSupport support)
\r
142 throws DatabaseException {
\r
143 throw new Error("Not implemented");
\r
146 public long getValueSizeEx(int rResourceId, ClusterSupport support)
\r
147 throws DatabaseException {
\r
148 throw new Error("Not implemented");
\r
151 synchronized public void setValueEx(int s)
\r
152 throws DatabaseException {
\r
155 synchronized public boolean removeValue(int s, ClusterSupport a) {
\r
156 throw new Error("Not implemented");
\r
159 synchronized public ClusterI getClusterByResourceKey(int resourceKey, ClusterSupport support) {
\r
160 int clusterShortId = ClusterTraitsBase.getClusterKeyFromResourceKeyNoThrow(resourceKey);
\r
161 if (this.clusterKey == clusterShortId)
\r
163 return support.getClusterByResourceKey(resourceKey);
\r
166 synchronized public int getNumberOfResources(ClusterSupport support) {
\r
167 return currentIndex - 1;
\r
170 public boolean isEmpty() {
\r
174 public long getUsedSpace()
\r
175 throws DatabaseException {
\r
176 throw new DatabaseException("Not implemented.");
\r
179 public void decreaseReferenceCount(int amount) {
\r
182 public void increaseReferenceCount(int amount) {
\r
185 public int getReferenceCount() {
\r
189 public byte[] getValue(int sr, ClusterSupport a) {
\r
190 throw new Error("Not implemented.");
\r
193 public InputStream getValueStream(int resourceKey, ClusterSupport support) throws DatabaseException {
\r
194 throw new Error("Not implemented.");
\r
197 public boolean hasValue(int r, ClusterSupport a) {
\r
198 throw new Error("Not implemented.");
\r
201 public void printDebugInfo(String message, ClusterSupport support) {
\r
202 throw new Error("Not implemented.");
\r
205 public void load() {
\r
208 public void load(Callback<DatabaseException> r) {
\r
212 public int getSingleObject(int resourceKey, int predicateKey, ClusterSupport support) throws DatabaseException {
\r
213 throw new DatabaseException("Not implemented.");
\r
216 public <T> int getSingleObject(int resourceKey,
\r
217 ForPossibleRelatedValueProcedure<T> procedure,
\r
218 ClusterSupport support) throws DatabaseException {
\r
219 throw new DatabaseException("Not implemented.");
\r
222 public <C, T> int getSingleObject(int resourceKey,
\r
223 ForPossibleRelatedValueContextProcedure<C, T> procedure,
\r
224 ClusterSupport support) throws DatabaseException {
\r
225 throw new DatabaseException("Not implemented.");
\r
228 public void forObjects(ReadGraphImpl graph, int resourceKey, int predicateKey,
\r
229 AsyncMultiProcedure<Resource> procedure) throws DatabaseException {
\r
230 throw new DatabaseException("Not implemented.");
\r
233 public <Context> boolean forObjects(int resourceKey, int predicateKey, int objectIndex,
\r
234 ObjectProcedure<Context> procedure, Context context, ClusterSupport support) throws DatabaseException {
\r
235 throw new DatabaseException("Not implemented.");
\r
238 public void forObjects(ReadGraphImpl graph, int resourceKey,
\r
239 ForEachObjectProcedure procedure) throws DatabaseException {
\r
240 throw new DatabaseException("Not implemented.");
\r
243 public <C> void forObjects(ReadGraphImpl graph, int resourceKey, C context,
\r
244 ForEachObjectContextProcedure<C> procedure) throws DatabaseException {
\r
245 throw new DatabaseException("Not implemented.");
\r
248 public <Context> boolean forObjects(int resourceKey, int predicateKey,
\r
249 ObjectProcedure<Context> procedure, Context context, ClusterSupport support) throws DatabaseException {
\r
250 throw new DatabaseException("Not implemented.");
\r
253 public <Context> boolean forPredicates(int resourceKey,
\r
254 PredicateProcedure<Context> procedure, Context context, ClusterSupport support) throws DatabaseException {
\r
255 throw new DatabaseException("Not implemented.");
\r
258 public int getCompleteObjectKey(int resourceKey, ClusterSupport support) throws DatabaseException {
\r
259 throw new DatabaseException("Not implemented.");
\r
262 public CompleteTypeEnum getCompleteType(int resourceKey, ClusterSupport support)
\r
263 throws DatabaseException {
\r
264 throw new DatabaseException("Not implemented.");
\r
267 public boolean isComplete(int resourceKey, ClusterSupport support) throws DatabaseException {
\r
268 throw new DatabaseException("Not implemented.");
\r
271 public boolean hasVirtual() {
\r
275 public void markVirtual() {
\r
278 public void load(ClusterSupport session, Runnable callback) {
\r
282 public boolean contains(int resource) {
\r
287 public ClusterTypeEnum getType() {
\r
288 return ClusterTypeEnum.WRITEONLY;
\r
291 public int execute(int valueToModify) throws DatabaseException {
\r
292 throw new Error("Not supported");
\r
295 public ClusterBig toBig(ClusterSupport support) throws DatabaseException {
\r
296 throw new Error("Not supported");
\r
299 public void checkDirectReference(int dr) throws DatabaseException {
\r
300 throw new Error("Not supported");
\r
303 public void checkForeingIndex(int fi) throws DatabaseException {
\r
304 throw new Error("Not supported");
\r
307 public void checkObjectSetReference(int or) throws DatabaseException {
\r
308 throw new Error("Not supported");
\r
311 public boolean getImmutable() {
\r
315 public void setImmutable(boolean immutable, ClusterSupport support) {
\r
316 sessionImpl.clusterTranslator.setImmutable(this, immutable);
\r
319 public boolean getDeleted() {
\r
323 public void setDeleted(boolean deleted, ClusterSupport support) {
\r
324 sessionImpl.clusterTranslator.setDeleted(this, deleted);
\r
327 public void checkValueInit() throws DatabaseException {
\r
328 throw new UnsupportedOperationException();
\r
332 public void checkCompleteSetReference(int cr) throws DatabaseException {
\r
333 throw new UnsupportedOperationException();
\r
337 public void checkPredicateIndex(int pi) throws DatabaseException {
\r
338 throw new UnsupportedOperationException();
\r
342 public void checkValue(int capacity, int index) throws DatabaseException {
\r
343 throw new UnsupportedOperationException();
\r
347 public void checkValueFini() throws DatabaseException {
\r
348 throw new UnsupportedOperationException();
\r
352 public Table<?> getPredicateTable() {
\r
353 throw new UnsupportedOperationException();
\r
356 public Table<?> getForeignTable() {
\r
357 throw new UnsupportedOperationException();
\r
360 public Table<?> getCompleteTable() {
\r
361 throw new UnsupportedOperationException();
\r
364 public Table<?> getValueTable() {
\r
365 throw new UnsupportedOperationException();
\r
368 public int makeResourceKey(int pRef) throws DatabaseException {
\r
369 throw new UnsupportedOperationException();
\r
372 public Table<?> getObjectTable() {
\r
373 throw new UnsupportedOperationException();
\r