]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/RangeUpdateRequest.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.objmap2 / src / org / simantics / objmap / graph / impl / RangeUpdateRequest.java
diff --git a/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/RangeUpdateRequest.java b/bundles/org.simantics.objmap2/src/org/simantics/objmap/graph/impl/RangeUpdateRequest.java
new file mode 100644 (file)
index 0000000..fed1918
--- /dev/null
@@ -0,0 +1,77 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2013 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.objmap.graph.impl;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.procedure.SyncListener;\r
+import org.simantics.db.request.Read;\r
+\r
+import org.simantics.objmap.exceptions.MappingException;\r
+import org.simantics.objmap.forward.IForwardMapping;\r
+import org.simantics.objmap.graph.impl.Link;\r
+\r
+\r
+public class RangeUpdateRequest<Domain,Range> implements Read<Boolean>, SyncListener<Boolean> {\r
+\r
+    Link<Domain,Range> link;\r
+    /*\r
+     * Note that this map uses a read request that it has got from caller and \r
+     * not the one that is used in updateRange. This is intentional.\r
+     */\r
+    IForwardMapping<Domain, Range> map; // map==null is used to flag that request is performed once\r
+    Mapping<Domain, Range> mapping; // mapping==null is used as a flag the request disposed\r
+    \r
+    public RangeUpdateRequest(Link<Domain,Range> link, IForwardMapping<Domain,Range> map, Mapping<Domain,Range> mapping) {\r
+        this.link = link;\r
+        this.map = map;\r
+        this.mapping = mapping;\r
+    }\r
+\r
+    @Override\r
+    public Boolean perform(ReadGraph g) throws DatabaseException {\r
+        if(map != null) {\r
+            link.type.updateRange(g, map, link.domainElement, link.rangeElement);\r
+            map = null;\r
+            return Boolean.TRUE;\r
+        }\r
+        else if(mapping != null) {\r
+            mapping.domainModified(link);\r
+            mapping = null;\r
+            return Boolean.FALSE;\r
+        }\r
+        else\r
+            return null;\r
+    }\r
+    \r
+    @Override\r
+    public void exception(ReadGraph graph, Throwable throwable)\r
+            throws DatabaseException {\r
+        if(throwable instanceof DatabaseException)\r
+            throw (DatabaseException)throwable;\r
+        else\r
+            throw new MappingException(throwable);\r
+    }\r
+\r
+    @Override\r
+    public void execute(ReadGraph graph, Boolean result)\r
+            throws DatabaseException {       \r
+    }\r
+\r
+    @Override\r
+    public boolean isDisposed() {\r
+        return mapping == null || link.removed || mapping.isDisposed();\r
+    }\r
+    \r
+    \r
+    \r
+}\r