-package fi.vtt.simantics.procore.internal;\r
-\r
-import java.io.IOException;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.serialization.SerializationException;\r
-import org.simantics.databoard.serialization.Serializer;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteOnlyGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.exception.RuntimeDatabaseException;\r
-import org.simantics.db.impl.graph.WriteGraphImpl;\r
-import org.simantics.db.procore.cluster.ClusterImpl;\r
-import org.simantics.db.service.ClusterBuilder.ResourceHandle;\r
-import org.simantics.db.service.ClusterBuilder.StatementHandle;\r
-import org.simantics.db.service.SerialisationSupport;\r
-\r
-import fi.vtt.simantics.procore.internal.SessionImplSocket.WriteOnlySupport;\r
-\r
-final public class ResourceHandleImpl implements ResourceHandle {\r
- \r
- final private ClusterImpl cluster;\r
- final public int resourceKey;\r
- \r
- public ResourceHandleImpl(WriteOnlySupport support) throws DatabaseException {\r
- this.resourceKey = support.createResourceKey(1);\r
- this.cluster = support.currentCluster;\r
- if(cluster.cc == null) cluster.cc = new ClusterChange(support.stream, cluster);\r
- }\r
- \r
- public ResourceHandleImpl(ClusterStream stream, ClusterImpl cluster, int resourceKey) {\r
- this.resourceKey = resourceKey;\r
- this.cluster = cluster;\r
- if(cluster.cc == null) cluster.cc = new ClusterChange(stream, cluster);\r
- }\r
-\r
- @Override\r
- public void applyPredicate(Object cluster) {\r
- \r
- ClusterImpl impl = (ClusterImpl)cluster;\r
- impl.change.addStatementIndex1(resourceKey, this.cluster.clusterUID, (byte)0, impl.foreignLookup);\r
- \r
- }\r
-\r
- @Override\r
- public void applyObject(Object cluster) {\r
-\r
- ClusterImpl impl = (ClusterImpl)cluster;\r
- impl.change.addStatementIndex2(resourceKey, this.cluster.clusterUID, (byte)0, impl.foreignLookup);\r
- \r
- }\r
- \r
- @Override\r
- public void addStatement(StatementHandle handle) {\r
-\r
- if(cluster.getImmutable()) return;\r
-\r
- cluster.change.addStatementIndex0(resourceKey, ClusterChange.ADD_OPERATION);\r
- handle.apply(cluster);\r
- cluster.cc.addChange(cluster.change);\r
- \r
- }\r
- \r
- @Override\r
- public void addStatement(ResourceHandle predicate, ResourceHandle object) {\r
- \r
- if(cluster.getImmutable()) return;\r
- \r
- Change change = cluster.change;\r
- change.addStatementIndex0(resourceKey, ClusterChange.ADD_OPERATION);\r
- predicate.applyPredicate(cluster);\r
- object.applyObject(cluster);\r
- cluster.cc.addChange(change);\r
- \r
- }\r
- \r
- @Override\r
- public void addStatement(WriteOnlyGraph graph, ResourceHandle predicate, ResourceHandle object) throws DatabaseException {\r
- if(cluster.isWriteOnly()) addStatement(predicate, object);\r
- else {\r
- WriteGraphImpl impl = (WriteGraphImpl)graph;\r
- impl.writeSupport.claim(graph.getProvider(), resourceKey, ((ResourceHandleImpl)predicate).resourceKey, ((ResourceHandleImpl)object).resourceKey);\r
- }\r
- }\r
- \r
- @Override\r
- public void addValue(WriteOnlyGraph graph, byte[] bytes) throws DatabaseException {\r
-\r
- if(cluster.isWriteOnly()) cluster.cc.setValue((short)(resourceKey & 0xFFFF), bytes);\r
- else {\r
- WriteGraphImpl impl = (WriteGraphImpl)graph;\r
- impl.writeSupport.claimValue(null, resourceKey, bytes, bytes.length);\r
- }\r
- \r
- }\r
- \r
- @Override\r
- public void addValue(Object value, Binding binding) {\r
-\r
- try {\r
- Serializer ser = Bindings.getSerializerUnchecked(binding);\r
- byte[] bytes = ser.serialize(value);\r
- cluster.cc.setValue((short)(resourceKey & 0xFFFF), bytes);\r
- } catch (SerializationException e) {\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
- \r
- }\r
- \r
- @Override\r
- public void addValue(Object value, Serializer serializer) {\r
-\r
- try {\r
- byte[] bytes = serializer.serialize(value);\r
- cluster.cc.setValue((short)(resourceKey & 0xFFFF), bytes);\r
- } catch (SerializationException e) {\r
- e.printStackTrace();\r
- } catch (IOException e) {\r
- e.printStackTrace();\r
- }\r
- \r
- }\r
- \r
- @Override\r
- public Resource resource(SerialisationSupport ss) {\r
- try {\r
- return ss.getResource(resourceKey);\r
- } catch (DatabaseException e) {\r
- throw new RuntimeDatabaseException(e);\r
- }\r
- }\r
- \r
-}\r
+package fi.vtt.simantics.procore.internal;
+
+import java.io.IOException;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.serialization.SerializationException;
+import org.simantics.databoard.serialization.Serializer;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteOnlyGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.exception.RuntimeDatabaseException;
+import org.simantics.db.impl.graph.WriteGraphImpl;
+import org.simantics.db.procore.cluster.ClusterImpl;
+import org.simantics.db.service.ClusterBuilder.ResourceHandle;
+import org.simantics.db.service.ClusterBuilder.StatementHandle;
+import org.simantics.db.service.SerialisationSupport;
+
+import fi.vtt.simantics.procore.internal.SessionImplSocket.WriteOnlySupport;
+
+final public class ResourceHandleImpl implements ResourceHandle {
+
+ final private ClusterImpl cluster;
+ final public int resourceKey;
+
+ public ResourceHandleImpl(WriteOnlySupport support) throws DatabaseException {
+ this.resourceKey = support.createResourceKey(1);
+ this.cluster = support.currentCluster;
+ if(cluster.cc == null) cluster.cc = new ClusterChange(support.stream, cluster);
+ }
+
+ public ResourceHandleImpl(ClusterStream stream, ClusterImpl cluster, int resourceKey) {
+ this.resourceKey = resourceKey;
+ this.cluster = cluster;
+ if(cluster.cc == null) cluster.cc = new ClusterChange(stream, cluster);
+ }
+
+ @Override
+ public void applyPredicate(Object cluster) {
+
+ ClusterImpl impl = (ClusterImpl)cluster;
+ impl.change.addStatementIndex1(resourceKey, this.cluster.clusterUID, (byte)0, impl.foreignLookup);
+
+ }
+
+ @Override
+ public void applyObject(Object cluster) {
+
+ ClusterImpl impl = (ClusterImpl)cluster;
+ impl.change.addStatementIndex2(resourceKey, this.cluster.clusterUID, (byte)0, impl.foreignLookup);
+
+ }
+
+ @Override
+ public void addStatement(StatementHandle handle) {
+
+ if(cluster.getImmutable()) return;
+
+ cluster.change.addStatementIndex0(resourceKey, ClusterChange.ADD_OPERATION);
+ handle.apply(cluster);
+ cluster.cc.addChange(cluster.change);
+
+ }
+
+ @Override
+ public void addStatement(ResourceHandle predicate, ResourceHandle object) {
+
+ if(cluster.getImmutable()) return;
+
+ Change change = cluster.change;
+ change.addStatementIndex0(resourceKey, ClusterChange.ADD_OPERATION);
+ predicate.applyPredicate(cluster);
+ object.applyObject(cluster);
+ cluster.cc.addChange(change);
+
+ }
+
+ @Override
+ public void addStatement(WriteOnlyGraph graph, ResourceHandle predicate, ResourceHandle object) throws DatabaseException {
+ if(cluster.isWriteOnly()) addStatement(predicate, object);
+ else {
+ WriteGraphImpl impl = (WriteGraphImpl)graph;
+ impl.writeSupport.claim(graph.getProvider(), resourceKey, ((ResourceHandleImpl)predicate).resourceKey, ((ResourceHandleImpl)object).resourceKey);
+ }
+ }
+
+ @Override
+ public void addValue(WriteOnlyGraph graph, byte[] bytes) throws DatabaseException {
+
+ if(cluster.isWriteOnly()) cluster.cc.setValue((short)(resourceKey & 0xFFFF), bytes);
+ else {
+ WriteGraphImpl impl = (WriteGraphImpl)graph;
+ impl.writeSupport.claimValue(null, resourceKey, bytes, bytes.length);
+ }
+
+ }
+
+ @Override
+ public void addValue(Object value, Binding binding) {
+
+ try {
+ Serializer ser = Bindings.getSerializerUnchecked(binding);
+ byte[] bytes = ser.serialize(value);
+ cluster.cc.setValue((short)(resourceKey & 0xFFFF), bytes);
+ } catch (SerializationException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ public void addValue(Object value, Serializer serializer) {
+
+ try {
+ byte[] bytes = serializer.serialize(value);
+ cluster.cc.setValue((short)(resourceKey & 0xFFFF), bytes);
+ } catch (SerializationException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ public Resource resource(SerialisationSupport ss) {
+ try {
+ return ss.getResource(resourceKey);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ }
+
+}