]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
refs #3483
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 30 May 2012 15:21:00 +0000 (15:21 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 09:22:20 +0000 (11:22 +0200)
git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@25076 ac1ea38d-2e2b-0410-8846-a27921b304fc

33 files changed:
org.simantics.interop.mapping/.classpath [new file with mode: 0644]
org.simantics.interop.mapping/.project [new file with mode: 0644]
org.simantics.interop.mapping/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
org.simantics.interop.mapping/META-INF/MANIFEST.MF [new file with mode: 0644]
org.simantics.interop.mapping/build.properties [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/CancelException.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/ConnectionGenerationRule.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/ConnectionIdentificationRule.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/GenerationRule.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/IdentificationRule.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/InitializedRule.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/Logger.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingHints.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingRule.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingTools.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/ModificationRule.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/ModuleResolver.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/SplittingWriteGraph.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/WriteGraphProxy.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/DistanceComparator.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/GraphNode.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/Identifiable.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/Link.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ObjectIdentifiable.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ObjectSetIdentifiable.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceIdentifiable.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetIdentifiable.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetSplitIdentifiable.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetSplitIdentifiable2.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSplitIdentifiable.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSplitIdentifiable2.java [new file with mode: 0644]
org.simantics.interop.mapping/src/org/simantics/interop/mapping/internal/Activator.java [new file with mode: 0644]

diff --git a/org.simantics.interop.mapping/.classpath b/org.simantics.interop.mapping/.classpath
new file mode 100644 (file)
index 0000000..8a8f166
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<classpath>\r
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
+       <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>\r
+       <classpathentry kind="src" path="src"/>\r
+       <classpathentry kind="output" path="bin"/>\r
+</classpath>\r
diff --git a/org.simantics.interop.mapping/.project b/org.simantics.interop.mapping/.project
new file mode 100644 (file)
index 0000000..3303d01
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<projectDescription>\r
+       <name>org.simantics.interop.mapping</name>\r
+       <comment></comment>\r
+       <projects>\r
+       </projects>\r
+       <buildSpec>\r
+               <buildCommand>\r
+                       <name>org.eclipse.jdt.core.javabuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.ManifestBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+               <buildCommand>\r
+                       <name>org.eclipse.pde.SchemaBuilder</name>\r
+                       <arguments>\r
+                       </arguments>\r
+               </buildCommand>\r
+       </buildSpec>\r
+       <natures>\r
+               <nature>org.eclipse.pde.PluginNature</nature>\r
+               <nature>org.eclipse.jdt.core.javanature</nature>\r
+       </natures>\r
+</projectDescription>\r
diff --git a/org.simantics.interop.mapping/.settings/org.eclipse.jdt.core.prefs b/org.simantics.interop.mapping/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..f287d53
--- /dev/null
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1\r
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled\r
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6\r
+org.eclipse.jdt.core.compiler.compliance=1.6\r
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error\r
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error\r
+org.eclipse.jdt.core.compiler.source=1.6\r
diff --git a/org.simantics.interop.mapping/META-INF/MANIFEST.MF b/org.simantics.interop.mapping/META-INF/MANIFEST.MF
new file mode 100644 (file)
index 0000000..45b38ed
--- /dev/null
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Mapping
+Bundle-SymbolicName: org.simantics.interop.mapping
+Bundle-Version: 0.0.1.qualifier
+Bundle-Activator: org.simantics.interop.mapping.internal.Activator
+Bundle-Vendor: VTT
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.simantics.db;bundle-version="1.1.0",
+ org.simantics.db.common;bundle-version="1.1.0",
+ org.simantics.scl.types;bundle-version="0.1.0",
+ org.simantics.diagram;bundle-version="1.1.1",
+ org.apache.log4j;bundle-version="1.2.15",
+ org.simantics.db.layer0;bundle-version="1.1.0",
+ org.simantics.ui;bundle-version="1.0.0"
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
+Export-Package: org.simantics.interop.mapping,
+ org.simantics.interop.mapping.data
diff --git a/org.simantics.interop.mapping/build.properties b/org.simantics.interop.mapping/build.properties
new file mode 100644 (file)
index 0000000..41eb6ad
--- /dev/null
@@ -0,0 +1,4 @@
+source.. = src/\r
+output.. = bin/\r
+bin.includes = META-INF/,\\r
+               .\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/CancelException.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/CancelException.java
new file mode 100644 (file)
index 0000000..98dcbae
--- /dev/null
@@ -0,0 +1,28 @@
+package org.simantics.interop.mapping;\r
+\r
+public class CancelException extends Exception{\r
+\r
+       /**\r
+        * \r
+        */\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       public CancelException() {\r
+               super();\r
+       }\r
+\r
+       public CancelException(String message, Throwable cause) {\r
+               super(message, cause);\r
+       }\r
+\r
+       public CancelException(String message) {\r
+               super(message);\r
+       }\r
+\r
+       public CancelException(Throwable cause) {\r
+               super(cause);\r
+       }\r
+       \r
+       \r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/ConnectionGenerationRule.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/ConnectionGenerationRule.java
new file mode 100644 (file)
index 0000000..322a3b5
--- /dev/null
@@ -0,0 +1,13 @@
+package org.simantics.interop.mapping;\r
+\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.interop.mapping.data.GraphNode;\r
+import org.simantics.interop.mapping.data.Identifiable;\r
+import org.simantics.interop.mapping.data.Link;\r
+\r
+public interface ConnectionGenerationRule {\r
+       \r
+\r
+       public void generate(WriteGraph g, GraphNode<Identifiable> inputNode1, GraphNode<Identifiable> inputNode2, Link<Identifiable> link) throws Exception;\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/ConnectionIdentificationRule.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/ConnectionIdentificationRule.java
new file mode 100644 (file)
index 0000000..808bd1c
--- /dev/null
@@ -0,0 +1,11 @@
+package org.simantics.interop.mapping;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.interop.mapping.data.GraphNode;\r
+import org.simantics.interop.mapping.data.Identifiable;\r
+import org.simantics.interop.mapping.data.Link;\r
+\r
+public interface ConnectionIdentificationRule {\r
+\r
+       boolean mathces(ReadGraph g, GraphNode<Identifiable> inputNode1, GraphNode<Identifiable> inputNode2,  Link<Identifiable> link);\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/GenerationRule.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/GenerationRule.java
new file mode 100644 (file)
index 0000000..e6907f5
--- /dev/null
@@ -0,0 +1,20 @@
+package org.simantics.interop.mapping;\r
+\r
+\r
+\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.interop.mapping.data.GraphNode;\r
+import org.simantics.interop.mapping.data.Identifiable;\r
+\r
+public interface GenerationRule extends MappingRule{\r
+       \r
+       /**\r
+        * Generates Apros model from a single comos object\r
+        * @param g\r
+        * @param inputNode Node that is going to be mapped\r
+        * @param env used Mapping Environment\r
+        * @throws Exception\r
+        */\r
+       public boolean generate(WriteGraph g, GraphNode<Identifiable> inputNode) throws Exception;\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/IdentificationRule.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/IdentificationRule.java
new file mode 100644 (file)
index 0000000..a723d48
--- /dev/null
@@ -0,0 +1,10 @@
+package org.simantics.interop.mapping;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.interop.mapping.data.GraphNode;\r
+import org.simantics.interop.mapping.data.Identifiable;\r
+\r
+public interface IdentificationRule {\r
+\r
+       boolean matches(ReadGraph g, GraphNode<Identifiable> node);\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/InitializedRule.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/InitializedRule.java
new file mode 100644 (file)
index 0000000..7300a71
--- /dev/null
@@ -0,0 +1,16 @@
+package org.simantics.interop.mapping;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+/**\r
+ * Interface for Generation- ModifiactionRules for initialization.\r
+ * \r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public interface InitializedRule {\r
+       public void initialize(WriteGraph g, Resource model) throws DatabaseException;\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Logger.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Logger.java
new file mode 100644 (file)
index 0000000..8ec1c07
--- /dev/null
@@ -0,0 +1,133 @@
+package org.simantics.interop.mapping;\r
+\r
+import java.util.Properties;\r
+\r
+import org.simantics.diagram.LogManager;\r
+\r
+public class Logger {\r
+       \r
+       \r
+       public static final boolean ECHO = false;\r
+       public static final boolean TRACE = false;\r
+    public static final Properties defaultProperties = new Properties();\r
+    static {\r
+        defaultProperties.put("log4j.rootCategory", "INFO, default");\r
+        defaultProperties.put("log4j.appender.default", "org.apache.log4j.FileAppender");\r
+        defaultProperties.put("log4j.appender.default.File", "mapping.log");\r
+        defaultProperties.put("log4j.appender.default.append", "false");\r
+        defaultProperties.put("log4j.appender.default.layout", "org.apache.log4j.PatternLayout");\r
+        defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r %-5p - %m%n");\r
+        //defaultProperties.put("log4j.appender.default.layout.ConversionPattern", "%-6r [%15.15t] %-5p %30.30c - %m%n");\r
+    }\r
+    private static LogManager defaultLogManager = new LogManager(defaultProperties);\r
+    private static final Logger defaultErrorLogger = new Logger(LogManager.class);\r
+    private org.apache.log4j.Logger logger;\r
+    \r
+    Logger(Class<?> clazz) {\r
+       logger = defaultLogManager.getLogger(clazz);\r
+    }\r
+\r
+    /**\r
+     * Log a trace event.\r
+     * \r
+     * @param message message of the trace\r
+     * @param exception the exception, or <code>null</code>\r
+     */\r
+    public void logTrace(String message, Throwable exception) {\r
+        // Errors are much more useful with a stack trace!\r
+        if (TRACE) {\r
+               if (exception == null)\r
+                       exception = new RuntimeException();\r
+        }\r
+        logger.trace(message, exception);\r
+    }\r
+\r
+    /**\r
+     * Log an info event.\r
+     * \r
+     * @param message message of the info\r
+     * @param exception the exception, or <code>null</code>\r
+     */\r
+    public void logInfo(String message, Throwable exception) {\r
+        // Errors are much more useful with a stack trace!\r
+       if (TRACE) {\r
+               if (exception == null)\r
+                       exception = new RuntimeException();\r
+        }\r
+        logger.info(message, exception);\r
+    }\r
+    \r
+    /**\r
+     * Log an warning event.\r
+     * @param message\r
+     * @param exception\r
+     */\r
+    public void logWarning(String message, Throwable exception) {\r
+        // Errors are much more useful with a stack trace!\r
+       if (TRACE) {\r
+               if (exception == null)\r
+                       exception = new RuntimeException();\r
+        }\r
+        logger.warn(message, exception);\r
+    }\r
+   \r
+\r
+    /**\r
+     * Log an error event.\r
+     * \r
+     * @param message message of the error\r
+     * @param exception the exception, or <code>null</code>\r
+     */\r
+    public void logError(String message, Throwable exception) {\r
+        // Errors are much more useful with a stack trace!\r
+       if (TRACE) {\r
+               if (exception == null)\r
+                       exception = new RuntimeException();\r
+        }\r
+        logger.error(message, exception);\r
+    }\r
+\r
+    public static Logger getDefault() {\r
+        return defaultErrorLogger;\r
+    }\r
+    \r
+    public static LogManager getDefaultLogManager() {\r
+        return defaultLogManager;\r
+    }\r
+    \r
+    public static void setDefaultThreshold(String level) {\r
+       getDefaultLogManager().setThreshold(level);\r
+    }\r
+    \r
+    public static void defaultLogError(Throwable exception) {\r
+        getDefault().logError(exception.getLocalizedMessage(), exception);\r
+        if(ECHO) exception.printStackTrace();\r
+    }\r
+    public static void defaultLogError(String message) {\r
+        getDefault().logError(message, null);\r
+        if(ECHO)\r
+            System.err.println(message);\r
+    }\r
+    public static void defaultLogError(String message, Throwable exception) {\r
+        getDefault().logError(message, exception);\r
+        if(ECHO)\r
+            System.err.println(message);\r
+    }\r
+    public static void defaultLogInfo(String message) {\r
+        getDefault().logInfo(message, null);\r
+        if(ECHO)\r
+            System.err.println(message);\r
+    }\r
+    \r
+    public static void defaultLogWarning(String message) {\r
+        getDefault().logWarning(message, null);\r
+        if(ECHO)\r
+            System.err.println(message);\r
+    }\r
+    \r
+    public static void defaultLogTrace(String message) {\r
+        getDefault().logTrace(message, null);\r
+        if(ECHO)\r
+            System.err.println(message);\r
+    }\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/Mapper.java
new file mode 100644 (file)
index 0000000..6f700d3
--- /dev/null
@@ -0,0 +1,772 @@
+package org.simantics.interop.mapping;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.NullProgressMonitor;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.request.WriteResultRequest;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.layer0.util.SessionGarbageCollection;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.interop.mapping.data.GraphNode;\r
+import org.simantics.interop.mapping.data.Identifiable;\r
+import org.simantics.interop.mapping.data.Link;\r
+import org.simantics.interop.mapping.data.ResourceIdentifiable;\r
+import org.simantics.ui.jobs.SessionGarbageCollectorJob;\r
+import org.simantics.utils.datastructures.MapList;\r
+import org.simantics.utils.datastructures.Pair;\r
+\r
+/**\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class Mapper {\r
+       \r
+       public static final boolean USE_SPLIT_TRANSACTIONS = false; // Split transactions\r
+       public static int OBJECTS_PER_TRANSACTION = 5000;           // number of objects handled per transaction (split mode) \r
+       private static boolean SLEEP_BETWEEN_WRITES = false;        // sleep between transactions (split mode)     \r
+       private static int SLEEP_TIME = 10;                         // time to sleep (ms)\r
+       private static boolean COLLECT_BETWEEN_WRITES = false;      // Run SessionGC between split transactions\r
+       private static boolean COLLECT_WITHIN_TRANSACTIONS = true;  // Run Collect within transactions (both modes)\r
+       public static int OBJECTS_BEFORE_COLLECT = 5000;            // number of objects that are handled before collect (non-split mode)\r
+       \r
+       private List<InitializedRule> initializedRules = new ArrayList<InitializedRule>();\r
+       private List<Pair<IdentificationRule, Pair<Integer,GenerationRule>>> generationRules;\r
+       private List<List<ModificationRule>> globalModificationRules;\r
+       private List<List<Pair<IdentificationRule, ModificationRule>>> modificationRules;\r
+       private List<Pair<ConnectionIdentificationRule, ConnectionGenerationRule>> connectionRules;\r
+\r
+       int maxGenPass = 0;\r
+       \r
+       public Mapper() {\r
+               long maxMemory = Runtime.getRuntime().maxMemory();\r
+               maxMemory /= (1024*1024);                            // Convert to MB;\r
+               int use = 290;                                       // Estimated memory usage of the system\r
+               int freeMem = (int)maxMemory-use;                                        // Free memory for mappings    \r
+               OBJECTS_BEFORE_COLLECT = (freeMem * freeMem) / 1000; //600M heap -> 84, 3000M heap -> 5645\r
+               if (OBJECTS_BEFORE_COLLECT < 2)\r
+                       OBJECTS_BEFORE_COLLECT = 2;\r
+               OBJECTS_PER_TRANSACTION = OBJECTS_BEFORE_COLLECT;\r
+               \r
+               \r
+               generationRules = new ArrayList<Pair<IdentificationRule,Pair<Integer,GenerationRule>>>();\r
+               modificationRules = new ArrayList<List<Pair<IdentificationRule,ModificationRule>>>();\r
+               globalModificationRules = new ArrayList<List<ModificationRule>>();\r
+               connectionRules = new ArrayList<Pair<ConnectionIdentificationRule, ConnectionGenerationRule>>();\r
+       }\r
+       \r
+       public void addRule(int pass, IdentificationRule idRule, GenerationRule genRule) {\r
+               if (idRule == null || genRule == null) throw new NullPointerException();\r
+               generationRules.add(new Pair<IdentificationRule, Pair<Integer,GenerationRule>>(idRule, new Pair<Integer,GenerationRule>(pass,genRule)));\r
+               maxGenPass = Math.max(maxGenPass, pass);\r
+               if (genRule instanceof InitializedRule)\r
+                       initializedRules.add((InitializedRule)genRule);\r
+       }\r
+       \r
+       public void addRule(IdentificationRule idRule, MappingRule mappingRule) {\r
+               addRule(0,idRule,mappingRule);\r
+       }\r
+       \r
+       public void addRule(int pass, IdentificationRule idRule, MappingRule mappingRule) {\r
+               if (idRule == null || mappingRule == null) throw new NullPointerException();\r
+               if (mappingRule instanceof ModificationRule) {\r
+                       while (pass >= modificationRules.size()) {\r
+                               modificationRules.add(new ArrayList<Pair<IdentificationRule,ModificationRule>>());\r
+                       }\r
+                       List<Pair<IdentificationRule,ModificationRule>> priList = modificationRules.get(pass);\r
+                       priList.add(new Pair<IdentificationRule, ModificationRule>(idRule, (ModificationRule)mappingRule));\r
+               }\r
+               if (mappingRule instanceof GenerationRule)\r
+                       generationRules.add(new Pair<IdentificationRule, Pair<Integer,GenerationRule>>(idRule, new Pair<Integer,GenerationRule>(pass,(GenerationRule)mappingRule)));\r
+               if (mappingRule instanceof InitializedRule)\r
+                       initializedRules.add((InitializedRule)mappingRule);\r
+       }\r
+       \r
+       public void addRule(IdentificationRule idRule, ModificationRule... modRules) {\r
+               addRule(0, idRule, modRules);\r
+       }\r
+\r
+       public void addRule(int pass, IdentificationRule idRule, ModificationRule... modRules) {\r
+               if (idRule == null) throw new NullPointerException();\r
+               \r
+               while (pass >= modificationRules.size()) {\r
+                       modificationRules.add(new ArrayList<Pair<IdentificationRule,ModificationRule>>());\r
+               }\r
+               List<Pair<IdentificationRule,ModificationRule>> priList = modificationRules.get(pass);\r
+               \r
+               for (ModificationRule modRule : modRules){\r
+                       if (modRule == null) throw new NullPointerException();  \r
+                       priList.add(new Pair<IdentificationRule, ModificationRule>(idRule, modRule));\r
+                       if (modRule instanceof InitializedRule)\r
+                               initializedRules.add((InitializedRule)modRule);\r
+               }\r
+       }\r
+       public void addRule(ModificationRule modRule) {\r
+               addRule(0, modRule);\r
+       }\r
+       \r
+       public void addRule(int pass, ModificationRule modRule) {\r
+               if (modRule == null) throw new NullPointerException();\r
+               while (pass >= globalModificationRules.size()) {\r
+                       globalModificationRules.add(new ArrayList<ModificationRule>());\r
+               }\r
+               List<ModificationRule> priList = globalModificationRules.get(pass);\r
+               priList.add(modRule);\r
+               if (modRule instanceof InitializedRule)\r
+                       initializedRules.add((InitializedRule)modRule);\r
+       }\r
+       \r
+       public void addRule(ConnectionIdentificationRule idRule, ConnectionGenerationRule genRule) {\r
+               if (idRule == null || genRule == null) throw new NullPointerException();\r
+               connectionRules.add(new Pair<ConnectionIdentificationRule, ConnectionGenerationRule>(idRule, genRule));\r
+               if (genRule instanceof InitializedRule)\r
+                       initializedRules.add((InitializedRule)genRule);\r
+       }\r
+       \r
+       /**\r
+        * Runs the mapping procedure. Disposes nodes after mapping is done.\r
+        * @param g\r
+        * @param model\r
+        * @param nodes\r
+        * @param monitor\r
+        * @throws Exception\r
+        */\r
+       public void map(WriteGraph g, Resource model, Collection<GraphNode<Identifiable>> nodes, IProgressMonitor monitor) throws Exception {\r
+               startMapping(null);\r
+               try {\r
+                       if (monitor == null)\r
+                               monitor = new NullProgressMonitor();\r
+                       \r
+                       for (InitializedRule rule : initializedRules)\r
+                               rule.initialize(g, model);\r
+                       \r
+                       applyModifications(g, nodes, monitor);\r
+                       monitor.worked(1);\r
+                       applyGenerations(g,nodes,monitor);\r
+                       monitor.worked(1);\r
+                       applyConnections(g,nodes,monitor);\r
+                       monitor.worked(1);\r
+               } finally {\r
+                       MappingTools.disposeNodes(nodes);\r
+                       endMapping();\r
+               }\r
+               \r
+       }\r
+       \r
+       /**\r
+        * Runs the mapping procedure. Disposes nodes after mapping is done.\r
+        * @param session\r
+        * @param model\r
+        * @param nodes\r
+        * @param monitor\r
+        * @throws Exception\r
+        */\r
+       public void map(Session session, Resource model, Collection<GraphNode<Identifiable>> nodes, IProgressMonitor monitor) throws Exception {\r
+               map(session, model, null, nodes, monitor);\r
+       }\r
+       \r
+       /**\r
+        * Runs the mapping procedure. Disposes nodes after mapping is done.\r
+        * @param session\r
+        * @param model\r
+        * @param vg\r
+        * @param nodes\r
+        * @param monitor\r
+        * @throws Exception\r
+        */\r
+       public void map(Session session, Resource model, VirtualGraph vg, Collection<GraphNode<Identifiable>> nodes, IProgressMonitor monitor) throws Exception {\r
+               startMapping(vg);\r
+               try {\r
+                       long time = System.currentTimeMillis();\r
+                       if (monitor == null)\r
+                               monitor = new NullProgressMonitor();\r
+                       \r
+                       initializeRules(session, vg, model);\r
+                       if (USE_SPLIT_TRANSACTIONS) {\r
+                               applyModifications(session, nodes, monitor);\r
+                               monitor.worked(1);\r
+                               applyGenerations(session, vg, nodes, monitor);\r
+                               monitor.worked(1);\r
+                               applyConnections(session, vg, nodes, monitor);\r
+                               monitor.worked(1);\r
+                       } else {\r
+                               applyModifications2(session, nodes, monitor);\r
+                               monitor.worked(1);\r
+                               applyGenerations2(session, vg, nodes, monitor);\r
+                               monitor.worked(1);\r
+                               applyConnections2(session, vg, nodes, monitor);\r
+                               monitor.worked(1);\r
+                       }\r
+                       long time2 = System.currentTimeMillis();\r
+                       System.out.println("Mapping took " + ((time2-time)/1000) + " seconds");\r
+               } finally {\r
+                       MappingTools.disposeNodes(nodes);\r
+                       if (COLLECT_BETWEEN_WRITES) {\r
+\r
+                               SessionGarbageCollection.gc(null, session, true, null);\r
+                       }\r
+                       endMapping();\r
+               }\r
+               \r
+       }\r
+       \r
+       \r
+       //private boolean autosaveEndabled = false;\r
+       private VirtualGraph vg;\r
+       \r
+       protected void startMapping(VirtualGraph vg) {\r
+                SessionGarbageCollectorJob.getInstance().setEnabled(false);\r
+                //autosaveEndabled = AutosaveCommands.getInstance().isEnabled();\r
+                //AutosaveCommands.getInstance().setEnabled(false);\r
+                this.vg = vg;\r
+       }\r
+       \r
+       protected void endMapping() {\r
+                SessionGarbageCollectorJob.getInstance().setEnabled(true).scheduleAfterQuietTime();\r
+               // AutosaveCommands.getInstance().setEnabled(autosaveEndabled);\r
+                vg = null;\r
+       }\r
+       \r
+       private void applyModifications(ReadGraph g, Collection<GraphNode<Identifiable>> nodes, IProgressMonitor monitor) throws Exception {\r
+               \r
+               // Apply global modification rules first\r
+               \r
+               int passCount = Math.max(globalModificationRules.size(),modificationRules.size());\r
+\r
+               for (int pass = 0; pass < passCount; pass++) {\r
+                       if (globalModificationRules.size() > pass) {\r
+                               int count = 0;\r
+                               List<ModificationRule> modRules = globalModificationRules.get(pass);\r
+                               int size = modRules.size();\r
+                               monitor.subTask("Running global modification rules: pass (" + (pass+1) + "/" + passCount + "), rule ("+ (++count) + "/" + size + ")");\r
+                               for (ModificationRule r : modRules) {\r
+                                       Collection<GraphNode<Identifiable>> ruleModified = r.modify(g, nodes);\r
+                                       if (ruleModified == null)\r
+                                               continue;\r
+                                       for (GraphNode<Identifiable> m : ruleModified) {\r
+                                               if (m.isDisposed()) {\r
+                                                       nodes.remove(m);\r
+                                               }\r
+                                               else if (!nodes.contains(m)) {\r
+                                                       nodes.add(m);\r
+                                               }\r
+                                       }\r
+                                       monitor.subTask("Running global modification rules: pass (" + (pass+1) + "/" + passCount + "), rule ("+ (++count) + "/" + size + ")");\r
+                                       if(monitor.isCanceled()) {\r
+                                               throw new CancelException("Cancel requested.");\r
+                                       }\r
+                                       if (COLLECT_WITHIN_TRANSACTIONS)\r
+                                               collect(g);\r
+                               }\r
+                       } if (modificationRules.size() > pass) {\r
+                               int count = 0;\r
+                               List<Pair<IdentificationRule, ModificationRule>> modRules = modificationRules.get(pass);\r
+                               int size = modRules.size();\r
+                               monitor.subTask("Running object modification rules: pass (" + (pass+1) + "/" + passCount + "), rule ("+ (++count) + "/" + size + ")");\r
+                               // Apply per object modification rules \r
+                               for (Pair<IdentificationRule, ModificationRule> modRule : modRules) {\r
+                                       Collection<GraphNode<Identifiable>> ruleModified = new ArrayList<GraphNode<Identifiable>>();\r
+                                       for (GraphNode<Identifiable> n : nodes) {\r
+                                               applyModifications(g, n, modRule, ruleModified);\r
+                                               if (COLLECT_WITHIN_TRANSACTIONS)\r
+                                                       collect2(g);\r
+                                       }\r
+                                       \r
+                                       for (GraphNode<Identifiable> m : ruleModified) {\r
+                                               if (m.isDisposed()) {\r
+                                                       nodes.remove(m);\r
+                                               }\r
+                                               else if (!nodes.contains(m)) {\r
+                                                       nodes.add(m);\r
+                                               }\r
+                                       }\r
+                                       monitor.subTask("Running object modification rules: pass (" + (pass+1) + "/" + passCount + "), rule ("+ (++count) + "/" + size + ")");\r
+                                       if(monitor.isCanceled()) {\r
+                                               throw new CancelException("Cancel requested.");\r
+                                       }\r
+                                       \r
+                               }\r
+                       }\r
+               }\r
+               \r
+       }\r
+       \r
+       \r
+       \r
+       private void applyGenerations(WriteGraph graph, Collection<GraphNode<Identifiable>> nodes, IProgressMonitor monitor) throws Exception {\r
+               \r
+               int size = nodes.size();\r
+               int count = 0;\r
+               monitor.subTask("Assigning generation rules ("+ count + "/" + size + ")");\r
+               // populate generation rules\r
+               for (GraphNode<Identifiable> n : nodes) {\r
+                       \r
+                       for (Pair<IdentificationRule,Pair<Integer,GenerationRule>> r : generationRules) {\r
+                               if (r.first.matches(graph, n)) {\r
+                                       MappingTools.assignGenerationRule(n, r.second.first,r.second.second);\r
+                               }\r
+                       }\r
+                       monitor.subTask("Assigning generation rules ("+ (++count) + "/" + size + ")");\r
+                       if(monitor.isCanceled()) {\r
+                               throw new CancelException("Cancel requested.");\r
+                       }\r
+                       if (COLLECT_WITHIN_TRANSACTIONS)\r
+                               collect2(graph);\r
+               }\r
+               \r
+               count = 0;\r
+               monitor.subTask("Generating objects ("+ count + "/" + size + ")");\r
+               \r
+               // apply generation rules.\r
+               //WriteWrapper g  = new WriteWrapper(graph);\r
+               \r
+               //Collection<GenerationRule> usedRules = new ArrayList<GenerationRule>();\r
+               for (int stage = 0; stage <= maxGenPass; stage++) {\r
+                       count = 0;\r
+                       for (GraphNode<Identifiable> n : nodes) {\r
+\r
+                               MapList<Integer,GenerationRule> priRules = n.getHint(MappingHints.KEY_GENERATION_RULES);\r
+                               List<GenerationRule> rules = priRules.getValues(stage);\r
+                               for (GenerationRule r : rules) {\r
+                                       r.generate(graph, n);\r
+                               }\r
+\r
+                               monitor.subTask("Generating objects, stage " + stage + " :  ("+ (++count) + "/" + size + ")");\r
+                               if(monitor.isCanceled()) {\r
+                                       throw new CancelException("Cancel requested.");\r
+                               }\r
+                               if (COLLECT_WITHIN_TRANSACTIONS)\r
+                                       collect2(graph);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       private void applyConnections(WriteGraph g, Collection<GraphNode<Identifiable>> nodes, IProgressMonitor monitor) throws Exception {\r
+               int size = nodes.size();\r
+               int count = 0;\r
+               \r
+               monitor.subTask("Generating connections ("+ count + "/" + size + ")");\r
+               \r
+               for (GraphNode<Identifiable> node : nodes) {\r
+                       applyConnections(g, node);\r
+                       monitor.subTask("Generating connections ("+ (++count) + "/" + size + ")");\r
+                       if(monitor.isCanceled()) {\r
+                               throw new CancelException("Cancel requested.");\r
+                       }\r
+                       if (COLLECT_WITHIN_TRANSACTIONS)\r
+                               collect2(g);\r
+               }\r
+       }\r
+       \r
+       \r
+       \r
+       protected String getName(ReadGraph g, Identifiable res) throws DatabaseException {\r
+               if (res instanceof ResourceIdentifiable)\r
+                       return NameUtils.getSafeName(g, ((ResourceIdentifiable)res).getResource());\r
+               else\r
+                       return res.toString();\r
+       }\r
+       \r
+       public class WriteWrapper extends WriteGraphProxy {\r
+               \r
+               \r
+               private Collection<Resource> createdResources = new ArrayList<Resource>();\r
+               \r
+               public WriteWrapper(WriteGraph graph) {\r
+                       super(graph);\r
+               }\r
+               \r
+               public Collection<Resource> getCreatedResources() {\r
+                       return createdResources;\r
+               }\r
+               \r
+               public void clearCreated() {\r
+                       createdResources = new ArrayList<Resource>();\r
+               }\r
+               \r
+               @Override\r
+               public Resource newResource() throws ServiceException {\r
+                       Resource res = graph.newResource();\r
+                       createdResources.add(res);\r
+                       return res;\r
+               }\r
+               \r
+               @Override\r
+               public Resource newResource(long clusterId) throws ServiceException {\r
+                       Resource res = graph.newResource(clusterId);\r
+                       createdResources.add(res);\r
+                       return res;\r
+               }\r
+               \r
+               \r
+       }\r
+       \r
+       private void initializeRules(Session session, VirtualGraph vg, final Resource model ) throws DatabaseException{\r
+               session.syncRequest(new WriteRequest(vg) {\r
+                       @Override\r
+                       public void perform(WriteGraph g) throws DatabaseException {\r
+                               for (InitializedRule rule : initializedRules)\r
+                                       rule.initialize(g, model);\r
+                               \r
+                       }\r
+               });\r
+               \r
+       }\r
+               \r
+       private void collect(ReadGraph g) throws DatabaseException {\r
+               if (vg != null)\r
+                       return;\r
+               SessionGarbageCollection.gc(g, 0, -1);\r
+       }\r
+       \r
+       int collect = 0;\r
+       \r
+       private void collect2(ReadGraph g) throws DatabaseException {\r
+               if (vg != null)\r
+                       return;\r
+               \r
+               if (collect == OBJECTS_BEFORE_COLLECT) {\r
+                       SessionGarbageCollection.gc(g, 0, -1);\r
+                       collect = 0;\r
+               } else {\r
+                       collect++;\r
+               }\r
+       }\r
+       \r
+       private void applyModifications(Session session, final Collection<GraphNode<Identifiable>> nodes, final IProgressMonitor monitor) throws Exception {\r
+               \r
+               \r
+               \r
+               int passCount = Math.max(globalModificationRules.size(),modificationRules.size());\r
+               \r
+               for (int pass = 0; pass <passCount; pass++) {\r
+                       // Apply global modification rules first\r
+                       if (globalModificationRules.size() > pass) {\r
+                               int count = 0;\r
+                               List<ModificationRule> modRules = globalModificationRules.get(pass);\r
+                               int size = modRules.size();\r
+                               monitor.subTask("Running global modification rules: pass (" + (pass+1) + "/" + passCount + "), rule ("+ (++count) + "/" + size + ")");\r
+                               for (final ModificationRule r : modRules) {\r
+                                       session.syncRequest(new ReadRequest() {\r
+                                               \r
+                                               @Override\r
+                                               public void run(ReadGraph g) throws DatabaseException {\r
+                                                       try {\r
+                                                               Collection<GraphNode<Identifiable>> ruleModified = r.modify(g, nodes);\r
+                                                               \r
+                                                               if (ruleModified == null)\r
+                                                                       return;\r
+                                                               for (GraphNode<Identifiable> m : ruleModified) {\r
+                                                                       if (m.isDisposed()) {\r
+                                                                               nodes.remove(m);\r
+                                                                       }\r
+                                                                       else if (!nodes.contains(m)) {\r
+                                                                               nodes.add(m);\r
+                                                                       }\r
+                                                               }\r
+                                                               if (COLLECT_WITHIN_TRANSACTIONS)\r
+                                                                       collect(g);\r
+                                                       } catch (Exception e) {\r
+                                                               throw new DatabaseException(e);\r
+                                                       }\r
+                                                       \r
+                                               }\r
+                                       });\r
+                                       //SessionGarbageCollection.gc(null, session, true, null);\r
+                                       monitor.subTask("Running global modification rules: pass (" + (pass+1) + "/" + passCount + "), rule ("+ (++count) + "/" + size + ")");\r
+                                       if(monitor.isCanceled()) {\r
+                                               throw new CancelException("Cancel requested.");\r
+                                       }\r
+                               }\r
+                       }\r
+                       if (modificationRules.size() > pass) {\r
+                               int count = 0;\r
+                               List<Pair<IdentificationRule, ModificationRule>> modRules = modificationRules.get(pass);\r
+                               int size = modRules.size();\r
+                               monitor.subTask("Running object modification rules: pass (" + (pass+1) + "/" + passCount + "), rule ("+ (++count) + "/" + size + ")");\r
+                               \r
+                               // Apply per object modification rules \r
+                               for (final Pair<IdentificationRule, ModificationRule> modRule : modRules) {\r
+                                       final Iterator<GraphNode<Identifiable>> iter = nodes.iterator();\r
+                                       final Collection<GraphNode<Identifiable>> ruleModified = new ArrayList<GraphNode<Identifiable>>();\r
+                                       while (iter.hasNext()) {\r
+                                               session.syncRequest(new ReadRequest() {\r
+                                                       \r
+                                                       @Override\r
+                                                       public void run(ReadGraph g) throws DatabaseException {\r
+                                                               try {\r
+                                                                       \r
+                                                                       int j = 0; \r
+                                                                       //for (GraphNode<Identifiable> n : nodes) {\r
+                                                                       while (iter.hasNext() && j < OBJECTS_PER_TRANSACTION) {\r
+                                                                               GraphNode<Identifiable> n = iter.next();\r
+                                                                               applyModifications(g, n, modRule, ruleModified);\r
+                                                                               j++;\r
+                                                                       }\r
+                                                                       if (COLLECT_WITHIN_TRANSACTIONS)\r
+                                                                               collect(g);\r
+                                                                       \r
+                                                               } catch (Exception e) {\r
+                                                                       throw new DatabaseException(e);\r
+                                                               }\r
+                                                               \r
+                                                       }\r
+                                               });\r
+                                       }\r
+                                       for (GraphNode<Identifiable> m : ruleModified) {\r
+                                               if (m.isDisposed()) {\r
+                                                       nodes.remove(m);\r
+                                               }\r
+                                               else if (!nodes.contains(m)) {\r
+                                                       nodes.add(m);\r
+                                               }\r
+                                       }\r
+                                       ruleModified.clear();\r
+                                       \r
+                                       //SessionGarbageCollection.gc(null, session, true, null);\r
+                                       monitor.subTask("Running object modification rules: pass (" + (pass+1) + "/" + passCount + "), rule ("+ (++count) + "/" + size + ")");\r
+                                       if(monitor.isCanceled()) {\r
+                                               throw new CancelException("Cancel requested.");\r
+                                       }\r
+                               }\r
+                       }       \r
+               }\r
+               \r
+       }\r
+       \r
+       private void applyModifications2(Session session, final Collection<GraphNode<Identifiable>> nodes, final IProgressMonitor monitor) throws Exception {\r
+               session.syncRequest(new ReadRequest() {\r
+                       \r
+                       @Override\r
+                       public void run(ReadGraph g) throws DatabaseException {\r
+                               try {\r
+                                       applyModifications(g, nodes, monitor);\r
+                               } catch (Exception e) {\r
+                                       throw new DatabaseException(e);\r
+                               }\r
+                               \r
+                       }\r
+               });\r
+       }\r
+       \r
+       private void applyGenerations(Session session, VirtualGraph vg, Collection<GraphNode<Identifiable>> nodes, IProgressMonitor monitor) throws Exception {\r
+               \r
+               int size = nodes.size();\r
+               int count = 0;\r
+               monitor.subTask("Assigning generation rules ("+ count + "/" + size + ")");\r
+               // populate generation rules\r
+\r
+               {\r
+                       final Iterator<GraphNode<Identifiable>> iter = nodes.iterator();\r
+                       while (iter.hasNext()) {\r
+                               int c = session.syncRequest(new Read<Integer>() {\r
+                                       \r
+                                       @Override\r
+                                       public Integer perform(ReadGraph graph)\r
+                                                       throws DatabaseException {\r
+                                               int j = 0;\r
+                                               while (iter.hasNext() && j < OBJECTS_PER_TRANSACTION) {\r
+                                                       GraphNode<Identifiable> n = iter.next();\r
+                                                       for (Pair<IdentificationRule,Pair<Integer,GenerationRule>> r : generationRules) {\r
+                                                               if (r.first.matches(graph, n)) {\r
+                                                                       MapList<Integer,GenerationRule> rules = n.getHint(MappingHints.KEY_GENERATION_RULES);\r
+                                                                       if (rules == null) {\r
+                                                                               rules = new MapList<Integer,GenerationRule>();  \r
+                                                                       }\r
+                                                                       rules.add(r.second.first,r.second.second);\r
+                                                                       n.setHint(MappingHints.KEY_GENERATION_RULES, rules);\r
+                                                               }\r
+                                                       }\r
+                                                       j++;\r
+                                               }\r
+                                               if (COLLECT_WITHIN_TRANSACTIONS)\r
+                                                       collect(graph);\r
+                                               return j;\r
+                                               \r
+                                       }\r
+                               });\r
+                               collect(session);\r
+                               monitor.subTask("Assigning generation rules ("+ (count+=c) + "/" + size + ")");\r
+                               if(monitor.isCanceled()) {\r
+                                       throw new CancelException("Cancel requested.");\r
+                               }\r
+                               sleep();\r
+                       }\r
+               }\r
+               \r
+               count = 0;\r
+               monitor.subTask("Generating objects ("+ (count) + "/" + size + ")");\r
+               \r
+               // apply generation rules.\r
+               \r
+               {\r
+                       for (int stage = 0; stage <= maxGenPass; stage++) {\r
+                               final int fStage = stage;\r
+                               count = 0;\r
+                               final Iterator<GraphNode<Identifiable>> iter = nodes.iterator();\r
+                               while (iter.hasNext()) {\r
+                                       int c = session.syncRequest(new WriteResultRequest<Integer>(vg) {\r
+                                               \r
+                                               @Override\r
+                                               public Integer perform(WriteGraph graph) throws DatabaseException {\r
+                                                       int j = 0;\r
+                                                       try {\r
+                                                               while (iter.hasNext() && j < OBJECTS_PER_TRANSACTION) {\r
+                                                                       GraphNode<Identifiable> n = iter.next();\r
+                                                                       \r
+                                                                       MapList<Integer,GenerationRule> priRules = n.getHint(MappingHints.KEY_GENERATION_RULES);\r
+                                                                       if (priRules == null) {\r
+                                                                               j++;\r
+                                                                               continue;\r
+                                                                       }\r
+                                                                       final List<GenerationRule> rules = priRules.getValues(fStage);\r
+                                                                       \r
+                                                                       if (fStage == 0 && rules.size() == 0)\r
+                                                                               System.out.println();\r
+                                                                       for (GenerationRule r : rules) {\r
+                                                                               r.generate(graph, n);\r
+\r
+                                                                       }\r
+\r
+                                                                               \r
+                                                                       j++;\r
+                                                                       \r
+                                                               }\r
+                                                               if (COLLECT_WITHIN_TRANSACTIONS)\r
+                                                                       collect(graph);\r
+                                                               return j;\r
+                                                       \r
+                                               } catch (Exception e) {\r
+                                                       throw new DatabaseException(e);\r
+                                               }\r
+                                       }});\r
+                                       collect(session);\r
+                                       monitor.subTask("Generating objects, stage " + stage + " :  ("+ (count+=c) + "/" + size + ")");\r
+                                       if(monitor.isCanceled()) {\r
+                                               throw new CancelException("Cancel requested.");\r
+                                       }\r
+                                       sleep();\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       \r
+       private void applyGenerations2(Session session, VirtualGraph vg, final Collection<GraphNode<Identifiable>> nodes, final IProgressMonitor monitor) throws Exception {\r
+               session.syncRequest(new WriteRequest(vg) {\r
+                       \r
+                       @Override\r
+                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                               try {\r
+                                       applyGenerations(graph, nodes, monitor);\r
+                               } catch (Exception e) {\r
+                                       throw new DatabaseException(e);\r
+                               }\r
+                               \r
+                       }\r
+               });\r
+       }\r
+       \r
+       private void collect(Session session) {\r
+               if (COLLECT_BETWEEN_WRITES)\r
+                       SessionGarbageCollection.gc(null, session, true, null);\r
+       }\r
+       \r
+       \r
+       private void sleep() {\r
+               if (SLEEP_BETWEEN_WRITES) {\r
+                       try {\r
+                               Thread.sleep(SLEEP_TIME);\r
+                       } catch (InterruptedException e) {\r
+                               \r
+                       }\r
+               }\r
+       }\r
+       \r
+       private void applyConnections(Session session, VirtualGraph vg, Collection<GraphNode<Identifiable>> nodes, IProgressMonitor monitor) throws Exception {\r
+               int size = nodes.size();\r
+               int count = 0;\r
+               \r
+               monitor.subTask("Generating connections ("+ count + "/" + size + ")");\r
+               \r
+               final Iterator<GraphNode<Identifiable>> iter = nodes.iterator();\r
+               while (iter.hasNext()) {\r
+                       int c = session.syncRequest(new WriteResultRequest<Integer>(vg) {\r
+                               \r
+                               @Override\r
+                               public Integer perform(WriteGraph g) throws DatabaseException {\r
+                                       int j = 0;\r
+                                       try {\r
+                                               while (iter.hasNext() && j < OBJECTS_PER_TRANSACTION) {\r
+                                                       GraphNode<Identifiable> node = iter.next();\r
+                                                       applyConnections(g, node);\r
+                                                       j++;\r
+                                               }\r
+                                               if (COLLECT_WITHIN_TRANSACTIONS)\r
+                                                       collect(g);\r
+                                               return j;\r
+                                               \r
+                                       } catch (Exception e) {\r
+                                               throw new DatabaseException(e);\r
+                                       }       \r
+                               }       \r
+                       });\r
+                       collect(session);\r
+                       monitor.subTask("Generating connections ("+ (count+=c) + "/" + size + ")");\r
+                       if(monitor.isCanceled()) {\r
+                               throw new CancelException("Cancel requested.");\r
+                       }\r
+                       sleep();\r
+               }\r
+       }\r
+       \r
+       private void applyConnections2(Session session, VirtualGraph vg, final Collection<GraphNode<Identifiable>> nodes, final IProgressMonitor monitor) throws Exception {\r
+               session.syncRequest(new WriteRequest(vg) {\r
+                       \r
+                       @Override\r
+                       public void perform(WriteGraph graph) throws DatabaseException {\r
+                               try {\r
+                                       applyConnections(graph, nodes, monitor);\r
+                               } catch (Exception e) {\r
+                                       throw new DatabaseException(e);\r
+                               }\r
+                               \r
+                       }\r
+               });\r
+       }\r
+\r
+       private void applyModifications(ReadGraph g, GraphNode<Identifiable> n, Pair<IdentificationRule, ModificationRule> modRule, Collection<GraphNode<Identifiable>> ruleModified) throws Exception {\r
+               if (!n.isDisposed() && modRule.first.matches(g, n)) { // we have to check \r
+                       Collection<GraphNode<Identifiable>> perRule = new ArrayList<GraphNode<Identifiable>>();\r
+                       perRule.add(n);\r
+                       ruleModified.addAll(modRule.second.modify(g, perRule));\r
+               }\r
+       }\r
+       \r
+       private void applyConnections(WriteGraph g, GraphNode<Identifiable> node) throws Exception {\r
+               for (Link<Identifiable> link : node.getLinks()) {\r
+                       if (link.isMain()) {\r
+                               \r
+                               for (Pair<ConnectionIdentificationRule, ConnectionGenerationRule> r : connectionRules) {\r
+                                       if (r.first.mathces(g, node, link.to(), link)) {\r
+                                               Logger.defaultLogInfo("Connecting " +  getName(g, node.getData()) + " to " + getName(g, link.to().getData()) + " " + link.getName() + "/"+link.getInverseName());\r
+                                               r.second.generate(g, node, link.to(), link);\r
+                                               break;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingHints.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingHints.java
new file mode 100644 (file)
index 0000000..b33965a
--- /dev/null
@@ -0,0 +1,48 @@
+package org.simantics.interop.mapping;\r
+\r
+import java.awt.geom.Point2D;\r
+import java.util.Collection;\r
+import java.util.Map;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.interop.mapping.data.GraphNode;\r
+import org.simantics.utils.datastructures.MapList;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+\r
+public class MappingHints {\r
+\r
+       // type of symbol to be created.\r
+       public static final Key KEY_GENERATE_TYPE = new KeyOf(Resource.class); \r
+       \r
+       // Module Resolver (symbol  type and terminals)\r
+       public static final Key KEY_RESOLVER = new KeyOf(ModuleResolver.class); \r
+       \r
+       // generated symbol.\r
+       //public static final Key KEY_GENERATED_SYMBOL = new KeyOf(Symbol.class); \r
+       \r
+       public static final Key KEY_GENERATION_RULES = new KeyOf(MapList.class); // Generation Rules <Integer,GenerationRule>\r
+       \r
+       //public static final Key KEY_DIAGRAM = new KeyOf(Diagram.class);             // Diagram where node's symbol(s) are generated.\r
+       public static final Key KEY_PATH_DIAGRAM = new KeyOf(Map.class);             // Diagram where node's symbol(s) by path are generated. <String,Diagram>\r
+       public static final Key KEY_PARENT_NODE = new KeyOf(GraphNode.class); // Parent Node (device) used with automation symbols. <Identifiable>\r
+       public static final Key KEY_CHILD_NODE = new KeyOf(Collection.class); // Child Node (device). <GraphNode<Identifiable>>\r
+       \r
+       public static final Key KEY_CONNECTION_TERMINAL = new KeyOf(Resource.class); // Connection terminal (in Apros symbol) \r
+       \r
+       public static final Key KEY_CONNECTION_TYPE = new KeyOf(String.class); // Connection Type\r
+       public static final Key KEY_CONNECTION_LABEL = new KeyOf(String.class);\r
+       public static final Key KEY_CONNECTION_NOT = new KeyOf(Boolean.class); // Is inverse (Binary signal)\r
+       \r
+       \r
+       public static final Key KEY_FLAG_POSITION = new KeyOf(Point2D.class);\r
+       public static final Key KEY_FLAG_NAME = new KeyOf(String.class);\r
+       \r
+       \r
+       public static final Key KEY_SPLIT_NAME = new KeyOf(String.class);\r
+       public static final Key KEY_SPLIT_COUNT = new KeyOf(Integer.class);\r
+       public static final Key KEY_SPLIT_PERCENTAGE = new KeyOf(Double.class);\r
+       \r
+       \r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingRule.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingRule.java
new file mode 100644 (file)
index 0000000..ae7e51c
--- /dev/null
@@ -0,0 +1,5 @@
+package org.simantics.interop.mapping;\r
+\r
+public interface MappingRule {\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingTools.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/MappingTools.java
new file mode 100644 (file)
index 0000000..03ea947
--- /dev/null
@@ -0,0 +1,118 @@
+package org.simantics.interop.mapping;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.interop.mapping.data.GraphNode;\r
+import org.simantics.interop.mapping.data.Identifiable;\r
+import org.simantics.interop.mapping.data.Link;\r
+import org.simantics.utils.datastructures.MapList;\r
+\r
+public class MappingTools {\r
+\r
+       public static Resource getSymbolType(ReadGraph g, GraphNode<Identifiable> node) throws DatabaseException {\r
+               Resource type = node.getHint(MappingHints.KEY_GENERATE_TYPE);\r
+               if (type == null) {\r
+                       ModuleResolver resolver = node.getHint(MappingHints.KEY_RESOLVER);\r
+                       if (resolver != null)\r
+                               type = resolver.getSymbolType(g);\r
+                       \r
+               }\r
+               return type;\r
+       }\r
+       \r
+       public static Resource getTerminal(ReadGraph g, Link<Identifiable> link) throws DatabaseException {\r
+               Resource terminal = link.getHint(MappingHints.KEY_CONNECTION_TERMINAL);\r
+               if (terminal == null) {\r
+                       ModuleResolver resolver = link.from().getHint(MappingHints.KEY_RESOLVER);\r
+                       if (resolver != null)\r
+                               terminal = resolver.getTerminal(g, link);\r
+                       \r
+               }\r
+               return terminal;\r
+       }\r
+       \r
+       public static void assignGenerationRule(GraphNode<Identifiable> node, int index, GenerationRule rule) {\r
+               MapList<Integer,GenerationRule> rules = node.getHint(MappingHints.KEY_GENERATION_RULES);\r
+               if (rules == null) {\r
+                       rules = new MapList<Integer,GenerationRule>();\r
+                       node.setHint(MappingHints.KEY_GENERATION_RULES, rules);\r
+               }\r
+               rules.add(index,rule);\r
+               \r
+       }\r
+       \r
+       public static void createEmptyGenerationRules(GraphNode<Identifiable> node) {\r
+               node.setHint(MappingHints.KEY_GENERATION_RULES, new MapList<Integer,GenerationRule>());\r
+       }\r
+       \r
+       public static void copyGenerationRules(GraphNode<Identifiable> from, GraphNode<Identifiable> to) {\r
+               MapList<Integer,GenerationRule> rules = from.getHint(MappingHints.KEY_GENERATION_RULES);\r
+               if (rules == null)\r
+                       return;\r
+               MapList<Integer,GenerationRule> toRules = to.getHint(MappingHints.KEY_GENERATION_RULES);\r
+               if (toRules == null) {\r
+                       toRules = new MapList<Integer,GenerationRule>();\r
+                       to.setHint(MappingHints.KEY_GENERATION_RULES, toRules);\r
+               }\r
+               for (Integer i : rules.getKeys()) {\r
+                       for (GenerationRule r : rules.getValues(i))\r
+                               toRules.add(i,r);\r
+               }\r
+       }\r
+       \r
+       public static void copyHints(GraphNode<Identifiable> from, GraphNode<Identifiable> to) {\r
+               to.setHints(from.getHints());\r
+               createEmptyGenerationRules(to);\r
+               copyGenerationRules(from, to);\r
+               reconnectParent(from, to);\r
+       }\r
+       \r
+       public static void copyDefaultHints(GraphNode<Identifiable> from, GraphNode<Identifiable> to) {\r
+               to.setHints(from.getHints());\r
+               createEmptyGenerationRules(to);\r
+               reconnectParent(from, to);\r
+       }\r
+       \r
+       private static void reconnectParent(GraphNode<Identifiable> from, GraphNode<Identifiable> to) {\r
+               GraphNode<Identifiable> parent = from.getHint(MappingHints.KEY_PARENT_NODE);\r
+               if (parent != null) {\r
+                       setParentNode(parent, to);\r
+                       \r
+               }\r
+       }\r
+       \r
+//     public static boolean hasModuleTypeAssigned(GraphNode<Identifiable> node) {\r
+//             return  (node.containsHint(MappingHints.KEY_RESOLVER) || node.containsHint(MappingHints.KEY_GENERATE_TYPE) || node.containsHint(MappingHints.KEY_GENERATED_SYMBOL));\r
+//     }\r
+       \r
+       public static <T> void disposeNodes(Collection<GraphNode<T>> nodes) {\r
+               for (GraphNode<T> node : nodes) {\r
+                       node.destroy();\r
+               }\r
+               nodes.clear();\r
+       }\r
+       \r
+       public static void setParentNode(GraphNode<?> parent, GraphNode<?> child) {\r
+               child.setHint(MappingHints.KEY_PARENT_NODE, parent);\r
+               Collection<GraphNode<?>> children = parent.getHint(MappingHints.KEY_CHILD_NODE);\r
+               if (children == null) {\r
+                       children = new ArrayList<GraphNode<?>>();\r
+                       parent.setHint(MappingHints.KEY_CHILD_NODE, children);\r
+               }\r
+               children.add(child);\r
+       }\r
+       \r
+       public static void unsetParentNode(GraphNode<?> child) {\r
+               GraphNode<Identifiable> parent = child.getHint(MappingHints.KEY_PARENT_NODE);\r
+               if (parent == null)\r
+                       return;\r
+               \r
+               Collection<GraphNode<?>> children = parent.getHint(MappingHints.KEY_CHILD_NODE);\r
+               children.remove(child);\r
+               child.removeHint(MappingHints.KEY_PARENT_NODE);\r
+       }\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/ModificationRule.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/ModificationRule.java
new file mode 100644 (file)
index 0000000..ab88265
--- /dev/null
@@ -0,0 +1,13 @@
+package org.simantics.interop.mapping;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.interop.mapping.data.GraphNode;\r
+import org.simantics.interop.mapping.data.Identifiable;\r
+\r
+public interface ModificationRule extends MappingRule{\r
+       \r
+       Collection<GraphNode<Identifiable>> modify(ReadGraph g, Collection<GraphNode<Identifiable>> nodes)  throws Exception;\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/ModuleResolver.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/ModuleResolver.java
new file mode 100644 (file)
index 0000000..f5b483b
--- /dev/null
@@ -0,0 +1,15 @@
+package org.simantics.interop.mapping;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.interop.mapping.data.Identifiable;\r
+import org.simantics.interop.mapping.data.Link;\r
+\r
+public interface ModuleResolver {\r
+       \r
+       public Resource getSymbolType(ReadGraph g) throws DatabaseException;\r
+       \r
+       public Resource getTerminal(ReadGraph g, Link<Identifiable> link) throws DatabaseException;\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/SplittingWriteGraph.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/SplittingWriteGraph.java
new file mode 100644 (file)
index 0000000..fb73ebd
--- /dev/null
@@ -0,0 +1,6167 @@
+package org.simantics.interop.mapping;\r
+\r
+import java.util.Collection;\r
+import java.util.Set;\r
+import java.util.TreeMap;\r
+\r
+import org.simantics.databoard.accessor.Accessor;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.type.Datatype;\r
+import org.simantics.databoard.util.binary.RandomAccessBinary;\r
+import org.simantics.db.Metadata;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
+import org.simantics.db.common.request.WriteResultRequest;\r
+import org.simantics.db.exception.AdaptionException;\r
+import org.simantics.db.exception.AssumptionException;\r
+import org.simantics.db.exception.BindingException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.DoesNotContainValueException;\r
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
+import org.simantics.db.exception.NoInverseException;\r
+import org.simantics.db.exception.NoSingleResultException;\r
+import org.simantics.db.exception.ResourceNotFoundException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.exception.ServiceNotFoundException;\r
+import org.simantics.db.exception.ValidationException;\r
+import org.simantics.db.procedure.AsyncListener;\r
+import org.simantics.db.procedure.AsyncMultiListener;\r
+import org.simantics.db.procedure.AsyncMultiProcedure;\r
+import org.simantics.db.procedure.AsyncProcedure;\r
+import org.simantics.db.procedure.AsyncSetListener;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.procedure.MultiListener;\r
+import org.simantics.db.procedure.MultiProcedure;\r
+import org.simantics.db.procedure.Procedure;\r
+import org.simantics.db.procedure.SetListener;\r
+import org.simantics.db.procedure.SyncListener;\r
+import org.simantics.db.procedure.SyncMultiListener;\r
+import org.simantics.db.procedure.SyncMultiProcedure;\r
+import org.simantics.db.procedure.SyncProcedure;\r
+import org.simantics.db.procedure.SyncSetListener;\r
+import org.simantics.db.request.AsyncMultiRead;\r
+import org.simantics.db.request.AsyncRead;\r
+import org.simantics.db.request.DelayedWrite;\r
+import org.simantics.db.request.DelayedWriteResult;\r
+import org.simantics.db.request.ExternalRead;\r
+import org.simantics.db.request.MultiRead;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.db.request.ReadInterface;\r
+import org.simantics.db.request.Write;\r
+import org.simantics.db.request.WriteInterface;\r
+import org.simantics.db.request.WriteOnly;\r
+import org.simantics.db.request.WriteOnlyResult;\r
+import org.simantics.db.request.WriteResult;\r
+import org.simantics.db.request.WriteTraits;\r
+import org.simantics.scl.types.Type;\r
+import org.simantics.utils.datastructures.Callback;\r
+\r
+/**\r
+ * This is insane.\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class SplittingWriteGraph implements WriteGraph {\r
+       \r
+       protected Session session;\r
+       \r
+       \r
+       @Override\r
+       public <T> T getRelatedValue2(final Resource subject, final Resource relation)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(new Read<T>() {\r
+                       @Override\r
+                       public T perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getRelatedValue2(subject, relation);\r
+                       }\r
+               });\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public <T> T getRelatedValue2(final Resource subject, final Resource relation, final Binding binding) throws DatabaseException {\r
+               return session.syncRequest(new Read<T>() {\r
+                       @Override\r
+                       public T perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getRelatedValue2(subject, relation, binding);\r
+                       }\r
+               });\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getRelatedValue2(final Resource subject, final Resource relation, final Object context) throws DatabaseException {\r
+               return session.syncRequest(new Read<T>() {\r
+                       @Override\r
+                       public T perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getRelatedValue2(subject, relation, context);\r
+                       }\r
+               });\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getRelatedValue2(final Resource subject, final Resource relation, final Object context, final Binding binding) throws DatabaseException {\r
+               return session.syncRequest(new Read<T>() {\r
+                       @Override\r
+                       public T perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getRelatedValue2(subject, relation, context, binding);\r
+                       }\r
+               });\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedValue2(final Resource subject, final Resource relation)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(new Read<T>() {\r
+                       @Override\r
+                       public T perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getPossibleRelatedValue2(subject, relation);\r
+                       }\r
+               });\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedValue2(final Resource subject, final Resource relation, final Binding binding) throws DatabaseException {\r
+               return session.syncRequest(new Read<T>() {\r
+                       @Override\r
+                       public T perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getPossibleRelatedValue2(subject, relation, binding);\r
+                       }\r
+               });\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedValue2(final Resource subject, final Resource relation, final Object context) throws DatabaseException {\r
+               return session.syncRequest(new Read<T>() {\r
+                       @Override\r
+                       public T perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getPossibleRelatedValue2(subject, relation, context);\r
+                       }\r
+               });\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedValue2(final Resource subject, final Resource relation, final Object context, final Binding binding) throws DatabaseException {\r
+               return session.syncRequest(new Read<T>() {\r
+                       @Override\r
+                       public T perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getPossibleRelatedValue2(subject, relation, context, binding);\r
+                       }\r
+               });\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(final ReadInterface<T> r, final AsyncListener<T> procedure) {\r
+               session.async(r, procedure);\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(final ReadInterface<T> r, final AsyncProcedure<T> procedure) {\r
+               session.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(final ReadInterface<T> r, final Listener<T> procedure) {\r
+               session.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(final ReadInterface<T> r, final Procedure<T> procedure) {\r
+               session.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(final ReadInterface<T> r, final SyncListener<T> procedure) {\r
+               session.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(final ReadInterface<T> r, final SyncProcedure<T> procedure) {\r
+               session.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(final WriteInterface<T> r) {\r
+               session.async(r);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(final WriteInterface<T> r, final Procedure<T> procedure) {\r
+               session.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T sync(final ReadInterface<T> r) throws DatabaseException {\r
+               return session.sync(r);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T sync(final WriteInterface<T> r) throws DatabaseException {\r
+               return session.sync(r);\r
+       }\r
+       \r
+       @Override\r
+       public Resource getRootLibrary() {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getRootLibrary();\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       return null;\r
+               }\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public void clearUndoList(final WriteTraits writeTraits) {\r
+               throw new RuntimeException("Not supported.");\r
+       }\r
+       \r
+       @Override\r
+       public void combineWithPrevious(WriteTraits writeTraits) {\r
+               throw new RuntimeException("Not supported.");\r
+       }\r
+       \r
+       @Override\r
+       public TreeMap<String, byte[]> getMetadata() {\r
+               try {\r
+                       return session.syncRequest(new WriteResultRequest<TreeMap<String, byte[]>>() {\r
+                               \r
+                               @Override\r
+                               public TreeMap<String, byte[]> perform(WriteGraph graph) throws DatabaseException {\r
+                                       return graph.getMetadata();\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       return null;\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T extends Metadata> T getMetadata(final Class<T> clazz)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new WriteResultRequest<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(WriteGraph graph) throws DatabaseException {\r
+                                       return graph.getMetadata(clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public Type getRelatedValueType(final Resource subject, final Resource relation)\r
+                       throws DatabaseException {\r
+\r
+               return session.syncRequest(new Read<Type>() {\r
+                       \r
+                       @Override\r
+                       public Type perform(ReadGraph graph) throws DatabaseException {\r
+                               return graph.getRelatedValueType(subject, relation);\r
+                       }\r
+               });\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void deny(final Resource subject, final Resource predicate, final Resource inverse, final Resource object, final VirtualGraph vgraph) throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.deny(subject, predicate, inverse, object, vgraph);\r
+                                       \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       \r
+       \r
+       \r
+       @Override\r
+       public <T> T adaptRelated(final Resource resource, final Resource relation,\r
+                       final Class<T> clazz) throws AdaptionException, NoSingleResultException,\r
+                       ValidationException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.adaptRelated(resource, relation, clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedAdapter(final Resource resource,\r
+                       final Resource relation, final Class<T> clazz) throws ValidationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getPossibleRelatedAdapter(resource, relation, clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ValidationException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void inc() {\r
+               throw new RuntimeException("Not supported.");\r
+       }\r
+       \r
+       @Override\r
+       public void dec() {\r
+               throw new RuntimeException("Not supported.");\r
+       }\r
+       \r
+       @Override\r
+       public Collection<Resource> getObjects(final Resource subject, final Resource relation) throws ServiceException \r
+                       {\r
+               try {\r
+                       return session.syncRequest(new Read<Collection<Resource>>() {\r
+                               \r
+                               @Override\r
+                               public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getObjects(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public <T extends Accessor> T newLiteral(final Resource resource,\r
+       final Resource predicate, final Datatype datatype, final Object initialValue)\r
+       throws DatabaseException {\r
+               return session.syncRequest(new WriteResultRequest<T>() {\r
+                       \r
+                       @Override\r
+                       public T perform(WriteGraph graph) throws DatabaseException {\r
+                               return graph.newLiteral(resource, predicate, datatype, initialValue);\r
+                       }\r
+               });\r
+       }\r
+\r
+    @Override\r
+    public RandomAccessBinary newLiteral4RandomAccessBinary\r
+    (final Resource resource, final Resource predicate, final Datatype datatype, final Object initialvalue)\r
+    throws DatabaseException {\r
+        return session.syncRequest(new WriteResultRequest<RandomAccessBinary>() {\r
+            @Override\r
+            public RandomAccessBinary perform(WriteGraph graph) throws DatabaseException {\r
+                return graph.newLiteral4RandomAccessBinary(resource, predicate, datatype, initialvalue);\r
+            }\r
+        });\r
+    }\r
+\r
+       public <T, C> T adaptContextual(final Resource resource, final  C context, final java.lang.Class<C> contextClass, final java.lang.Class<T> clazz) throws AdaptionException ,NoSingleResultException ,ValidationException ,ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.adaptContextual(resource, context, contextClass, clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       };\r
+       \r
+       public <T, C> T getPossibleContextualAdapter(final Resource resource, final C context, final java.lang.Class<C> contextClass, final java.lang.Class<T> clazz) throws ValidationException ,ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getPossibleContextualAdapter(resource, context, contextClass, clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       };\r
+       \r
+       \r
+       public SplittingWriteGraph(Session session) {\r
+               this.session = session;\r
+       }\r
+       \r
+       @Override\r
+       public Resource newResource() throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new WriteResultRequest<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(WriteGraph graph) throws DatabaseException {\r
+                                       return graph.newResource();\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+                \r
+       }\r
+       \r
+       @Override\r
+       public Resource newResource(final long clusterId) throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new WriteResultRequest<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(WriteGraph graph) throws DatabaseException {\r
+                                       return graph.newResource(clusterId);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T> T adapt(final Resource resource, final Class<T> clazz)\r
+                       throws AdaptionException, ValidationException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.adapt(resource, clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T> T adaptUnique(final Resource resource, final Class<T> clazz)\r
+                       throws AdaptionException, ValidationException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.adaptUnique(resource, clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void addLiteral(final Resource resource, final Resource predicate,\r
+                       final Resource inverse, final Object value, final Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.addLiteral(resource, predicate, inverse, value, binding);\r
+                                       \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void addLiteral(final Resource resource, final Resource predicate,\r
+                       final Resource inverse, final Resource type, final Object value, final Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.addLiteral(resource, predicate, inverse, type, value, binding);\r
+                                       \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T> void addMetadata(Metadata data) throws ServiceException {\r
+               throw new RuntimeException("Not supported.");\r
+       }\r
+       \r
+       @Override\r
+       @Deprecated\r
+       public void addValue(final Resource resource, final Resource predicate,\r
+                       final Resource inverse, final Resource type, final Object value, final Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.addValue(resource, predicate, inverse, type, value, binding);\r
+                                       \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(final AsyncMultiRead<T> request) {\r
+               session.asyncRequest(request);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       AsyncMultiListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       AsyncMultiProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       MultiListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       MultiProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       SyncMultiListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       SyncMultiProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request) {\r
+               session.asyncRequest(request);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       AsyncListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       AsyncProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request, Listener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       Procedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       SyncListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       SyncProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(DelayedWrite request) {\r
+               session.asyncRequest(request);  \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(DelayedWrite request,\r
+                       Callback<DatabaseException> callback) {\r
+               session.asyncRequest(request,callback); \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(DelayedWriteResult<T> r,\r
+                       Procedure<T> procedure) {\r
+               session.asyncRequest(r,procedure);      \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(ExternalRead<T> request) {\r
+               session.asyncRequest(request);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(ExternalRead<T> request,\r
+                       Listener<T> procedure) {\r
+               session.asyncRequest(request,procedure);\r
+       }       \r
+       \r
+       @Override\r
+       public <T> void asyncRequest(ExternalRead<T> request,\r
+                       Procedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request) {\r
+               session.asyncRequest(request);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       AsyncMultiListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       AsyncMultiProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       MultiListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       MultiProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       SyncMultiListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       SyncMultiProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request) {\r
+               session.asyncRequest(request);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, AsyncListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request,\r
+                       AsyncProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, Listener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, Procedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, SyncListener<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, SyncProcedure<T> procedure) {\r
+               session.asyncRequest(request,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(Write request) {\r
+               session.asyncRequest(request);  \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(Write request,\r
+                       Callback<DatabaseException> callback) {\r
+               session.asyncRequest(request, callback);        \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(WriteOnly r) {\r
+               session.asyncRequest(r);        \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(WriteOnly r,\r
+                       Callback<DatabaseException> callback) {\r
+               session.asyncRequest(r,callback);       \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(WriteOnlyResult<T> r,\r
+                       Procedure<T> procedure) {\r
+               session.asyncRequest(r,procedure);      \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(WriteResult<T> r, Procedure<T> procedure) {\r
+               session.asyncRequest(r,procedure);      \r
+       }\r
+       \r
+       \r
+       \r
+       @Override\r
+       public void claim(final Resource subject, final Resource predicate,\r
+                       final Resource inverse, final Resource object) throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claim(subject, predicate, inverse, object);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void claim(final Resource subject, final Resource predicate, final Resource object)\r
+                       throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claim(subject, predicate, object);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+\r
+       @Override\r
+       public void claimLiteral(final Resource resource, final Resource predicate,\r
+                       final Object value) throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimLiteral(resource, predicate, value);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(final Resource resource, final Resource predicate,\r
+                       final Object value, final Binding binding) throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimLiteral(resource, predicate, value, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(final Resource resource, final Resource predicate,\r
+                       final Resource inverse, final Resource type, final Object value)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimLiteral(resource, predicate, inverse, type, value);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(final Resource resource, final Resource predicate,\r
+                       final Resource inverse, final Resource type, final Object value, final Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimLiteral(resource, predicate, inverse, type, value, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(final Resource resource, final Resource predicate,\r
+                       final Resource type, final Object value) throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimLiteral(resource, predicate, type, value);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(final Resource resource, final Resource predicate,\r
+                       final Resource type, final Object value, final Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimLiteral(resource, predicate, type, value, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void claimValue(final Resource resource, final Object value)\r
+                       throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimValue(resource, value);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void claimValue(final Resource resource, final Object value, final Binding binding)\r
+                       throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimValue(resource, value, binding);     \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @SuppressWarnings("deprecation")\r
+       @Override\r
+       public void claimValue(final Resource resource, final Resource predicate,\r
+                       final Object value) throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimValue(resource, predicate, value);   \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @SuppressWarnings("deprecation")\r
+       @Override\r
+       public void claimValue(final Resource resource, final Resource predicate,\r
+                       final Object value, final Binding binding) throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimValue(resource, predicate, value, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @SuppressWarnings("deprecation")\r
+       @Override\r
+       public void claimValue(final Resource resource, final Resource predicate,\r
+                       final Resource inverse, final Resource type, final Object value, final Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.claimValue(resource, predicate, inverse, type, value, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void deny(final Resource subject) throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.deny(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void deny(final Resource subject, final Resource predicate)\r
+                       throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.deny(subject, predicate);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void deny(final Resource subject, final Resource predicate,\r
+                       final Resource inverse, final Resource object) throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.deny(subject, predicate, inverse, object);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void deny(final Resource subject, final Resource predicate, final Resource object)\r
+                       throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.deny(subject, predicate, object);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void deny(final Statement statement) throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.deny(statement);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+\r
+       @Override\r
+       public void denyStatement(final Resource subject, final Resource predicate,\r
+                       final Resource object) throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.denyStatement(subject, predicate, object);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void denyValue(final Resource resource) throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.denyValue(resource);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void denyValue(final Resource resource, final Resource predicate)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.denyValue(resource, predicate);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void flushCluster() throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.flushCluster();\r
+                                       \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void flushCluster(final Resource r) throws ServiceException {\r
+               try {\r
+                       session.syncRequest(new WriteRequest() {\r
+                               \r
+                               @Override\r
+                               public void perform(WriteGraph graph) throws DatabaseException {\r
+                                       graph.flushCluster(r);\r
+                                       \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(final Resource resource, final Class<T> clazz,\r
+                       final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(final Resource resource, final Class<T> clazz,\r
+                       final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(final Resource resource, final Class<T> clazz,\r
+                       final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(final Resource resource, final Class<T> clazz,\r
+                       final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(final Resource resource, final Class<T> clazz,\r
+                       final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(final Resource resource, final Class<T> clazz,\r
+                       final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedObjectSet(final Resource subject, final Resource relation,\r
+                       final AsyncSetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAssertedObjectSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedObjectSet(final Resource subject, final Resource relation,\r
+                       final SetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAssertedObjectSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedObjectSet(final Resource subject, final Resource relation,\r
+                       final SyncSetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAssertedObjectSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedStatementSet(final Resource subject,\r
+                       final Resource relation, final AsyncSetListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAssertedStatementSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedStatementSet(final Resource subject,\r
+                       final Resource relation, final SetListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAssertedStatementSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedStatementSet(final Resource subject,\r
+                       final Resource relation, final SyncSetListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forAssertedStatementSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(final String id, final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forBuiltin(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(final String id, final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forBuiltin(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(final String id, final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forBuiltin(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(final String id, final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forBuiltin(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(final String id, final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forBuiltin(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(final String id, final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forBuiltin(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forDirectSuperrelations(final Resource subject,\r
+                       final AsyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forDirectSuperrelations(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedObject(final Resource subject, final Resource relation,\r
+                       final AsyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachAssertedObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedObject(final Resource subject, final Resource relation,\r
+                       final MultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachAssertedObject(subject, relation, procedure);      \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedObject(final Resource subject, final Resource relation,\r
+                       final SyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachAssertedObject(subject, relation, procedure);      \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedStatement(final Resource subject,\r
+                       final Resource relation, final AsyncMultiProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachAssertedStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedStatement(final Resource subject,\r
+                       final Resource relation, final MultiProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachAssertedStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedStatement(final Resource subject,\r
+                       final Resource relation, final SyncMultiProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachAssertedStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectObject(final Resource subject, final Resource relation,\r
+                       final AsyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachDirectObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectObject(final Resource subject, final Resource relation,\r
+                       final MultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachDirectObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectObject(final Resource subject, final Resource relation,\r
+                       final SyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachDirectObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectPredicate(final Resource subject,\r
+                       final AsyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachDirectPredicate(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectPredicate(final Resource subject,\r
+                       final MultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachDirectPredicate(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectPredicate(final Resource subject,\r
+                       final SyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachDirectPredicate(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachObject(final Resource subject, final Resource relation,\r
+                       final AsyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachObject(final Resource subject, final Resource relation,\r
+                       final MultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachObject(final Resource subject, final Resource relation,\r
+                       final SyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPredicate(final Resource subject,\r
+                       final AsyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachPredicate(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPredicate(final Resource subject,\r
+                       final MultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachPredicate(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPredicate(final Resource subject,\r
+                       final SyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachPredicate(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPrincipalType(final Resource subject,\r
+                       final AsyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachPrincipalType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPrincipalType(final Resource subject,\r
+                       final MultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachPrincipalType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPrincipalType(final Resource subject,\r
+                       final SyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachPrincipalType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachStatement(final Resource subject, final Resource relation,\r
+                       final AsyncMultiProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachStatement(final Resource subject, final Resource relation,\r
+                       final MultiProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forEachStatement(final Resource subject, final Resource relation,\r
+                       final SyncMultiProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forEachStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject,\r
+                       final AsyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject,\r
+                       final AsyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, procedure);      \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject,\r
+                       final Listener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, procedure);      \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject,\r
+                       final Procedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final AsyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, procedure);    \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final AsyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final Listener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final Procedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, procedure);    \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final Resource object, final AsyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, object, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final Resource object, final AsyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, object, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final Resource object, final Listener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final Resource object, final Procedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final Resource object, final SyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final Resource object, final SyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final SyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation,  procedure);   \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject, final Resource relation,\r
+                       final SyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject,\r
+                       final SyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject,  procedure);     \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(final Resource subject,\r
+                       final SyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasStatement(subject,  procedure);     \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(final Resource subject,\r
+                       final AsyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(final Resource subject,\r
+                       final AsyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasValue(subject, procedure);  \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(final Resource subject, final Listener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasValue(subject, procedure);  \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(final Resource subject, final Procedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasValue(subject, procedure);  \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(final Resource subject,\r
+                       final SyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasValue(subject, procedure);  \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(final Resource subject,\r
+                       final SyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forHasValue(subject, procedure);  \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public void forInverse(final Resource relation,\r
+                       final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                               \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getService(Class<T> api) throws ServiceNotFoundException {\r
+               return session.getService(api);\r
+       }\r
+\r
+       @Override\r
+       public <T> T peekService(Class<T> api) {\r
+               return session.peekService(api);\r
+       }\r
+\r
+       @Override\r
+       public boolean hasService(Class<?> api) {\r
+               return session.hasService(api);\r
+       }\r
+\r
+       @Override\r
+       public <T> void registerService(Class<T> api, T service) {\r
+               session.registerService(api, service);\r
+       }\r
+\r
+       @Override\r
+       public String getURI(final Resource resource)\r
+                       throws ValidationException,\r
+                       ServiceException, AssumptionException {\r
+               try {\r
+                       return session.syncRequest(new Read<String>() {\r
+                               \r
+                               @Override\r
+                               public String perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getURI(resource);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+               \r
+       }\r
+\r
+       @Override\r
+       public String getPossibleURI(final Resource resource)\r
+                       throws ValidationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<String>() {\r
+                               \r
+                               @Override\r
+                               public String perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getPossibleURI(resource);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getResource(final String uri)\r
+                       throws ResourceNotFoundException, ValidationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getResource(uri);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getPossibleResource(final String uri)\r
+                       throws ResourceNotFoundException, ValidationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getPossibleResource(uri);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Collection<Statement> getStatements(final Resource subject,\r
+                       final Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Collection<Statement>>() {\r
+                               \r
+                               @Override\r
+                               public Collection<Statement> perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getStatements(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Collection<Statement> getAssertedStatements(final Resource subject,\r
+                       final Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Collection<Statement>>() {\r
+                               \r
+                               @Override\r
+                               public Collection<Statement> perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getAssertedStatements(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Collection<Resource> getPredicates(final Resource subject)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Collection<Resource>>() {\r
+                               \r
+                               @Override\r
+                               public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getPredicates(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Collection<Resource> getPrincipalTypes(final Resource subject)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Collection<Resource>>() {\r
+                               \r
+                               @Override\r
+                               public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getPrincipalTypes(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Set<Resource> getTypes(final Resource subject) throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Set<Resource>>() {\r
+                               \r
+                               @Override\r
+                               public Set<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getTypes(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Set<Resource> getSupertypes(final Resource subject)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Set<Resource>>() {\r
+                               \r
+                               @Override\r
+                               public Set<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getSupertypes(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Set<Resource> getSuperrelations(final Resource subject)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Set<Resource>>() {\r
+                               \r
+                               @Override\r
+                               public Set<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getSuperrelations(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+//     @Override\r
+//     public Collection<Resource> getObjects(final Resource subject,\r
+//                     Resource relation)\r
+//                     throws ManyObjectsForFunctionalRelationException,\r
+//                     ServiceException {\r
+//             return graph.getObjects(subject, relation);\r
+//     }\r
+\r
+       @Override\r
+       public Collection<Resource> getAssertedObjects(final Resource subject, final Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Collection<Resource>>() {\r
+                               \r
+                               @Override\r
+                               public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getAssertedObjects(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getInverse(final Resource relation)\r
+                       throws NoInverseException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getInverse(relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getSingleObject(final Resource subject, final Resource relation)\r
+                       throws NoSingleResultException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getSingleObject(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Statement getSingleStatement(final Resource subject, final Resource relation)\r
+                       throws NoSingleResultException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Statement>() {\r
+                               \r
+                               @Override\r
+                               public Statement perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getSingleStatement(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getSingleType(final Resource subject)\r
+                       throws NoSingleResultException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getSingleType(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getSingleType(final Resource subject, final Resource baseType)\r
+                       throws NoSingleResultException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getSingleType(subject, baseType);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getValue(final Resource subject)\r
+                       throws DoesNotContainValueException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getValue(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getValue(final Resource subject, final Binding binding)\r
+                       throws DoesNotContainValueException, BindingException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getValue(subject, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getRelatedValue(final Resource subject, final Resource relation)\r
+                       throws NoSingleResultException, DoesNotContainValueException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getRelatedValue(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getRelatedValue(final Resource subject, final Resource relation,\r
+                       final Binding binding) throws NoSingleResultException,\r
+                       DoesNotContainValueException, BindingException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getRelatedValue(subject, relation, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getPossibleInverse(final Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleInverse(relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getPossibleObject(final Resource subject, final Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleObject(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Statement getPossibleStatement(final Resource subject,\r
+                       final Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Statement>() {\r
+                               \r
+                               @Override\r
+                               public Statement perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleStatement(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Resource getPossibleType(final Resource subject, final Resource baseType)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleType(subject, baseType);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleValue(final Resource subject) throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleValue(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleValue(final Resource subject, final Binding binding)\r
+                       throws BindingException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleValue(subject, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleRelatedValue(final Resource subject, final Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleRelatedValue(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Binding binding)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       BindingException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleRelatedValue(subject, relation, binding);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleAdapter(final Resource resource, final Class<T> clazz)\r
+                       throws ValidationException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleAdapter(resource, clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleUniqueAdapter(final Resource resource, final Class<T> clazz)\r
+                       throws ValidationException, ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getPossibleUniqueAdapter(resource, clazz);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public boolean isInstanceOf(final Resource resource, final Resource type)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Boolean>() {\r
+                               \r
+                               @Override\r
+                               public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.isInstanceOf(resource, type);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public boolean isInheritedFrom(final Resource resource, final Resource type)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Boolean>() {\r
+                               \r
+                               @Override\r
+                               public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.isInheritedFrom(resource, type);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public boolean isSubrelationOf(final Resource resource, final Resource relation)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Boolean>() {\r
+                               \r
+                               @Override\r
+                               public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.isSubrelationOf(resource, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public boolean hasStatement(final Resource subject) throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Boolean>() {\r
+                               \r
+                               @Override\r
+                               public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.hasStatement(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public boolean hasStatement(final Resource subject, final Resource relation)\r
+                       throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Boolean>() {\r
+                               \r
+                               @Override\r
+                               public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.hasStatement(subject, relation);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public boolean hasStatement(final Resource subject, final Resource relation,\r
+                       final Resource object) throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Boolean>() {\r
+                               \r
+                               @Override\r
+                               public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.hasStatement(subject, relation, object);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public boolean hasValue(final Resource subject) throws ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Boolean>() {\r
+                               \r
+                               @Override\r
+                               public Boolean perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.hasValue(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Datatype getDataType(final Resource subject) throws DatabaseException {\r
+               try {\r
+                       return session.syncRequest(new Read<Datatype>() {\r
+                               \r
+                               @Override\r
+                               public Datatype perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getDataType(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T extends Accessor> T getAccessor(final Resource subject)\r
+                       throws DatabaseException {\r
+               try {\r
+                       return session.syncRequest(new Read<T>() {\r
+                               \r
+                               @Override\r
+                               public T perform(ReadGraph graph) throws DatabaseException {\r
+               return graph.getAccessor(subject);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       throw new ServiceException(e);\r
+               }\r
+       }\r
+\r
+    @Override\r
+    public RandomAccessBinary getRandomAccessBinary(final Resource subject)\r
+    throws DatabaseException {\r
+        try {\r
+            return session.syncRequest(new Read<RandomAccessBinary>() {\r
+                @Override\r
+                public RandomAccessBinary perform(ReadGraph graph) throws DatabaseException {\r
+                    return graph.getRandomAccessBinary(subject);\r
+                }\r
+            });\r
+        } catch (DatabaseException e) {\r
+            throw new ServiceException(e);\r
+        }\r
+    }\r
+\r
+    @Override\r
+       public <T> T syncRequest(Read<T> request) throws DatabaseException {\r
+               return session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, AsyncListener<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, SyncListener<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, Listener<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, AsyncProcedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, SyncProcedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, Procedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request) throws DatabaseException {\r
+               return session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request,\r
+                       AsyncListener<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request, SyncListener<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request, Listener<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request,\r
+                       AsyncProcedure<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request,\r
+                       SyncProcedure<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request, Procedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       AsyncMultiListener<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       SyncMultiListener<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       MultiListener<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       AsyncMultiProcedure<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       SyncMultiProcedure<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       MultiProcedure<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       AsyncMultiListener<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       SyncMultiListener<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       MultiListener<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       AsyncMultiProcedure<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       SyncMultiProcedure<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       MultiProcedure<T> procedure) throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(ExternalRead<T> request)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(ExternalRead<T> request, Listener<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(ExternalRead<T> request, Procedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void syncRequest(Write request) throws DatabaseException {\r
+               session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public void syncRequest(DelayedWrite request) throws DatabaseException {\r
+               session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public void syncRequest(WriteOnly r) throws DatabaseException {\r
+               session.syncRequest(r);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(WriteResult<T> request)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(DelayedWriteResult<T> request)\r
+                       throws DatabaseException {\r
+               return session.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(WriteOnlyResult<T> r) throws DatabaseException {\r
+               return session.syncRequest(r);\r
+       }\r
+\r
+       @Override\r
+       public void forURI(final Resource resource, final AsyncListener<String> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forURI(resource, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forURI(final Resource resource, final SyncListener<String> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forURI(resource, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forURI(final Resource resource, final Listener<String> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forURI(resource, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forURI(final Resource resource, final AsyncProcedure<String> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forURI(resource, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forURI(final Resource resource, final SyncProcedure<String> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forURI(resource, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forURI(final Resource resource, final Procedure<String> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forURI(resource, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forResource(final String id, final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forResource(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forResource(final String id, final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forResource(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forResource(final String id, final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forResource(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forResource(final String id, final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forResource(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forResource(final String id, final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forResource(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forResource(final String id, final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forResource(id, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forStatementSet(final Resource subject, final Resource relation,\r
+                       final AsyncSetListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forStatementSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forStatementSet(final Resource subject, final Resource relation,\r
+                       final SyncSetListener<Statement> procedure) {\r
+               \r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forStatementSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forStatementSet(final Resource subject, final Resource relation,\r
+                       final SetListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forStatementSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPredicateSet(final Resource subject,\r
+                       final AsyncSetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPredicateSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPredicateSet(final Resource subject,\r
+                       final SyncSetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPredicateSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPredicateSet(final Resource subject,\r
+                       final SetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPredicateSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPrincipalTypeSet(final Resource subject,\r
+                       final AsyncSetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPrincipalTypeSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPrincipalTypeSet(final Resource subject,\r
+                       final SyncSetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forPrincipalTypeSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPrincipalTypeSet(final Resource subject,\r
+                       final SetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPrincipalTypeSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(final Resource subject,\r
+                       final AsyncListener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forTypes(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(final Resource subject,\r
+                       final SyncListener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forTypes(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(final Resource subject, final Listener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forTypes(subject, procedure);             \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(final Resource subject,\r
+                       final AsyncProcedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forTypes(subject, procedure);             \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(final Resource subject,\r
+                       final SyncProcedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forTypes(subject, procedure);             \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(final Resource subject,\r
+                       final Procedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forTypes(subject, procedure);     \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(final Resource subject,\r
+                       final AsyncListener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSupertypes(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(final Resource subject,\r
+                       final SyncListener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSupertypes(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(final Resource subject,\r
+                       final Listener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSupertypes(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(final Resource subject,\r
+                       final AsyncProcedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSupertypes(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(final Resource subject,\r
+                       final SyncProcedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSupertypes(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(final Resource subject,\r
+                       final Procedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSupertypes(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleSuperrelation(final Resource subject,\r
+                       final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleSuperrelation(subject, procedure);     \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(final Resource subject,\r
+                       final AsyncListener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSuperrelations(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(final Resource subject,\r
+                       final SyncListener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSuperrelations(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(final Resource subject,\r
+                       final Listener<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSuperrelations(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(final Resource subject,\r
+                       final AsyncProcedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSuperrelations(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(final Resource subject,\r
+                       final SyncProcedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSuperrelations(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(final Resource subject,\r
+                       final Procedure<Set<Resource>> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSuperrelations(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forObjectSet(final Resource subject, final Resource relation,\r
+                       final AsyncSetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forObjectSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forObjectSet(final Resource subject, final Resource relation,\r
+                       final SyncSetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forObjectSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forObjectSet(final Resource subject, final Resource relation,\r
+                       final SetListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forObjectSet(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(final Resource relation,\r
+                       final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(final Resource relation, final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(final Resource relation,\r
+                       final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(final Resource relation,\r
+                       final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(final Resource relation, final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(final Resource subject, final Resource relation,\r
+                       final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(final Resource subject, final Resource relation,\r
+                       final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(final Resource subject, final Resource relation,\r
+                       final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleObject(subject, relation, procedure);            \r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(final Resource subject, final Resource relation,\r
+                       final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(final Resource subject, final Resource relation,\r
+                       final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(final Resource subject, final Resource relation,\r
+                       final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(final Resource subject, final Resource relation,\r
+                       final AsyncListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(final Resource subject, final Resource relation,\r
+                       final SyncListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(final Resource subject, final Resource relation,\r
+                       final Listener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forSingleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+                               \r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(final Resource subject, final Resource relation,\r
+                       final AsyncProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(final Resource subject, final Resource relation,\r
+                       final SyncProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(final Resource subject, final Resource relation,\r
+                       final Procedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject,\r
+                       final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject,\r
+                       final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject, final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject,\r
+                       final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject,\r
+                       final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject,\r
+                       final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject, final Resource baseType,\r
+                       final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject, final Resource baseType,\r
+                       final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject, final Resource baseType,\r
+                       final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject, final Resource baseType,\r
+                       final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject, final Resource baseType,\r
+                       final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(final Resource subject, final Resource baseType,\r
+                       final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final Binding binding,\r
+                       final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final Binding binding,\r
+                       final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final Binding binding,\r
+                       final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final Binding binding,\r
+                       final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final Binding binding,\r
+                       final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(final Resource subject, final Binding binding,\r
+                       final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forValue(subject, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final Binding binding, final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final Binding binding, final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final Binding binding, final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final Binding binding, final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final Binding binding, final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(final Resource subject, final Resource relation,\r
+                       final Binding binding, final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(final Resource resource, final Class<T> clazz,\r
+                       final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(final Resource resource, final Class<T> clazz,\r
+                       final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(final Resource resource, final Class<T> clazz,\r
+                       final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(final Resource resource, final Class<T> clazz,\r
+                       final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(final Resource resource, final Class<T> clazz,\r
+                       final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(final Resource resource, final Class<T> clazz,\r
+                       final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(final Resource relation,\r
+                       final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(final Resource relation,\r
+                       final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(final Resource relation,\r
+                       final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(final Resource relation,\r
+                       final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(final Resource relation,\r
+                       final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(final Resource relation,\r
+                       final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleInverse(relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(final Resource subject, final Resource relation,\r
+                       final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(final Resource subject, final Resource relation,\r
+                       final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(final Resource subject, final Resource relation,\r
+                       final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(final Resource subject, final Resource relation,\r
+                       final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(final Resource subject, final Resource relation,\r
+                       final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(final Resource subject, final Resource relation,\r
+                       final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(final Resource subject, final Resource relation,\r
+                       final AsyncListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(final Resource subject, final Resource relation,\r
+                       final SyncListener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(final Resource subject, final Resource relation,\r
+                       final Listener<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(final Resource subject, final Resource relation,\r
+                       final AsyncProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(final Resource subject, final Resource relation,\r
+                       final SyncProcedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(final Resource subject, final Resource relation,\r
+                       final Procedure<Statement> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(final Resource subject, final Resource baseType,\r
+                       final AsyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(final Resource subject, final Resource baseType,\r
+                       final SyncListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(final Resource subject, final Resource baseType,\r
+                       final Listener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(final Resource subject, final Resource baseType,\r
+                       final AsyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(final Resource subject, final Resource baseType,\r
+                       final SyncProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(final Resource subject, final Resource baseType,\r
+                       final Procedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject,\r
+                       final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject,\r
+                       final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject, final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject,\r
+                       final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject,\r
+                       final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject,\r
+                       final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject, final Binding binding,\r
+                       final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject, final Binding binding,\r
+                       final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject, final Binding binding,\r
+                       final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject, final Binding binding,\r
+                       final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject, final Binding binding,\r
+                       final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(final Resource subject, final Binding binding,\r
+                       final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleValue(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Binding binding, final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Binding binding, final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Binding binding, final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Binding binding, final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Binding binding, final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(final Resource subject,\r
+                       final Resource relation, final Binding binding, final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(final Resource resource, final Class<T> clazz,\r
+                       final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(final Resource resource, final Class<T> clazz,\r
+                       final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(final Resource resource, final Class<T> clazz,\r
+                       final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(final Resource resource, final Class<T> clazz,\r
+                       final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(final Resource resource, final Class<T> clazz,\r
+                       final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(final Resource resource, final Class<T> clazz,\r
+                       final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(final Resource resource,\r
+                       final Class<T> clazz, final AsyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(final Resource resource,\r
+                       final Class<T> clazz, final SyncListener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(final Resource resource,\r
+                       final Class<T> clazz, final Listener<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(final Resource resource,\r
+                       final Class<T> clazz, final AsyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(final Resource resource,\r
+                       final Class<T> clazz, final SyncProcedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(final Resource resource,\r
+                       final Class<T> clazz, final Procedure<T> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(final Resource resource, final Resource type,\r
+                       final AsyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(final Resource resource, final Resource type,\r
+                       final SyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(final Resource resource, final Resource type,\r
+                       final Listener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(final Resource resource, final Resource type,\r
+                       final AsyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(final Resource resource, final Resource type,\r
+                       final SyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(final Resource resource, final Resource type,\r
+                       final Procedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(final Resource resource, final Resource type,\r
+                       final AsyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(final Resource resource, final Resource type,\r
+                       final SyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(final Resource resource, final Resource type,\r
+                       final Listener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(final Resource resource, final Resource type,\r
+                       final AsyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(final Resource resource, final Resource type,\r
+                       final SyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(final Resource resource, final Resource type,\r
+                       final Procedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(final Resource resource, final Resource relation,\r
+                       final AsyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(final Resource resource, final Resource relation,\r
+                       final SyncListener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(final Resource resource, final Resource relation,\r
+                       final Listener<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(final Resource resource, final Resource relation,\r
+                       final AsyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(final Resource resource, final Resource relation,\r
+                       final SyncProcedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(final Resource resource, final Resource relation,\r
+                       final Procedure<Boolean> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(final Resource subject,\r
+                       final AsyncMultiListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forOrderedSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(final Resource subject,\r
+                       final SyncMultiListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forOrderedSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(final Resource subject,\r
+                       final MultiListener<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forOrderedSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(final Resource subject,\r
+                       final AsyncMultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forOrderedSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(final Resource subject,\r
+                       final SyncMultiProcedure<Resource> procedure) {\r
+               \r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       graph.forOrderedSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(final Resource subject,\r
+                       final MultiProcedure<Resource> procedure) {\r
+               try {\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+               graph.forOrderedSet(subject, procedure);\r
+                               }\r
+                       });\r
+               } catch (DatabaseException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       @Override\r
+       public int thread() {\r
+               return -1;\r
+       }\r
+\r
+       @Override\r
+       public Session getSession() {\r
+               return session;\r
+       }\r
+\r
+       @Override\r
+       public Resource getBuiltin(final String id) throws ResourceNotFoundException,\r
+                       ServiceException {\r
+               try {\r
+                       return session.syncRequest(new Read<Resource>() {\r
+                               \r
+                               @Override\r
+                               public Resource perform(ReadGraph graph) throws DatabaseException {\r
+                                       return graph.getBuiltin(id);\r
+                               }\r
+                               });\r
+                       } catch (DatabaseException e) {\r
+                               throw new ServiceException(e);\r
+                       }\r
+       }\r
+       \r
+       @Override\r
+       public VirtualGraph getProvider() {\r
+               return null;\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/WriteGraphProxy.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/WriteGraphProxy.java
new file mode 100644 (file)
index 0000000..96ee011
--- /dev/null
@@ -0,0 +1,2732 @@
+package org.simantics.interop.mapping;\r
+\r
+import java.util.Collection;\r
+import java.util.Set;\r
+import java.util.TreeMap;\r
+\r
+import org.simantics.databoard.accessor.Accessor;\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.type.Datatype;\r
+import org.simantics.databoard.util.binary.RandomAccessBinary;\r
+import org.simantics.db.Metadata;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.VirtualGraph;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.exception.AdaptionException;\r
+import org.simantics.db.exception.AssumptionException;\r
+import org.simantics.db.exception.BindingException;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.exception.DoesNotContainValueException;\r
+import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;\r
+import org.simantics.db.exception.NoInverseException;\r
+import org.simantics.db.exception.NoSingleResultException;\r
+import org.simantics.db.exception.ResourceNotFoundException;\r
+import org.simantics.db.exception.ServiceException;\r
+import org.simantics.db.exception.ServiceNotFoundException;\r
+import org.simantics.db.exception.ValidationException;\r
+import org.simantics.db.procedure.AsyncListener;\r
+import org.simantics.db.procedure.AsyncMultiListener;\r
+import org.simantics.db.procedure.AsyncMultiProcedure;\r
+import org.simantics.db.procedure.AsyncProcedure;\r
+import org.simantics.db.procedure.AsyncSetListener;\r
+import org.simantics.db.procedure.Listener;\r
+import org.simantics.db.procedure.MultiListener;\r
+import org.simantics.db.procedure.MultiProcedure;\r
+import org.simantics.db.procedure.Procedure;\r
+import org.simantics.db.procedure.SetListener;\r
+import org.simantics.db.procedure.SyncListener;\r
+import org.simantics.db.procedure.SyncMultiListener;\r
+import org.simantics.db.procedure.SyncMultiProcedure;\r
+import org.simantics.db.procedure.SyncProcedure;\r
+import org.simantics.db.procedure.SyncSetListener;\r
+import org.simantics.db.request.AsyncMultiRead;\r
+import org.simantics.db.request.AsyncRead;\r
+import org.simantics.db.request.DelayedWrite;\r
+import org.simantics.db.request.DelayedWriteResult;\r
+import org.simantics.db.request.ExternalRead;\r
+import org.simantics.db.request.MultiRead;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.db.request.ReadInterface;\r
+import org.simantics.db.request.Write;\r
+import org.simantics.db.request.WriteInterface;\r
+import org.simantics.db.request.WriteOnly;\r
+import org.simantics.db.request.WriteOnlyResult;\r
+import org.simantics.db.request.WriteResult;\r
+import org.simantics.db.request.WriteTraits;\r
+import org.simantics.scl.types.Type;\r
+import org.simantics.utils.datastructures.Callback;\r
+\r
+/**\r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class WriteGraphProxy implements WriteGraph {\r
+       \r
+       protected WriteGraph graph;\r
+       \r
+       \r
+       @Override\r
+       public <T> T getRelatedValue2(Resource subject, Resource relation)\r
+                       throws DatabaseException {\r
+               return graph.getRelatedValue2(subject, relation);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getRelatedValue2(Resource subject, Resource relation,\r
+                       Binding binding) throws DatabaseException {\r
+               return graph.getRelatedValue2(subject, relation, binding);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getRelatedValue2(Resource subject, Resource relation,\r
+                       Object context) throws DatabaseException {\r
+               return graph.getRelatedValue2(subject, relation, context);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getRelatedValue2(Resource subject, Resource relation,\r
+                       Object context, Binding binding) throws DatabaseException {\r
+               return graph.getRelatedValue2(subject, relation, context, binding);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedValue2(Resource subject, Resource relation)\r
+                       throws DatabaseException {\r
+               return graph.getPossibleRelatedValue2(subject, relation);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedValue2(Resource subject, Resource relation,\r
+                       Binding binding) throws DatabaseException {\r
+               return graph.getPossibleRelatedValue2(subject, relation, binding);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedValue2(Resource subject, Resource relation,\r
+                       Object context) throws DatabaseException {\r
+               return graph.getPossibleRelatedValue2(subject, relation, context);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedValue2(Resource subject, Resource relation,\r
+                       Object context, Binding binding) throws DatabaseException {\r
+               return getPossibleRelatedValue2(subject, relation, context, binding);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(ReadInterface<T> r, AsyncListener<T> procedure) {\r
+               graph.async(r,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(ReadInterface<T> r, AsyncProcedure<T> procedure) {\r
+               graph.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(ReadInterface<T> r, Listener<T> procedure) {\r
+               graph.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(ReadInterface<T> r, Procedure<T> procedure) {\r
+               graph.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(ReadInterface<T> r, SyncListener<T> procedure) {\r
+               graph.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(ReadInterface<T> r, SyncProcedure<T> procedure) {\r
+               graph.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(WriteInterface<T> r) {\r
+               graph.async(r);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void async(WriteInterface<T> r, Procedure<T> procedure) {\r
+               graph.async(r, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T sync(ReadInterface<T> r) throws DatabaseException {\r
+               return graph.sync(r);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T sync(WriteInterface<T> r) throws DatabaseException {\r
+               return graph.sync(r);\r
+       }\r
+       \r
+       @Override\r
+       public Resource getRootLibrary() {\r
+               return graph.getRootLibrary();\r
+       }\r
+       \r
+       \r
+       @Override\r
+       public void clearUndoList(WriteTraits writeTraits) {\r
+               graph.clearUndoList(writeTraits);\r
+       }\r
+       \r
+       @Override\r
+       public void combineWithPrevious(WriteTraits writeTraits) {\r
+               graph.combineWithPrevious(writeTraits);\r
+       }\r
+       \r
+       @Override\r
+       public TreeMap<String, byte[]> getMetadata() {\r
+               return graph.getMetadata();\r
+       }\r
+       \r
+       @Override\r
+       public <T extends Metadata> T getMetadata(Class<T> clazz)\r
+                       throws ServiceException {\r
+               return graph.getMetadata(clazz);\r
+       }\r
+       \r
+       @Override\r
+       public Type getRelatedValueType(Resource subject, Resource relation)\r
+                       throws DatabaseException {\r
+               return graph.getRelatedValueType(subject, relation);\r
+       }\r
+       \r
+       @Override\r
+       public void deny(Resource subject, Resource predicate, Resource inverse,\r
+                       Resource object, VirtualGraph graph) throws ServiceException {\r
+               this.graph.deny(subject, predicate, inverse, object, graph);\r
+       }\r
+       \r
+       \r
+       \r
+       \r
+       @Override\r
+       public <T> T adaptRelated(Resource resource, Resource relation,\r
+                       Class<T> clazz) throws AdaptionException, NoSingleResultException,\r
+                       ValidationException, ServiceException {\r
+               return graph.adaptRelated(resource, relation, clazz);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T getPossibleRelatedAdapter(Resource resource,\r
+                       Resource relation, Class<T> clazz) throws ValidationException,\r
+                       ServiceException {\r
+               return graph.getPossibleRelatedAdapter(resource, relation, clazz);\r
+       }\r
+       \r
+       @Override\r
+       public void inc() {\r
+               graph.inc();\r
+       }\r
+       \r
+       @Override\r
+       public void dec() {\r
+               graph.dec();\r
+       }\r
+       \r
+       @Override\r
+       public Collection<Resource> getObjects(Resource subject, Resource relation) throws ServiceException \r
+                       {\r
+               return graph.getObjects(subject, relation);\r
+       }\r
+       \r
+       @Override\r
+       public <T extends Accessor> T newLiteral(Resource resource,\r
+       Resource predicate, Datatype datatype, Object initialValue)\r
+       throws DatabaseException {\r
+               return graph.newLiteral(resource, predicate, datatype, initialValue);\r
+       }\r
+\r
+    @Override\r
+    public RandomAccessBinary newLiteral4RandomAccessBinary\r
+    (Resource resource, Resource predicate, Datatype datatype, Object initialValue)\r
+    throws DatabaseException {\r
+        return graph.newLiteral4RandomAccessBinary(resource, predicate, datatype, initialValue);\r
+    }\r
+//     @Override\r
+//     public void claimFile(Resource resource, Object content, Binding binding)\r
+//                     throws DatabaseException {\r
+//             graph.claimFile(resource, content, binding);\r
+//     }\r
+//     \r
+//     @Override\r
+//     public void denyFile(Resource resource) throws DatabaseException {\r
+//             graph.denyFile(resource);\r
+//     }\r
+       \r
+       public <T, C> T adaptContextual(Resource resource, C context, java.lang.Class<C> contextClass, java.lang.Class<T> clazz) throws AdaptionException ,NoSingleResultException ,ValidationException ,ServiceException {\r
+               return graph.adaptContextual(resource, context, contextClass, clazz);\r
+       };\r
+       \r
+       public <T, C> T getPossibleContextualAdapter(Resource resource, C context, java.lang.Class<C> contextClass, java.lang.Class<T> clazz) throws ValidationException ,ServiceException {\r
+               return graph.getPossibleContextualAdapter(resource, context, contextClass, clazz);\r
+       };\r
+       \r
+       \r
+       public WriteGraphProxy(WriteGraph graph) {\r
+               this.graph = graph;\r
+       }\r
+       \r
+       @Override\r
+       public Resource newResource() throws ServiceException {\r
+               return graph.newResource();\r
+       }\r
+       \r
+       @Override\r
+       public Resource newResource(long clusterId) throws ServiceException {\r
+               return graph.newResource(clusterId);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T adapt(Resource resource, Class<T> clazz)\r
+                       throws AdaptionException, ValidationException, ServiceException {\r
+               return graph.adapt(resource, clazz);\r
+       }\r
+       \r
+       @Override\r
+       public <T> T adaptUnique(Resource resource, Class<T> clazz)\r
+                       throws AdaptionException, ValidationException, ServiceException {\r
+               return adaptUnique(resource, clazz);\r
+       }\r
+       \r
+       @Override\r
+       public void addLiteral(Resource resource, Resource predicate,\r
+                       Resource inverse, Object value, Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.addLiteral(resource, predicate, inverse, value, binding);\r
+       }\r
+       \r
+       @Override\r
+       public void addLiteral(Resource resource, Resource predicate,\r
+                       Resource inverse, Resource type, Object value, Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.addLiteral(resource, predicate, inverse, type, value, binding);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void addMetadata(Metadata data) throws ServiceException {\r
+               graph.addMetadata(data);\r
+       }\r
+       \r
+       @SuppressWarnings("deprecation")\r
+       @Override\r
+       public void addValue(Resource resource, Resource predicate,\r
+                       Resource inverse, Resource type, Object value, Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.addValue(resource, predicate, inverse, type, value, binding);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request) {\r
+               graph.asyncRequest(request);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       AsyncMultiListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       AsyncMultiProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       MultiListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       MultiProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       SyncMultiListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncMultiRead<T> request,\r
+                       SyncMultiProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request) {\r
+               graph.asyncRequest(request);    \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       AsyncListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request, Listener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       Procedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       SyncListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(AsyncRead<T> request,\r
+                       SyncProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(DelayedWrite request) {\r
+               graph.asyncRequest(request);    \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(DelayedWrite request,\r
+                       Callback<DatabaseException> callback) {\r
+               graph.asyncRequest(request,callback);   \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(DelayedWriteResult<T> r,\r
+                       Procedure<T> procedure) {\r
+               graph.asyncRequest(r,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(ExternalRead<T> request) {\r
+               graph.asyncRequest(request);    \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(ExternalRead<T> request,\r
+                       Listener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);\r
+       }       \r
+       \r
+       @Override\r
+       public <T> void asyncRequest(ExternalRead<T> request,\r
+                       Procedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request) {\r
+               graph.asyncRequest(request);    \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       AsyncMultiListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       AsyncMultiProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       MultiListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       MultiProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       SyncMultiListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(MultiRead<T> request,\r
+                       SyncMultiProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request) {\r
+               graph.asyncRequest(request);    \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, AsyncListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, Listener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, Procedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, SyncListener<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(Read<T> request, SyncProcedure<T> procedure) {\r
+               graph.asyncRequest(request,procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(Write request) {\r
+               graph.asyncRequest(request);    \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(Write request,\r
+                       Callback<DatabaseException> callback) {\r
+               graph.asyncRequest(request, callback);  \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(WriteOnly r) {\r
+               graph.asyncRequest(r);  \r
+       }\r
+       \r
+       @Override\r
+       public void asyncRequest(WriteOnly r,\r
+                       Callback<DatabaseException> callback) {\r
+               graph.asyncRequest(r,callback); \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(WriteOnlyResult<T> r,\r
+                       Procedure<T> procedure) {\r
+               graph.asyncRequest(r,procedure);        \r
+       }\r
+       \r
+       @Override\r
+       public <T> void asyncRequest(WriteResult<T> r, Procedure<T> procedure) {\r
+               graph.asyncRequest(r,procedure);        \r
+       }\r
+       \r
+       \r
+       \r
+       @Override\r
+       public void claim(Resource subject, Resource predicate,\r
+                       Resource inverse, Resource object) throws ServiceException {\r
+               graph.claim(subject, predicate, inverse, object);\r
+       }\r
+       \r
+       @Override\r
+       public void claim(Resource subject, Resource predicate, Resource object)\r
+                       throws ServiceException {\r
+               graph.claim(subject, predicate, object);\r
+       }\r
+       \r
+\r
+       @Override\r
+       public void claimLiteral(Resource resource, Resource predicate,\r
+                       Object value) throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               graph.claimLiteral(resource, predicate, value);\r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(Resource resource, Resource predicate,\r
+                       Object value, Binding binding) throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.claimLiteral(resource, predicate, value, binding);\r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(Resource resource, Resource predicate,\r
+                       Resource inverse, Resource type, Object value)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.claimLiteral(resource, predicate, inverse, type, value);\r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(Resource resource, Resource predicate,\r
+                       Resource inverse, Resource type, Object value, Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.claimLiteral(resource, predicate, inverse, type, value, binding);\r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(Resource resource, Resource predicate,\r
+                       Resource type, Object value) throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.claimLiteral(resource, predicate, type, value);\r
+       }\r
+       \r
+       @Override\r
+       public void claimLiteral(Resource resource, Resource predicate,\r
+                       Resource type, Object value, Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.claimLiteral(resource, predicate, type, value, binding);\r
+       }\r
+       \r
+       @Override\r
+       public void claimValue(Resource resource, Object value)\r
+                       throws ServiceException {\r
+               graph.claimValue(resource, value);\r
+       }\r
+       \r
+       @Override\r
+       public void claimValue(Resource resource, Object value, Binding binding)\r
+                       throws ServiceException {\r
+               graph.claimValue(resource, value, binding);     \r
+       }\r
+       \r
+       @SuppressWarnings("deprecation")\r
+       @Override\r
+       public void claimValue(Resource resource, Resource predicate,\r
+                       Object value) throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               graph.claimValue(resource, predicate, value);   \r
+       }\r
+       \r
+       @SuppressWarnings("deprecation")\r
+       @Override\r
+       public void claimValue(Resource resource, Resource predicate,\r
+                       Object value, Binding binding) throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.claimValue(resource, predicate, value, binding);\r
+       }\r
+       \r
+       @SuppressWarnings("deprecation")\r
+       @Override\r
+       public void claimValue(Resource resource, Resource predicate,\r
+                       Resource inverse, Resource type, Object value, Binding binding)\r
+                       throws BindingException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               graph.claimValue(resource, predicate, inverse, type, value, binding);\r
+       }\r
+       \r
+       @Override\r
+       public void deny(Resource subject) throws ServiceException {\r
+               graph.deny(subject);\r
+       }\r
+       \r
+       @Override\r
+       public void deny(Resource subject, Resource predicate)\r
+                       throws ServiceException {\r
+               graph.deny(subject, predicate);\r
+       }\r
+       \r
+       @Override\r
+       public void deny(Resource subject, Resource predicate,\r
+                       Resource inverse, Resource object) throws ServiceException {\r
+               graph.deny(subject, predicate, inverse, object);\r
+       }\r
+       \r
+       @Override\r
+       public void deny(Resource subject, Resource predicate, Resource object)\r
+                       throws ServiceException {\r
+               graph.deny(subject, predicate, object);\r
+       }\r
+       \r
+       @Override\r
+       public void deny(Statement statement) throws ServiceException {\r
+               graph.deny(statement);\r
+       }\r
+       \r
+\r
+       @Override\r
+       public void denyStatement(Resource subject, Resource predicate,\r
+                       Resource object) throws ServiceException {\r
+               graph.denyStatement(subject, predicate, object);\r
+       }\r
+       \r
+       @Override\r
+       public void denyValue(Resource resource) throws ServiceException {\r
+               graph.denyValue(resource);\r
+       }\r
+       \r
+       @Override\r
+       public void denyValue(Resource resource, Resource predicate)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               graph.denyValue(resource, predicate);\r
+       }\r
+       \r
+       @Override\r
+       public void flushCluster() throws ServiceException {\r
+               graph.flushCluster();\r
+       }\r
+       \r
+       @Override\r
+       public void flushCluster(Resource r) throws ServiceException {\r
+               graph.flushCluster(r);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(Resource resource, Class<T> clazz,\r
+                       AsyncListener<T> procedure) {\r
+               graph.forAdapted(resource, clazz, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(Resource resource, Class<T> clazz,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.forAdapted(resource, clazz, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(Resource resource, Class<T> clazz,\r
+                       Listener<T> procedure) {\r
+               graph.forAdapted(resource, clazz, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(Resource resource, Class<T> clazz,\r
+                       Procedure<T> procedure) {\r
+               graph.forAdapted(resource, clazz, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(Resource resource, Class<T> clazz,\r
+                       SyncListener<T> procedure) {\r
+               graph.forAdapted(resource, clazz, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public <T> void forAdapted(Resource resource, Class<T> clazz,\r
+                       SyncProcedure<T> procedure) {\r
+               graph.forAdapted(resource, clazz, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedObjectSet(Resource subject, Resource relation,\r
+                       AsyncSetListener<Resource> procedure) {\r
+               graph.forAssertedObjectSet(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedObjectSet(Resource subject, Resource relation,\r
+                       SetListener<Resource> procedure) {\r
+               graph.forAssertedObjectSet(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedObjectSet(Resource subject, Resource relation,\r
+                       SyncSetListener<Resource> procedure) {\r
+               graph.forAssertedObjectSet(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedStatementSet(Resource subject,\r
+                       Resource relation, AsyncSetListener<Statement> procedure) {\r
+               graph.forAssertedStatementSet(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedStatementSet(Resource subject,\r
+                       Resource relation, SetListener<Statement> procedure) {\r
+               graph.forAssertedStatementSet(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forAssertedStatementSet(Resource subject,\r
+                       Resource relation, SyncSetListener<Statement> procedure) {\r
+               graph.forAssertedStatementSet(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(String id, AsyncListener<Resource> procedure) {\r
+               graph.forBuiltin(id, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(String id, Listener<Resource> procedure) {\r
+               graph.forBuiltin(id, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(String id, AsyncProcedure<Resource> procedure) {\r
+               graph.forBuiltin(id, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(String id, Procedure<Resource> procedure) {\r
+               graph.forBuiltin(id, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(String id, SyncListener<Resource> procedure) {\r
+               graph.forBuiltin(id, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forBuiltin(String id, SyncProcedure<Resource> procedure) {\r
+               graph.forBuiltin(id, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forDirectSuperrelations(Resource subject,\r
+                       AsyncMultiProcedure<Resource> procedure) {\r
+               graph.forDirectSuperrelations(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedObject(Resource subject, Resource relation,\r
+                       AsyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachAssertedObject(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedObject(Resource subject, Resource relation,\r
+                       MultiProcedure<Resource> procedure) {\r
+               graph.forEachAssertedObject(subject, relation, procedure);      \r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedObject(Resource subject, Resource relation,\r
+                       SyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachAssertedObject(subject, relation, procedure);      \r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedStatement(Resource subject,\r
+                       Resource relation, AsyncMultiProcedure<Statement> procedure) {\r
+               graph.forEachAssertedStatement(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedStatement(Resource subject,\r
+                       Resource relation, MultiProcedure<Statement> procedure) {\r
+               graph.forEachAssertedStatement(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachAssertedStatement(Resource subject,\r
+                       Resource relation, SyncMultiProcedure<Statement> procedure) {\r
+               graph.forEachAssertedStatement(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectObject(Resource subject, Resource relation,\r
+                       AsyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachDirectObject(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectObject(Resource subject, Resource relation,\r
+                       MultiProcedure<Resource> procedure) {\r
+               graph.forEachDirectObject(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectObject(Resource subject, Resource relation,\r
+                       SyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachDirectObject(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectPredicate(Resource subject,\r
+                       AsyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachDirectPredicate(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectPredicate(Resource subject,\r
+                       MultiProcedure<Resource> procedure) {\r
+               graph.forEachDirectPredicate(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachDirectPredicate(Resource subject,\r
+                       SyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachDirectPredicate(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachObject(Resource subject, Resource relation,\r
+                       AsyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachObject(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachObject(Resource subject, Resource relation,\r
+                       MultiProcedure<Resource> procedure) {\r
+               graph.forEachObject(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachObject(Resource subject, Resource relation,\r
+                       SyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachObject(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPredicate(Resource subject,\r
+                       AsyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachPredicate(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPredicate(Resource subject,\r
+                       MultiProcedure<Resource> procedure) {\r
+               graph.forEachPredicate(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPredicate(Resource subject,\r
+                       SyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachPredicate(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPrincipalType(Resource subject,\r
+                       AsyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachPrincipalType(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPrincipalType(Resource subject,\r
+                       MultiProcedure<Resource> procedure) {\r
+               graph.forEachPrincipalType(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachPrincipalType(Resource subject,\r
+                       SyncMultiProcedure<Resource> procedure) {\r
+               graph.forEachPrincipalType(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachStatement(Resource subject, Resource relation,\r
+                       AsyncMultiProcedure<Statement> procedure) {\r
+               graph.forEachStatement(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachStatement(Resource subject, Resource relation,\r
+                       MultiProcedure<Statement> procedure) {\r
+               graph.forEachStatement(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forEachStatement(Resource subject, Resource relation,\r
+                       SyncMultiProcedure<Statement> procedure) {\r
+               graph.forEachStatement(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject,\r
+                       AsyncListener<Boolean> procedure) {\r
+               graph.forHasStatement(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject,\r
+                       AsyncProcedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject, procedure);      \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject,\r
+                       Listener<Boolean> procedure) {\r
+               graph.forHasStatement(subject, procedure);      \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject,\r
+                       Procedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       AsyncListener<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, procedure);    \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       AsyncProcedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       Listener<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       Procedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, procedure);    \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       Resource object, AsyncListener<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, object, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       Resource object, AsyncProcedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       Resource object, Listener<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       Resource object, Procedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       Resource object, SyncListener<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       Resource object, SyncProcedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, object, procedure);    \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       SyncListener<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation,  procedure);   \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject, Resource relation,\r
+                       SyncProcedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject, relation, procedure);    \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject,\r
+                       SyncListener<Boolean> procedure) {\r
+               graph.forHasStatement(subject,  procedure);     \r
+       }\r
+       \r
+       @Override\r
+       public void forHasStatement(Resource subject,\r
+                       SyncProcedure<Boolean> procedure) {\r
+               graph.forHasStatement(subject,  procedure);     \r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(Resource subject,\r
+                       AsyncListener<Boolean> procedure) {\r
+               graph.forHasValue(subject, procedure);\r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(Resource subject,\r
+                       AsyncProcedure<Boolean> procedure) {\r
+               graph.forHasValue(subject, procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(Resource subject, Listener<Boolean> procedure) {\r
+               graph.forHasValue(subject, procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(Resource subject, Procedure<Boolean> procedure) {\r
+               graph.forHasValue(subject, procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(Resource subject,\r
+                       SyncListener<Boolean> procedure) {\r
+               graph.forHasValue(subject, procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public void forHasValue(Resource subject,\r
+                       SyncProcedure<Boolean> procedure) {\r
+               graph.forHasValue(subject, procedure);  \r
+       }\r
+       \r
+       @Override\r
+       public void forInverse(Resource relation,\r
+                       AsyncListener<Resource> procedure) {\r
+               graph.forInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getService(Class<T> api) throws ServiceNotFoundException {\r
+               return graph.getService(api);\r
+       }\r
+\r
+       @Override\r
+       public <T> T peekService(Class<T> api) {\r
+               return graph.peekService(api);\r
+       }\r
+\r
+       @Override\r
+       public boolean hasService(Class<?> api) {\r
+               return graph.hasService(api);\r
+       }\r
+\r
+       @Override\r
+       public <T> void registerService(Class<T> api, T service) {\r
+               graph.registerService(api, service);\r
+       }\r
+\r
+       @Override\r
+       public String getURI(Resource resource)\r
+                       throws ValidationException,\r
+                       ServiceException, AssumptionException {\r
+               return graph.getURI(resource);\r
+       }\r
+\r
+       @Override\r
+       public String getPossibleURI(Resource resource)\r
+                       throws ValidationException,\r
+                       ServiceException {\r
+               return graph.getPossibleURI(resource);\r
+       }\r
+\r
+       @Override\r
+       public Resource getResource(String uri)\r
+                       throws ResourceNotFoundException, ValidationException,\r
+                       ServiceException {\r
+               return graph.getResource(uri);\r
+       }\r
+\r
+       @Override\r
+       public Resource getPossibleResource(String uri)\r
+                       throws ResourceNotFoundException, ValidationException,\r
+                       ServiceException {\r
+               return graph.getPossibleResource(uri);\r
+       }\r
+\r
+       @Override\r
+       public Collection<Statement> getStatements(Resource subject,\r
+                       Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               return graph.getStatements(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public Collection<Statement> getAssertedStatements(Resource subject,\r
+                       Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               return graph.getAssertedStatements(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public Collection<Resource> getPredicates(Resource subject)\r
+                       throws ServiceException {\r
+               return graph.getPredicates(subject);\r
+       }\r
+\r
+       @Override\r
+       public Collection<Resource> getPrincipalTypes(Resource subject)\r
+                       throws ServiceException {\r
+               return graph.getPrincipalTypes(subject);\r
+       }\r
+\r
+       @Override\r
+       public Set<Resource> getTypes(Resource subject) throws ServiceException {\r
+               return graph.getTypes(subject);\r
+       }\r
+\r
+       @Override\r
+       public Set<Resource> getSupertypes(Resource subject)\r
+                       throws ServiceException {\r
+               return graph.getSupertypes(subject);\r
+       }\r
+\r
+       @Override\r
+       public Set<Resource> getSuperrelations(Resource subject)\r
+                       throws ServiceException {\r
+               return graph.getSuperrelations(subject);\r
+       }\r
+\r
+//     @Override\r
+//     public Collection<Resource> getObjects(Resource subject,\r
+//                     Resource relation)\r
+//                     throws ManyObjectsForFunctionalRelationException,\r
+//                     ServiceException {\r
+//             return graph.getObjects(subject, relation);\r
+//     }\r
+\r
+       @Override\r
+       public Collection<Resource> getAssertedObjects(Resource subject,\r
+                       Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               return graph.getAssertedObjects(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public Resource getInverse(Resource relation)\r
+                       throws NoInverseException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               return graph.getInverse(relation);\r
+       }\r
+\r
+       @Override\r
+       public Resource getSingleObject(Resource subject, Resource relation)\r
+                       throws NoSingleResultException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               return graph.getSingleObject(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public Statement getSingleStatement(Resource subject, Resource relation)\r
+                       throws NoSingleResultException,\r
+                       ManyObjectsForFunctionalRelationException, ServiceException {\r
+               return graph.getSingleStatement(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public Resource getSingleType(Resource subject)\r
+                       throws NoSingleResultException, ServiceException {\r
+               return graph.getSingleType(subject);\r
+       }\r
+\r
+       @Override\r
+       public Resource getSingleType(Resource subject, Resource baseType)\r
+                       throws NoSingleResultException, ServiceException {\r
+               return graph.getSingleType(subject, baseType);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getValue(Resource subject)\r
+                       throws DoesNotContainValueException, ServiceException {\r
+               return graph.getValue(subject);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getValue(Resource subject, Binding binding)\r
+                       throws DoesNotContainValueException, BindingException,\r
+                       ServiceException {\r
+               return graph.getValue(subject, binding);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getRelatedValue(Resource subject, Resource relation)\r
+                       throws NoSingleResultException, DoesNotContainValueException,\r
+                       ServiceException {\r
+               return graph.getRelatedValue(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getRelatedValue(Resource subject, Resource relation,\r
+                       Binding binding) throws NoSingleResultException,\r
+                       DoesNotContainValueException, BindingException,\r
+                       ServiceException {\r
+               return graph.getRelatedValue(subject, relation, binding);\r
+       }\r
+\r
+       @Override\r
+       public Resource getPossibleInverse(Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               return graph.getPossibleInverse(relation);\r
+       }\r
+\r
+       @Override\r
+       public Resource getPossibleObject(Resource subject, Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               return graph.getPossibleObject(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public Statement getPossibleStatement(Resource subject,\r
+                       Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               return graph.getPossibleStatement(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public Resource getPossibleType(Resource subject, Resource baseType)\r
+                       throws ServiceException {\r
+               return graph.getPossibleType(subject, baseType);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleValue(Resource subject) throws ServiceException {\r
+               return graph.getPossibleValue(subject);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleValue(Resource subject, Binding binding)\r
+                       throws BindingException, ServiceException {\r
+               return graph.getPossibleValue(subject, binding);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleRelatedValue(Resource subject, Resource relation)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       ServiceException {\r
+               return graph.getPossibleRelatedValue(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Binding binding)\r
+                       throws ManyObjectsForFunctionalRelationException,\r
+                       BindingException, ServiceException {\r
+               return graph.getPossibleRelatedValue(subject, relation, binding);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleAdapter(Resource resource, Class<T> clazz)\r
+                       throws ValidationException, ServiceException {\r
+               return graph.getPossibleAdapter(resource, clazz);\r
+       }\r
+\r
+       @Override\r
+       public <T> T getPossibleUniqueAdapter(Resource resource, Class<T> clazz)\r
+                       throws ValidationException, ServiceException {\r
+               return graph.getPossibleUniqueAdapter(resource, clazz);\r
+       }\r
+\r
+       @Override\r
+       public boolean isInstanceOf(Resource resource, Resource type)\r
+                       throws ServiceException {\r
+               return graph.isInstanceOf(resource, type);\r
+       }\r
+\r
+       @Override\r
+       public boolean isInheritedFrom(Resource resource, Resource type)\r
+                       throws ServiceException {\r
+               return graph.isInheritedFrom(resource, type);\r
+       }\r
+\r
+       @Override\r
+       public boolean isSubrelationOf(Resource resource, Resource relation)\r
+                       throws ServiceException {\r
+               return graph.isSubrelationOf(resource, relation);\r
+       }\r
+\r
+       @Override\r
+       public boolean hasStatement(Resource subject) throws ServiceException {\r
+               return graph.hasStatement(subject);\r
+       }\r
+\r
+       @Override\r
+       public boolean hasStatement(Resource subject, Resource relation)\r
+                       throws ServiceException {\r
+               return graph.hasStatement(subject, relation);\r
+       }\r
+\r
+       @Override\r
+       public boolean hasStatement(Resource subject, Resource relation,\r
+                       Resource object) throws ServiceException {\r
+               return graph.hasStatement(subject, relation, object);\r
+       }\r
+\r
+       @Override\r
+       public boolean hasValue(Resource subject) throws ServiceException {\r
+               return graph.hasValue(subject);\r
+       }\r
+\r
+       @Override\r
+       public Datatype getDataType(Resource subject) throws DatabaseException {\r
+               return graph.getDataType(subject);\r
+       }\r
+\r
+       @Override\r
+       public <T extends Accessor> T getAccessor(Resource subject)\r
+                       throws DatabaseException {\r
+               return graph.getAccessor(subject);\r
+       }\r
+\r
+    @Override\r
+    public RandomAccessBinary getRandomAccessBinary(Resource subject)\r
+            throws DatabaseException {\r
+        return graph.getRandomAccessBinary(subject);\r
+    }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request) throws DatabaseException {\r
+               return graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, AsyncListener<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, SyncListener<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, Listener<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, AsyncProcedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, SyncProcedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(Read<T> request, Procedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request) throws DatabaseException {\r
+               return graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request,\r
+                       AsyncListener<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request, SyncListener<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request, Listener<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request,\r
+                       AsyncProcedure<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request,\r
+                       SyncProcedure<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(AsyncRead<T> request, Procedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       AsyncMultiListener<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       SyncMultiListener<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       MultiListener<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       AsyncMultiProcedure<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       SyncMultiProcedure<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(MultiRead<T> request,\r
+                       MultiProcedure<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       AsyncMultiListener<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       SyncMultiListener<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       MultiListener<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       AsyncMultiProcedure<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       SyncMultiProcedure<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> Collection<T> syncRequest(AsyncMultiRead<T> request,\r
+                       MultiProcedure<T> procedure) throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(ExternalRead<T> request)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(ExternalRead<T> request, Listener<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(ExternalRead<T> request, Procedure<T> procedure)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void syncRequest(Write request) throws DatabaseException {\r
+               graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public void syncRequest(DelayedWrite request) throws DatabaseException {\r
+               graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public void syncRequest(WriteOnly r) throws DatabaseException {\r
+               graph.syncRequest(r);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(WriteResult<T> request)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(DelayedWriteResult<T> request)\r
+                       throws DatabaseException {\r
+               return graph.syncRequest(request);\r
+       }\r
+\r
+       @Override\r
+       public <T> T syncRequest(WriteOnlyResult<T> r) throws DatabaseException {\r
+               return graph.syncRequest(r);\r
+       }\r
+\r
+       @Override\r
+       public void forURI(Resource resource, AsyncListener<String> procedure) {\r
+               graph.forURI(resource, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forURI(Resource resource, SyncListener<String> procedure) {\r
+               graph.forURI(resource, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forURI(Resource resource, Listener<String> procedure) {\r
+               graph.forURI(resource, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forURI(Resource resource, AsyncProcedure<String> procedure) {\r
+               graph.forURI(resource, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forURI(Resource resource, SyncProcedure<String> procedure) {\r
+               graph.forURI(resource, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forURI(Resource resource, Procedure<String> procedure) {\r
+               graph.forURI(resource, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forResource(String id, AsyncListener<Resource> procedure) {\r
+               graph.forResource(id, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forResource(String id, SyncListener<Resource> procedure) {\r
+               graph.forResource(id, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forResource(String id, Listener<Resource> procedure) {\r
+               graph.forResource(id, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forResource(String id, AsyncProcedure<Resource> procedure) {\r
+               graph.forResource(id, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forResource(String id, SyncProcedure<Resource> procedure) {\r
+               graph.forResource(id, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forResource(String id, Procedure<Resource> procedure) {\r
+               graph.forResource(id, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forStatementSet(Resource subject, Resource relation,\r
+                       AsyncSetListener<Statement> procedure) {\r
+               graph.forStatementSet(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forStatementSet(Resource subject, Resource relation,\r
+                       SyncSetListener<Statement> procedure) {\r
+               graph.forStatementSet(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forStatementSet(Resource subject, Resource relation,\r
+                       SetListener<Statement> procedure) {\r
+               graph.forStatementSet(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPredicateSet(Resource subject,\r
+                       AsyncSetListener<Resource> procedure) {\r
+               graph.forPredicateSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPredicateSet(Resource subject,\r
+                       SyncSetListener<Resource> procedure) {\r
+               graph.forPredicateSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPredicateSet(Resource subject,\r
+                       SetListener<Resource> procedure) {\r
+               graph.forPredicateSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPrincipalTypeSet(Resource subject,\r
+                       AsyncSetListener<Resource> procedure) {\r
+               graph.forPrincipalTypeSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPrincipalTypeSet(Resource subject,\r
+                       SyncSetListener<Resource> procedure) {\r
+               graph.forPrincipalTypeSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPrincipalTypeSet(Resource subject,\r
+                       SetListener<Resource> procedure) {\r
+               graph.forPrincipalTypeSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(Resource subject,\r
+                       AsyncListener<Set<Resource>> procedure) {\r
+               graph.forTypes(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(Resource subject,\r
+                       SyncListener<Set<Resource>> procedure) {\r
+               graph.forTypes(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forTypes(Resource subject, Listener<Set<Resource>> procedure) {\r
+               graph.forTypes(subject, procedure);             \r
+       }\r
+\r
+       @Override\r
+       public void forTypes(Resource subject,\r
+                       AsyncProcedure<Set<Resource>> procedure) {\r
+               graph.forTypes(subject, procedure);             \r
+       }\r
+\r
+       @Override\r
+       public void forTypes(Resource subject,\r
+                       SyncProcedure<Set<Resource>> procedure) {\r
+               graph.forTypes(subject, procedure);             \r
+       }\r
+\r
+       @Override\r
+       public void forTypes(Resource subject,\r
+                       Procedure<Set<Resource>> procedure) {\r
+               graph.forTypes(subject, procedure);             \r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(Resource subject,\r
+                       AsyncListener<Set<Resource>> procedure) {\r
+               graph.forSupertypes(subject, procedure);                \r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(Resource subject,\r
+                       SyncListener<Set<Resource>> procedure) {\r
+               graph.forSupertypes(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(Resource subject,\r
+                       Listener<Set<Resource>> procedure) {\r
+               graph.forSupertypes(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(Resource subject,\r
+                       AsyncProcedure<Set<Resource>> procedure) {\r
+               graph.forSupertypes(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(Resource subject,\r
+                       SyncProcedure<Set<Resource>> procedure) {\r
+               graph.forSupertypes(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSupertypes(Resource subject,\r
+                       Procedure<Set<Resource>> procedure) {\r
+               graph.forSupertypes(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleSuperrelation(Resource subject,\r
+                       AsyncProcedure<Resource> procedure) {\r
+               graph.forPossibleSuperrelation(subject, procedure);             \r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(Resource subject,\r
+                       AsyncListener<Set<Resource>> procedure) {\r
+               graph.forSuperrelations(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(Resource subject,\r
+                       SyncListener<Set<Resource>> procedure) {\r
+               graph.forSuperrelations(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(Resource subject,\r
+                       Listener<Set<Resource>> procedure) {\r
+               graph.forSuperrelations(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(Resource subject,\r
+                       AsyncProcedure<Set<Resource>> procedure) {\r
+               graph.forSuperrelations(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(Resource subject,\r
+                       SyncProcedure<Set<Resource>> procedure) {\r
+               graph.forSuperrelations(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSuperrelations(Resource subject,\r
+                       Procedure<Set<Resource>> procedure) {\r
+               graph.forSuperrelations(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forObjectSet(Resource subject, Resource relation,\r
+                       AsyncSetListener<Resource> procedure) {\r
+               graph.forObjectSet(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forObjectSet(Resource subject, Resource relation,\r
+                       SyncSetListener<Resource> procedure) {\r
+               graph.forObjectSet(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forObjectSet(Resource subject, Resource relation,\r
+                       SetListener<Resource> procedure) {\r
+               graph.forObjectSet(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(Resource relation,\r
+                       SyncListener<Resource> procedure) {\r
+               graph.forInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(Resource relation, Listener<Resource> procedure) {\r
+               graph.forInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(Resource relation,\r
+                       AsyncProcedure<Resource> procedure) {\r
+               graph.forInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(Resource relation,\r
+                       SyncProcedure<Resource> procedure) {\r
+               graph.forInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forInverse(Resource relation, Procedure<Resource> procedure) {\r
+               graph.forInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(Resource subject, Resource relation,\r
+                       AsyncListener<Resource> procedure) {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(Resource subject, Resource relation,\r
+                       SyncListener<Resource> procedure) {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(Resource subject, Resource relation,\r
+                       Listener<Resource> procedure) {\r
+               graph.forSingleObject(subject, relation, procedure);            \r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(Resource subject, Resource relation,\r
+                       AsyncProcedure<Resource> procedure) {\r
+               graph.forSingleObject(subject, relation, procedure);            \r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(Resource subject, Resource relation,\r
+                       SyncProcedure<Resource> procedure) {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleObject(Resource subject, Resource relation,\r
+                       Procedure<Resource> procedure) {\r
+               graph.forSingleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(Resource subject, Resource relation,\r
+                       AsyncListener<Statement> procedure) {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(Resource subject, Resource relation,\r
+                       SyncListener<Statement> procedure) {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(Resource subject, Resource relation,\r
+                       Listener<Statement> procedure) {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(Resource subject, Resource relation,\r
+                       AsyncProcedure<Statement> procedure) {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(Resource subject, Resource relation,\r
+                       SyncProcedure<Statement> procedure) {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleStatement(Resource subject, Resource relation,\r
+                       Procedure<Statement> procedure) {\r
+               graph.forSingleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject,\r
+                       AsyncListener<Resource> procedure) {\r
+               graph.forSingleType(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject,\r
+                       SyncListener<Resource> procedure) {\r
+               graph.forSingleType(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject, Listener<Resource> procedure) {\r
+               graph.forSingleType(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject,\r
+                       AsyncProcedure<Resource> procedure) {\r
+               graph.forSingleType(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject,\r
+                       SyncProcedure<Resource> procedure) {\r
+               graph.forSingleType(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject,\r
+                       Procedure<Resource> procedure) {\r
+               graph.forSingleType(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject, Resource baseType,\r
+                       AsyncListener<Resource> procedure) {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject, Resource baseType,\r
+                       SyncListener<Resource> procedure) {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject, Resource baseType,\r
+                       Listener<Resource> procedure) {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject, Resource baseType,\r
+                       AsyncProcedure<Resource> procedure) {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject, Resource baseType,\r
+                       SyncProcedure<Resource> procedure) {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forSingleType(Resource subject, Resource baseType,\r
+                       Procedure<Resource> procedure) {\r
+               graph.forSingleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, AsyncListener<T> procedure) {\r
+               graph.forValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, SyncListener<T> procedure) {\r
+               graph.forValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, Listener<T> procedure) {\r
+               graph.forValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, AsyncProcedure<T> procedure) {\r
+               graph.forValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, SyncProcedure<T> procedure) {\r
+               graph.forValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, Procedure<T> procedure) {\r
+               graph.forValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, Binding binding,\r
+                       AsyncListener<T> procedure) {\r
+               graph.forValue(subject, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, Binding binding,\r
+                       SyncListener<T> procedure) {\r
+               graph.forValue(subject, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, Binding binding,\r
+                       Listener<T> procedure) {\r
+               graph.forValue(subject, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, Binding binding,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.forValue(subject, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, Binding binding,\r
+                       SyncProcedure<T> procedure) {\r
+               graph.forValue(subject, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forValue(Resource subject, Binding binding,\r
+                       Procedure<T> procedure) {\r
+               graph.forValue(subject, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       AsyncListener<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       SyncListener<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       Listener<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       SyncProcedure<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       Procedure<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       Binding binding, AsyncListener<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       Binding binding, SyncListener<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       Binding binding, Listener<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       Binding binding, AsyncProcedure<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       Binding binding, SyncProcedure<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forRelatedValue(Resource subject, Resource relation,\r
+                       Binding binding, Procedure<T> procedure) {\r
+               graph.forRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(Resource resource, Class<T> clazz,\r
+                       AsyncListener<T> procedure) {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(Resource resource, Class<T> clazz,\r
+                       SyncListener<T> procedure) {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(Resource resource, Class<T> clazz,\r
+                       Listener<T> procedure) {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(Resource resource, Class<T> clazz,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(Resource resource, Class<T> clazz,\r
+                       SyncProcedure<T> procedure) {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forUniqueAdapted(Resource resource, Class<T> clazz,\r
+                       Procedure<T> procedure) {\r
+               graph.forUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(Resource relation,\r
+                       AsyncListener<Resource> procedure) {\r
+               graph.forPossibleInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(Resource relation,\r
+                       SyncListener<Resource> procedure) {\r
+               graph.forPossibleInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(Resource relation,\r
+                       Listener<Resource> procedure) {\r
+               graph.forPossibleInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(Resource relation,\r
+                       AsyncProcedure<Resource> procedure) {\r
+               graph.forPossibleInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(Resource relation,\r
+                       SyncProcedure<Resource> procedure) {\r
+               graph.forPossibleInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleInverse(Resource relation,\r
+                       Procedure<Resource> procedure) {\r
+               graph.forPossibleInverse(relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(Resource subject, Resource relation,\r
+                       AsyncListener<Resource> procedure) {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(Resource subject, Resource relation,\r
+                       SyncListener<Resource> procedure) {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(Resource subject, Resource relation,\r
+                       Listener<Resource> procedure) {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(Resource subject, Resource relation,\r
+                       AsyncProcedure<Resource> procedure) {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(Resource subject, Resource relation,\r
+                       SyncProcedure<Resource> procedure) {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleObject(Resource subject, Resource relation,\r
+                       Procedure<Resource> procedure) {\r
+               graph.forPossibleObject(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(Resource subject, Resource relation,\r
+                       AsyncListener<Statement> procedure) {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(Resource subject, Resource relation,\r
+                       SyncListener<Statement> procedure) {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(Resource subject, Resource relation,\r
+                       Listener<Statement> procedure) {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(Resource subject, Resource relation,\r
+                       AsyncProcedure<Statement> procedure) {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(Resource subject, Resource relation,\r
+                       SyncProcedure<Statement> procedure) {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleStatement(Resource subject, Resource relation,\r
+                       Procedure<Statement> procedure) {\r
+               graph.forPossibleStatement(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(Resource subject, Resource baseType,\r
+                       AsyncListener<Resource> procedure) {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(Resource subject, Resource baseType,\r
+                       SyncListener<Resource> procedure) {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(Resource subject, Resource baseType,\r
+                       Listener<Resource> procedure) {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(Resource subject, Resource baseType,\r
+                       AsyncProcedure<Resource> procedure) {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(Resource subject, Resource baseType,\r
+                       SyncProcedure<Resource> procedure) {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forPossibleType(Resource subject, Resource baseType,\r
+                       Procedure<Resource> procedure) {\r
+               graph.forPossibleType(subject, baseType, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject,\r
+                       AsyncListener<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject,\r
+                       SyncListener<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject, Listener<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject,\r
+                       SyncProcedure<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject,\r
+                       Procedure<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject, Binding binding,\r
+                       AsyncListener<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject, Binding binding,\r
+                       SyncListener<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject, Binding binding,\r
+                       Listener<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject, Binding binding,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject, Binding binding,\r
+                       SyncProcedure<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleValue(Resource subject, Binding binding,\r
+                       Procedure<T> procedure) {\r
+               graph.forPossibleValue(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, AsyncListener<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, SyncListener<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Listener<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, AsyncProcedure<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, SyncProcedure<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Procedure<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Binding binding, AsyncListener<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Binding binding, SyncListener<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Binding binding, Listener<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Binding binding, AsyncProcedure<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Binding binding, SyncProcedure<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleRelatedValue(Resource subject,\r
+                       Resource relation, Binding binding, Procedure<T> procedure) {\r
+               graph.forPossibleRelatedValue(subject, relation, binding, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(Resource resource, Class<T> clazz,\r
+                       AsyncListener<T> procedure) {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(Resource resource, Class<T> clazz,\r
+                       SyncListener<T> procedure) {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(Resource resource, Class<T> clazz,\r
+                       Listener<T> procedure) {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(Resource resource, Class<T> clazz,\r
+                       AsyncProcedure<T> procedure) {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(Resource resource, Class<T> clazz,\r
+                       SyncProcedure<T> procedure) {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleAdapted(Resource resource, Class<T> clazz,\r
+                       Procedure<T> procedure) {\r
+               graph.forPossibleAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(Resource resource,\r
+                       Class<T> clazz, AsyncListener<T> procedure) {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(Resource resource,\r
+                       Class<T> clazz, SyncListener<T> procedure) {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(Resource resource,\r
+                       Class<T> clazz, Listener<T> procedure) {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(Resource resource,\r
+                       Class<T> clazz, AsyncProcedure<T> procedure) {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(Resource resource,\r
+                       Class<T> clazz, SyncProcedure<T> procedure) {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public <T> void forPossibleUniqueAdapted(Resource resource,\r
+                       Class<T> clazz, Procedure<T> procedure) {\r
+               graph.forPossibleUniqueAdapted(resource, clazz, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(Resource resource, Resource type,\r
+                       AsyncListener<Boolean> procedure) {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(Resource resource, Resource type,\r
+                       SyncListener<Boolean> procedure) {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(Resource resource, Resource type,\r
+                       Listener<Boolean> procedure) {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(Resource resource, Resource type,\r
+                       AsyncProcedure<Boolean> procedure) {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(Resource resource, Resource type,\r
+                       SyncProcedure<Boolean> procedure) {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInstanceOf(Resource resource, Resource type,\r
+                       Procedure<Boolean> procedure) {\r
+               graph.forIsInstanceOf(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(Resource resource, Resource type,\r
+                       AsyncListener<Boolean> procedure) {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(Resource resource, Resource type,\r
+                       SyncListener<Boolean> procedure) {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(Resource resource, Resource type,\r
+                       Listener<Boolean> procedure) {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(Resource resource, Resource type,\r
+                       AsyncProcedure<Boolean> procedure) {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(Resource resource, Resource type,\r
+                       SyncProcedure<Boolean> procedure) {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsInheritedFrom(Resource resource, Resource type,\r
+                       Procedure<Boolean> procedure) {\r
+               graph.forIsInheritedFrom(resource, type, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(Resource resource, Resource relation,\r
+                       AsyncListener<Boolean> procedure) {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(Resource resource, Resource relation,\r
+                       SyncListener<Boolean> procedure) {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(Resource resource, Resource relation,\r
+                       Listener<Boolean> procedure) {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(Resource resource, Resource relation,\r
+                       AsyncProcedure<Boolean> procedure) {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(Resource resource, Resource relation,\r
+                       SyncProcedure<Boolean> procedure) {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forIsSubrelationOf(Resource resource, Resource relation,\r
+                       Procedure<Boolean> procedure) {\r
+               graph.forIsSubrelationOf(resource, relation, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(Resource subject,\r
+                       AsyncMultiListener<Resource> procedure) {\r
+               graph.forOrderedSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(Resource subject,\r
+                       SyncMultiListener<Resource> procedure) {\r
+               graph.forOrderedSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(Resource subject,\r
+                       MultiListener<Resource> procedure) {\r
+               graph.forOrderedSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(Resource subject,\r
+                       AsyncMultiProcedure<Resource> procedure) {\r
+               graph.forOrderedSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(Resource subject,\r
+                       SyncMultiProcedure<Resource> procedure) {\r
+               graph.forOrderedSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public void forOrderedSet(Resource subject,\r
+                       MultiProcedure<Resource> procedure) {\r
+               graph.forOrderedSet(subject, procedure);\r
+       }\r
+\r
+       @Override\r
+       public int thread() {\r
+               return graph.thread();\r
+       }\r
+\r
+       @Override\r
+       public Session getSession() {\r
+               return graph.getSession();\r
+       }\r
+\r
+       @Override\r
+       public Resource getBuiltin(String id) throws ResourceNotFoundException,\r
+                       ServiceException {\r
+               return graph.getBuiltin(id);\r
+       }\r
+       \r
+       @Override\r
+       public VirtualGraph getProvider() {\r
+               return graph.getProvider();\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/DistanceComparator.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/DistanceComparator.java
new file mode 100644 (file)
index 0000000..7ea8dc8
--- /dev/null
@@ -0,0 +1,28 @@
+package org.simantics.interop.mapping.data;\r
+\r
+import java.util.Comparator;\r
+\r
+public class DistanceComparator<T> implements Comparator<GraphNode<T>> {\r
+\r
+       private String rel;\r
+       private String inv;\r
+       \r
+       public DistanceComparator(String rel, String inv) {\r
+               this.rel = rel;\r
+               this.inv = inv;\r
+       }\r
+       \r
+       @Override\r
+       public int compare(GraphNode<T> arg0, GraphNode<T> arg1) {\r
+               int dist = arg0.distanceTo(arg1, rel, inv);\r
+               if (dist < 0) {\r
+                       dist = arg0.distanceTo(arg1, inv, rel);\r
+                       if (dist < 0)\r
+                               return 0;\r
+                       return -dist;\r
+               } else {\r
+                       return dist;\r
+               }\r
+               \r
+       }\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/GraphNode.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/GraphNode.java
new file mode 100644 (file)
index 0000000..c775e8b
--- /dev/null
@@ -0,0 +1,820 @@
+package org.simantics.interop.mapping.data;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.Set;\r
+\r
+import org.simantics.interop.mapping.Logger;\r
+import org.simantics.utils.datastructures.hints.HintContext;\r
+\r
+\r
+/**\r
+ * \r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ * @param <T>\r
+ */\r
+public class GraphNode<T> extends HintContext {\r
+       protected T data;\r
+       private List<Link<T>> nodes = new ArrayList<Link<T>>();\r
+\r
+       private boolean disposed = false;\r
+       \r
+       public GraphNode(T data) {\r
+               this.data = data;\r
+       }\r
+       \r
+       /**\r
+        * Returns data.\r
+        * @return\r
+        */\r
+       public T getData() {\r
+               return data;\r
+       }\r
+\r
+       \r
+       @Override\r
+    public void setHint(Key key, Object value) {\r
+               _checkDisposed();\r
+               if (value == null)\r
+                       return; \r
+               super.setHint(key, value);\r
+       }\r
+       \r
+       \r
+       \r
+       \r
+       /**\r
+        * Adds link to the other node.\r
+        * @param relationName name of the link from this node to the other node.\r
+        * @param inverseRelationName nam,e of the link from the other node to this node.\r
+        * @param node the other node.\r
+        * @return the created link. Returns null if the link cannot be created.\r
+        */\r
+       public Link<T> addLink(String relationName, String inverseRelationName,GraphNode<T> node) {\r
+               _checkDisposed();\r
+               Logger.defaultLogInfo("Node link " + data + " " + node.data + " " + relationName + " " + inverseRelationName +"\n");\r
+               if(containsLink(relationName, node) && node.containsLink(inverseRelationName, this)) {\r
+                       Logger.defaultLogWarning("Node " + getData() + " has already given child " +  node.getData() + " ,with name " + relationName + " / " + inverseRelationName);\r
+                       return null;\r
+               }\r
+               Link<T> rel = _addLink(relationName,node);\r
+               Link<T> inv = node._addLink(inverseRelationName,this);\r
+               rel.setInverseLink(inv);\r
+               inv.setMainLink(rel);\r
+               return rel;\r
+       }\r
+       \r
+       /**\r
+        * Adds link to the other node, with <pre>null</pre> link name from the other node to this node.\r
+        * @param relationName\r
+        * @param node name of the link from this node to the other node\r
+        * @return the created link. Returns null if the link cannot be created.\r
+        */\r
+       public Link<T> addLink(String relationName,GraphNode<T> node) {\r
+               _checkDisposed();\r
+               if(containsLink(relationName, node)) {\r
+                       Logger.defaultLogWarning("Node " + getData() + " has already given child " +  node.getData() + " ,with name " + relationName );\r
+                       return null;\r
+               }\r
+               Link<T> rel = _addLink(relationName,node);\r
+               Link<T> inv = node._addLink(null,this);\r
+               rel.setInverseLink(inv);\r
+               inv.setMainLink(rel);\r
+               return rel;\r
+       }\r
+       \r
+       /**\r
+        * Adds link to the other node, with copying link properties from given link.\r
+        * @param link\r
+        * @param node name of the link from this node to the other node\r
+        * @return the created link. Returns null if the link cannot be created.\r
+        */\r
+       public Link<T> addLink(Link<T> link ,GraphNode<T> node) {\r
+               _checkDisposed();\r
+               if(containsLink(link.getName(), node) && node.containsLink(link.getInverseName(), this)) {\r
+                       Logger.defaultLogWarning("Node " + getData() + " has already given child " +  node.getData() + " ,with name " + link.getName() + " / " + link.getInverseName());\r
+                       return null;\r
+               }\r
+               Link<T> rel = _addLink(link.getName(),node);\r
+               Link<T> inv = node._addLink(link.getInverseName(),this);\r
+               rel.setInverseLink(inv);\r
+               inv.setMainLink(rel);\r
+               rel.setHints(link.getHints());\r
+               inv.setHints(link.getInverse().getHints());\r
+               return rel;\r
+       }\r
+       \r
+       protected Link<T> _addLink(String relation,  GraphNode<T> node) {\r
+               Link<T> link = new Link<T>(this, relation,node);\r
+               nodes.add(link);\r
+               return link;\r
+       }\r
+       \r
+       protected Link<T> _removeLink(String relation,String inverse, GraphNode<T> node) {\r
+               for (int i = 0; i < nodes.size(); i++) {\r
+                       Link<T> link = nodes.get(i);\r
+                       if (node.equals(link.to()) && equals(relation,link.getName()) && equals(inverse,link.getInverseName())) {\r
+                               return nodes.remove(i);\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       protected Link<T> _removeLink(String relation) {\r
+               for (int i = 0; i < nodes.size(); i++) {\r
+                       Link<T> link = nodes.get(i);\r
+                       if (equals(relation,link.getName())) {\r
+                               return nodes.remove(i);\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       protected Link<T> _removeLink(String relation, String inverse) {\r
+               for (int i = 0; i < nodes.size(); i++) {\r
+                       Link<T> link = nodes.get(i);\r
+                       if (equals(relation,link.getName()) && equals(inverse,link.getInverseName())) {\r
+                               return nodes.remove(i);\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       protected Link<T> _removeLink(String relation, GraphNode<T> node) {\r
+               for (int i = 0; i < nodes.size(); i++) {\r
+                       Link<T> link = nodes.get(i);\r
+                       if (node.equals(link.to()) && equals(relation,link.getName())) {\r
+                               return nodes.remove(i);\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       protected Link<T> _removeLink(GraphNode<T> node) {\r
+               for (int i = 0; i < nodes.size(); i++ ) {\r
+                       Link<T> link = nodes.get(i);\r
+                       if (node.equals(link.to())) {\r
+                               return nodes.remove(i);\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       protected boolean _removeLink(Link<T> link) {\r
+               return nodes.remove(link);\r
+       }\r
+       \r
+       /**\r
+        * Removes the given link.\r
+        * @param link\r
+        * @return true if the link was removed.\r
+        */\r
+       public boolean removeLink(Link<T> link) {\r
+               _checkDisposed();\r
+               if (_removeLink(link)) {\r
+                       if (link.hasInverse()) {\r
+                               link.to()._removeLink(link.getInverse());\r
+                       }\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+       \r
+       /**\r
+        * Removes a link (or multiple links).\r
+        * @param relation the name of the link from this node.\r
+        * @return true if a link was removed.\r
+        */\r
+       public boolean removeLink(String relation) {\r
+               _checkDisposed();\r
+               boolean deleted = false;\r
+               while (true) {\r
+                       Link<T> removed = _removeLink(relation);\r
+                       if (removed == null)\r
+                               break;\r
+                       if (removed.hasInverse()) {\r
+                               removed.to()._removeLink(removed.getInverse());\r
+                               deleted = true;\r
+                       }\r
+               }\r
+               return deleted;\r
+       }\r
+       \r
+       /**\r
+        * Removes a link (or multiple links).\r
+        * @param relation the name of the link from this node.\r
+        * @return true if the link was removed.\r
+        */\r
+       public boolean removeLink(String relation, String inverse) {\r
+               _checkDisposed();\r
+               boolean deleted = false;\r
+               while (true) {\r
+                       Link<T> removed = _removeLink(relation, inverse);\r
+                       if (removed == null)\r
+                               break;\r
+                       if (removed.hasInverse()) {\r
+                               removed.to()._removeLink(removed.getInverse());\r
+                               deleted = true;\r
+                       }\r
+               }\r
+               return deleted;\r
+       }\r
+\r
+       /**\r
+        * Removes a link.\r
+        * @param relation the name of the link from this node to the other node.\r
+        * @param node the other node.\r
+        * @return true if the link was removed.\r
+        */\r
+       public boolean removeLink(String relation, GraphNode<T> node) {\r
+               _checkDisposed();\r
+               \r
+               boolean deleted = false;\r
+               while (true) {\r
+                       Link<T> removed = _removeLink(relation, node);\r
+                       if (removed == null)\r
+                               break;\r
+                       if (removed.hasInverse()) {\r
+                               removed.to()._removeLink(removed.getInverse());\r
+                               deleted = true;\r
+                       }\r
+               }\r
+               return deleted;\r
+       }\r
+       \r
+       /**\r
+        * Removes all links from this node to the other node.\r
+        * @param node the other node.\r
+        * @return\r
+        */\r
+       public boolean removeLink(GraphNode<T> node) {\r
+               _checkDisposed();\r
+               boolean deleted = false;\r
+               while (true) {\r
+                       Link<T> removed = _removeLink(node);\r
+                       if (removed == null)\r
+                               break;\r
+                       if (removed.hasInverse()) {\r
+                               removed.to()._removeLink(removed.getInverse());\r
+                               deleted = true;\r
+                       }\r
+               }\r
+               return deleted;\r
+       }\r
+       \r
+       /**\r
+        * Removes a link.\r
+        * @param relation the name of the link from this node to the other node.\r
+        * @param inverse the name of the link from the other node to this node.\r
+        * @param node the other node.\r
+        * @return true if the link was removed.\r
+        */\r
+       public boolean removeLink(String relation, String inverse, GraphNode<T> node) {\r
+               _checkDisposed();\r
+               Link<T> removed = _removeLink(relation, inverse, node);\r
+               if (removed != null && removed.hasInverse()) {\r
+                       removed.to()._removeLink(removed.getInverse());\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+       \r
+       public boolean containsLink(GraphNode<T> node) {\r
+               _checkDisposed();\r
+               for (Link<T> link : nodes) {\r
+                       if (node.equals(link.to()))\r
+                               return true;\r
+               }\r
+               return false;\r
+       }\r
+       \r
+       public boolean containsLink(String relationName, GraphNode<T> node) {\r
+               _checkDisposed();\r
+               if (relationName == null)\r
+                       return false;\r
+               for (Link<T> link : nodes) {\r
+                       if (node.equals(link.to()) && equals(relationName,link.getName()))\r
+                               return true;\r
+               }\r
+               return false;\r
+       }\r
+       \r
+       public boolean containsLink(String relationName, String inverseName, GraphNode<T> node) {\r
+               _checkDisposed();\r
+               for (Link<T> link : nodes) {\r
+                       if (node.equals(link.to()) && equals(relationName,link.getName()) && equals(inverseName,link.getInverseName()))\r
+                               return true;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       public Collection<Link<T>> getLinks() {\r
+               _checkDisposed();\r
+               Collection<Link<T>> coll = new ArrayList<Link<T>>(nodes);\r
+               return coll;\r
+       }\r
+       \r
+       public Collection<GraphNode<T>> getNodes(String rel) {\r
+               _checkDisposed();\r
+               Collection<GraphNode<T>> result = new ArrayList<GraphNode<T>>();\r
+\r
+               for (Link<T> link : nodes) {\r
+                       if (equals(rel,link.getName()))\r
+                               result.add(link.to());\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       public Collection<Link<T>> getLinks(String rel) {\r
+               _checkDisposed();\r
+               Collection<Link<T>> result = new ArrayList<Link<T>>();\r
+\r
+               for (Link<T> link : nodes) {\r
+                       if (equals(rel,link.getName()))\r
+                               result.add(link);\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       public Collection<Link<T>> getLinks(String rel, GraphNode<T> node) {\r
+               _checkDisposed();\r
+               Collection<Link<T>> result = new ArrayList<Link<T>>();\r
+\r
+               for (Link<T> link : nodes) {\r
+                       if (equals(rel,link.getName()) && link.to().equals(node))\r
+                               result.add(link);\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       public Collection<Link<T>> getLinks(String rel, String inverse) {\r
+               _checkDisposed();\r
+               Collection<Link<T>> result = new ArrayList<Link<T>>();\r
+\r
+               for (Link<T> link : nodes) {\r
+                       if (equals(rel,link.getName()) && equals(inverse, link.getInverseName()))\r
+                               result.add(link);\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       public Collection<Link<T>> getLinks(String rel, String inverse, GraphNode<T> node) {\r
+               _checkDisposed();\r
+               Collection<Link<T>> result = new ArrayList<Link<T>>();\r
+\r
+               for (Link<T> link : nodes) {\r
+                       if (equals(rel,link.getName()) && equals(inverse, link.getInverseName()) && link.to().equals(node))\r
+                               result.add(link);\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       public Collection<GraphNode<T>> getNodesWithInv(String inv) {\r
+               _checkDisposed();\r
+               Collection<GraphNode<T>> result = new ArrayList<GraphNode<T>>();\r
+\r
+               for (Link<T> link : nodes) {\r
+                       if (equals(inv,link.getInverseName()))\r
+                               result.add(link.to());\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       public Collection<GraphNode<T>> getNodes(String rel, String inv) {\r
+               _checkDisposed();\r
+               Collection<GraphNode<T>> result = new ArrayList<GraphNode<T>>();\r
+\r
+               for (Link<T> link : nodes) {\r
+                       if (equals(rel,link.getName()) && equals(inv,link.getInverseName()))\r
+                               result.add(link.to());\r
+               }\r
+\r
+               return result;\r
+       }\r
+       \r
+       public static boolean equals(String s1, String s2) {\r
+               if (s1 != null)\r
+                       return s1.equals(s2);\r
+               if (s2 != null)\r
+                       return s2.equals(s1);\r
+               return true; // both null\r
+       }\r
+       \r
+       \r
+       /**\r
+        * Returns links from this node to the given node.\r
+        * @param node\r
+        * @return\r
+        */\r
+       public Collection<Link<T>> getLinks(GraphNode<T> node) {\r
+               _checkDisposed();\r
+               Collection<Link<T>> result = new ArrayList<Link<T>>();\r
+               for (Link<T> link : nodes) {\r
+                       if (link.to().equals(node))\r
+                               result.add(link);\r
+               }\r
+               return result;\r
+       }\r
+       \r
+       /**\r
+        * Returns names of links from this node to the given node. Does not return null names.\r
+        * @param node\r
+        * @return\r
+        */\r
+       public Collection<String> getRelations(GraphNode<T> node) {\r
+               _checkDisposed();\r
+               Collection<String> result = new ArrayList<String>();\r
+               for (Link<T> link : nodes) {\r
+                       if (link.to().equals(node) && link.getName() != null)\r
+                               result.add(link.getName());\r
+               }\r
+               return result;\r
+       }\r
+       \r
+       /**\r
+        * Returns links from given node to this node.\r
+        * @param node\r
+        * @return\r
+        */\r
+       public Collection<Link<T>> getInverseLinks(GraphNode<T> node) {\r
+               _checkDisposed();\r
+               Collection<Link<T>> result = new ArrayList<Link<T>>();\r
+               for (Link<T> link : nodes) {\r
+                       if (link.to().equals(node))\r
+                               result.add(link.getInverse());\r
+               }\r
+               return result;\r
+       }\r
+       \r
+       /**\r
+        * Returns names of links from given node to this node. Does not return null names.\r
+        * @param node\r
+        * @return\r
+        */\r
+       public Collection<String> getInverses(GraphNode<T> node) {\r
+               _checkDisposed();\r
+               Collection<String> result = new ArrayList<String>();\r
+               for (Link<T> link : nodes) {\r
+                       if (link.to().equals(node) && link.getInverseName() != null)\r
+                               result.add(link.getInverseName());\r
+               }\r
+               return result;\r
+       }\r
+       \r
+       \r
+       \r
+       @Override\r
+       public int hashCode() {\r
+               return data.hashCode();\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (!arg0.getClass().equals(getClass()))\r
+                       return false;\r
+               GraphNode<?> other = (GraphNode<?>)arg0;\r
+               if (this == other)\r
+                       return true;\r
+               if (this.data == null || other.data == null)\r
+                       return false;\r
+               if (!data.equals(other.data))\r
+                       return false;\r
+\r
+               return true;\r
+       }\r
+       \r
+       /**\r
+        * Merges given nodes to new node. \r
+        * Does not copy hints!\r
+        * @param other\r
+        */\r
+       public GraphNode<T> merge(GraphNode<T> other, T mergedData) {\r
+               _checkDisposed();\r
+               GraphNode<T> mergedNode = new GraphNode<T>(mergedData);\r
+               copyLinks(this, mergedNode);\r
+               copyLinks(other, mergedNode);\r
+               \r
+               //mergedNode.setHints(other.getHints());\r
+               //mergedNode.setHints(this.getHints());\r
+               \r
+               this.destroy();\r
+               other.destroy();\r
+               \r
+               return mergedNode;\r
+       }\r
+       \r
+       \r
+       \r
+       \r
+       \r
+       /**\r
+        * Copies a link to other node.\r
+        * @param from the node containing original link\r
+        * @param to the node where link is copied to\r
+        * @param l the link that is copied.\r
+        * @return created link, if copy is successful. Otherwise returns null.\r
+        */\r
+       public static <T> Link<T> copyLink(GraphNode<T> from, GraphNode<T> to, Link<T> l) {\r
+               if (l.from() != from)\r
+                       throw new IllegalArgumentException("Link is not starting from " + from + " node.");\r
+               if (l.to() == to)\r
+                       return null;\r
+               if (to.containsLink(l.getName(), l.getInverseName(),l.to()))\r
+                       return null;\r
+               if (l.isMain()) {\r
+                       Link<T> newLink = to.addLink(l.getName(),l.getInverseName(),l.to());\r
+                       if (newLink != null) {\r
+                               newLink.setHints(l.getHints());\r
+                               newLink.getInverse().setHints(l.getInverse().getHints());\r
+                               return newLink;\r
+                       } else {\r
+                               return null;\r
+                       }\r
+               } else {\r
+                       Link<T> newLink = l.to().addLink(l.getInverseName(), l.getName(),to);\r
+                       if (newLink != null) {\r
+                               newLink.setHints(l.getInverse().getHints());\r
+                               newLink.getInverse().setHints(l.getHints());\r
+                               return newLink.getInverse();\r
+                       } else {\r
+                               return null;\r
+                       }\r
+               }       \r
+               \r
+       }\r
+       \r
+       /**\r
+        * Copies a link to other node, but inverts its direction.\r
+        * @param from the node containing original link\r
+        * @param to the node where link is copied to\r
+        * @param l the link that is copied.\r
+        * @return created link, if copy is successful. Otherwise returns null.\r
+        */\r
+       public static <T> Link<T> copyLinkInverse(GraphNode<T> from, GraphNode<T> to, Link<T> l) {\r
+               if (l.from() != from)\r
+                       throw new IllegalArgumentException("Link is not starting from " + from + " node.");\r
+               if (l.to() == to)\r
+                       return null;\r
+               if (to.containsLink(l.getInverseName(), l.getName(),l.to()))\r
+                       return null;\r
+               if (l.isMain()) {\r
+                       Link<T> newLink = l.to().addLink(l.getName(),l.getInverseName(),to);\r
+                       if (newLink != null) {\r
+                               newLink.setHints(l.getHints());\r
+                               newLink.getInverse().setHints(l.getInverse().getHints());\r
+                               return newLink;\r
+                       } else {\r
+                               return null;\r
+                       }\r
+               } else {\r
+                       Link<T> newLink = to.addLink(l.getInverseName(), l.getName(),l.to());\r
+                       if (newLink != null) {\r
+                               newLink.setHints(l.getInverse().getHints());\r
+                               newLink.getInverse().setHints(l.getHints());\r
+                               return newLink.getInverse();\r
+                       } else {\r
+                               return null;\r
+                       }\r
+               }       \r
+               \r
+       }\r
+\r
+       public static <T> void copyLinks(GraphNode<T> from, GraphNode<T> to, Collection<Link<T>> links) {\r
+               for (Link<T> l : links) {\r
+                       copyLink(from, to, l);\r
+               }\r
+       }\r
+\r
+       \r
+       public static <T> void copyLinks(GraphNode<T> from, GraphNode<T> to) {\r
+               for (Link<T> l : from.getLinks()) {\r
+                       copyLink(from, to, l);\r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Copies a link to other node and removes the original link. If move is not successful, the original link is not removed.\r
+        * @param from the node containing original link\r
+        * @param to the node where link is copied to\r
+        * @param l the link that is moved.\r
+        * @return created link, if move is successful. Otherwise returns null. \r
+        */\r
+       public static <T> Link<T> moveLink(GraphNode<T> from, GraphNode<T> to, Link<T> l) {\r
+               Link<T> newLink = copyLink(from, to, l);\r
+               if (newLink != null) {\r
+                       from.removeLink(l);\r
+                       return newLink;\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       public static <T> void moveLinks(GraphNode<T> from, GraphNode<T> to, Collection<Link<T>> links) {\r
+               for (Link<T> l : links) {\r
+                       Link<T> newLink = copyLink(from, to, l);\r
+                       if (newLink != null) {\r
+                               from.removeLink(l);\r
+                       }       \r
+               }\r
+       }\r
+       \r
+       public static <T> void moveLinkInverses(GraphNode<T> from, GraphNode<T> to, Collection<Link<T>> links) {\r
+               for (Link<T> l : links) {\r
+                       Link<T> newLink = copyLinkInverse(from, to, l);\r
+                       if (newLink != null) {\r
+                               from.removeLink(l);\r
+                       }       \r
+               }\r
+       }\r
+       \r
+       public static <T> void moveLinks(GraphNode<T> from, GraphNode<T> to) {\r
+               for (Link<T> l : from.getLinks()) {\r
+                       Link<T> newLink = copyLink(from, to, l);\r
+                       if (newLink != null) {\r
+                               from.removeLink(l);\r
+                       }       \r
+               }\r
+       }\r
+       \r
+       /**\r
+        * Replaces a link with a link going first to given node, and the to the original destination.\r
+        * The link names and hints are copied to the created links.\r
+        * \r
+        * Example: link is 'a' -> 'b'. With insert attribute 'c', the result is 'a' -> 'c' -> 'b'.\r
+        *   \r
+        * @param link\r
+        * @param insert\r
+        * @return Array containing created links (2).\r
+        */\r
+       @SuppressWarnings("unchecked")\r
+       public static <T> Link<T>[] insert(Link<T> link, GraphNode<T> insert) {\r
+               GraphNode<T> a = link.from();\r
+               Link<T> c_b = moveLink(a, insert, link);\r
+               Link<T> a_c = a.addLink(c_b, insert);\r
+               return new Link[]{a_c,c_b};\r
+       }\r
+\r
+       \r
+       \r
+       /**\r
+        * Finds all nodes that have the same relations to the same nodes as this node. \r
+        * @return\r
+        */\r
+       public Collection<GraphNode<T>> getFullSimilars() {\r
+               _checkDisposed();\r
+               Collection<GraphNode<T>> result = new ArrayList<GraphNode<T>>();\r
+               Set<GraphNode<T>> potential = new HashSet<GraphNode<T>>();\r
+               for (Link<T> link : nodes) {\r
+                       for (Link<T> link2 : link.to().nodes) {\r
+                               if (!link2.to().equals(this))\r
+                                       potential.add(link2.to());\r
+                       }\r
+               }\r
+               for (GraphNode<T> node : potential) {\r
+                       if (node.nodes.containsAll(nodes))\r
+                               result.add(node);\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+       /**\r
+        * Finds all nodes that have at least one similar relation to the same nodes as this node. \r
+        * @return\r
+        */\r
+       public Collection<GraphNode<T>> getSemiSimilars() {\r
+               _checkDisposed();\r
+               Collection<GraphNode<T>> result = new ArrayList<GraphNode<T>>();\r
+               Set<GraphNode<T>> potential = new HashSet<GraphNode<T>>();\r
+               for (Link<T> link : nodes) {\r
+                       for (Link<T> link2 : link.to().nodes) {\r
+                               if (!link2.to().equals(this))\r
+                                       potential.add(link2.to());\r
+                       }\r
+               }\r
+               for (GraphNode<T> node : potential) {\r
+                       for (Link<T> link : nodes) {\r
+                               if (node.nodes.contains(link))\r
+                                       result.add(node);\r
+                       }\r
+               }\r
+               \r
+               return result;\r
+       }\r
+       \r
+\r
+       /**\r
+        * Disposes this node. Removes all the links that connect to thi snode.\r
+        */\r
+       public void destroy() {\r
+               if (disposed)\r
+                       return;\r
+               Logger.defaultLogInfo("Node destroy " + data + " " + this);\r
+               Collection<Link<T>> coll = new ArrayList<Link<T>>();\r
+               coll.addAll(nodes);\r
+               nodes.clear();\r
+               for (Link<T> link : coll) {\r
+                       link.to()._removeLink(this);\r
+               }\r
+               nodes = null;\r
+               disposed = true;\r
+       }\r
+       \r
+       /**\r
+        * Removes this node from the graph, and reconnects parents and children of this node.\r
+        */\r
+       public void remove() {\r
+               if (disposed)\r
+                       return;\r
+               // FIXME: link.to may be *this.\r
+               Logger.defaultLogInfo("Node remove " + data + " " + this);\r
+               if (nodes.size() == 1) {\r
+                       Link<T> link = nodes.get(0);\r
+                       link.to().removeLink(link.getInverseName(), link.getName(), this);\r
+               } else {\r
+                       for (int i = 0; i < nodes.size() -1 ; i++) {\r
+                               Link<T> link1 = nodes.get(i);\r
+                               link1.to().removeLink(link1.getInverseName(), link1.getName(), this);\r
+                               for (int j = i; j < nodes.size(); j++) {\r
+                                       Link<T> link2 = nodes.get(j);\r
+                                       link2.to().removeLink(link2.getInverseName(), link2.getName(), this);\r
+                                       if (link1.to().equals(link2.to()))\r
+                                               continue;\r
+                                       link1.to().addLink(link1.getInverseName(),link2.getInverseName(),link2.to());\r
+                               }\r
+                               \r
+                       }\r
+               }\r
+               \r
+               nodes.clear();\r
+               nodes = null;\r
+               disposed = true;\r
+\r
+       }\r
+       \r
+       /**\r
+        * \r
+        * @return true if the node has been disposed and cannot be used anymore.\r
+        */\r
+       public boolean isDisposed() {\r
+               return disposed;\r
+       }\r
+       \r
+       /**\r
+        * Disposed the node and all nodes that are in the same graph.\r
+        */\r
+       public void dispose() {\r
+               if (disposed)\r
+                       return;\r
+               Collection<Link<T>> links = new ArrayList<Link<T>>();\r
+               links.addAll(nodes);\r
+               nodes.clear();\r
+               for (Link<T> l : links)\r
+                       l.to().dispose();\r
+               links.clear();\r
+               nodes = null;\r
+               disposed = true;\r
+       }\r
+       \r
+\r
+       protected void _checkDisposed() {\r
+               if (disposed) {\r
+                       Logger.defaultLogError("Remove Node, disposed " + this);\r
+                       throw new RuntimeException("Node " + this + " is disposed.");\r
+               }\r
+       }\r
+       \r
+       \r
+       public int distanceTo(GraphNode<T> node, String rel, String inv) {\r
+               if (node.equals(this))\r
+                       return 0;\r
+               int count = 0;\r
+               Set<GraphNode<T>> processed = new HashSet<GraphNode<T>>();\r
+               Set<GraphNode<T>> next = new HashSet<GraphNode<T>>();\r
+               next.add(this);\r
+               while (true) {\r
+                       if (next.size() == 0)\r
+                               return -1;\r
+                       count++;\r
+                       processed.addAll(next);\r
+                       Set<GraphNode<T>> nextNext = new HashSet<GraphNode<T>>();\r
+                       for (GraphNode<T> n : next) {\r
+                               for (GraphNode<T> nn : n.getNodes(rel, inv))\r
+                                       if (!processed.contains(nn))\r
+                                               nextNext.add(nn);\r
+                       }\r
+                       next = nextNext;\r
+                       if (next.contains(node))\r
+                               return count;\r
+               }\r
+       }\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/Identifiable.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/Identifiable.java
new file mode 100644 (file)
index 0000000..ceb4bc7
--- /dev/null
@@ -0,0 +1,27 @@
+package org.simantics.interop.mapping.data;\r
+\r
+/**\r
+ * \r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public interface Identifiable {\r
+       \r
+       /**\r
+        * Returns object of given class, or null.\r
+        * \r
+        * Used classes:\r
+        * Resource\r
+        * Resource[]\r
+        * String\r
+        * \r
+        * @param <T>\r
+        * @param clazz\r
+        * @return\r
+        */\r
+       public <T> T getAdapter(Class<T> clazz);\r
+       \r
+       public Identifiable merge(Identifiable other);\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/Link.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/Link.java
new file mode 100644 (file)
index 0000000..f03f10f
--- /dev/null
@@ -0,0 +1,95 @@
+package org.simantics.interop.mapping.data;\r
+\r
+\r
+import org.simantics.utils.datastructures.hints.HintContext;\r
+\r
+public class Link <T> extends HintContext {\r
+       private GraphNode<T> from;\r
+       private GraphNode<T> to;\r
+       private String name;\r
+       \r
+       private Link<T> inverseLink;\r
+       private Link<T> mainLink;\r
+\r
+       Link(GraphNode<T> from, String name, GraphNode<T> to) {\r
+               this.from = from;\r
+               this.to = to;\r
+               this.name = name;\r
+       }\r
+       \r
+       public GraphNode<T> from() {\r
+               return from;\r
+       }\r
+       \r
+       public GraphNode<T> to() {\r
+               return to;\r
+       }\r
+       \r
+       public String getName() {\r
+               return name;\r
+       }\r
+       \r
+       void setInverseLink(Link<T> inverseLink) {\r
+               this.inverseLink = inverseLink;\r
+       }\r
+       \r
+       void setMainLink(Link<T> mainLink) {\r
+               this.mainLink = mainLink;\r
+       }\r
+       \r
+       public String getInverseName() {\r
+               if (inverseLink != null)\r
+                       return inverseLink.getName();\r
+               if (mainLink != null)\r
+                       return mainLink.getName();\r
+               return null;\r
+       }\r
+       \r
+       public boolean hasInverse() {\r
+               return inverseLink != null || mainLink != null;\r
+       }\r
+       \r
+       public Link<T> getInverse() {\r
+               if (inverseLink != null)\r
+                       return inverseLink;\r
+               if (mainLink != null)\r
+                       return mainLink;\r
+               return null;\r
+       }\r
+       \r
+       public boolean isInverse() {\r
+               return mainLink != null;\r
+       }\r
+       \r
+       public boolean isMain() {\r
+               return inverseLink != null;\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object obj) {\r
+               if (!obj.getClass().equals(getClass()))\r
+                       return false;\r
+               Link<?> other = (Link<?>)obj;\r
+               if (!from.equals(other.from))\r
+                       return false;\r
+               if (!to.equals(other.to))\r
+                       return false;\r
+               if (!GraphNode.equals(name,other.name))\r
+                       return false;\r
+               return true;\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public int hashCode() {\r
+               return from.hashCode() * to.hashCode() + name.hashCode();\r
+       }\r
+       \r
+       @Override\r
+    public void setHint(Key key, Object value) {\r
+               if (value == null)\r
+                       return;\r
+               super.setHint(key, value);\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ObjectIdentifiable.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ObjectIdentifiable.java
new file mode 100644 (file)
index 0000000..5723423
--- /dev/null
@@ -0,0 +1,57 @@
+package org.simantics.interop.mapping.data;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+\r
+public class ObjectIdentifiable implements Identifiable {\r
+\r
+       private Object obj;\r
+       \r
+       public ObjectIdentifiable(Object obj) {\r
+               this.obj = obj;\r
+       }\r
+       \r
+       public Object getObject() {\r
+               return obj;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public <T> T getAdapter(Class<T> clazz) {\r
+               if (clazz == String.class)\r
+                       return (T)obj.toString();\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public int hashCode() {\r
+               return obj.hashCode();\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (arg0 == null)\r
+                       return false;\r
+               if (this.getClass() != arg0.getClass())\r
+                       return false;\r
+               ObjectIdentifiable other = (ObjectIdentifiable)arg0;\r
+               return obj.equals(other.obj);\r
+       }\r
+       \r
+       @Override\r
+       public Identifiable merge(Identifiable other) {\r
+               if (other instanceof ObjectIdentifiable) {\r
+                       ObjectSetIdentifiable i = new ObjectSetIdentifiable(this.obj,((ObjectIdentifiable)other).obj);\r
+                       return i;\r
+               } else if (other instanceof ObjectSetIdentifiable) {\r
+                       Collection<Object> coll = new ArrayList<Object>();\r
+                       coll.add(this.obj);\r
+                       coll.addAll(((ObjectSetIdentifiable)other).getObjects());\r
+                       ObjectSetIdentifiable i = new ObjectSetIdentifiable(coll);\r
+                       return i;\r
+               }\r
+               return null;\r
+       }\r
+       \r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ObjectSetIdentifiable.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ObjectSetIdentifiable.java
new file mode 100644 (file)
index 0000000..2494470
--- /dev/null
@@ -0,0 +1,79 @@
+package org.simantics.interop.mapping.data;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+\r
+public class ObjectSetIdentifiable implements Identifiable {\r
+\r
+       private Set<Object> objs;\r
+       \r
+       public ObjectSetIdentifiable(Object obj) {\r
+               objs = new HashSet<Object>();\r
+               objs.add(obj);\r
+       }\r
+       \r
+       public ObjectSetIdentifiable(Object... obj) {\r
+               this.objs = new HashSet<Object>();\r
+               for (Object r : obj)\r
+                       this.objs.add(r);\r
+       }\r
+       \r
+       public ObjectSetIdentifiable(Collection<Object> obj) {\r
+               this.objs = new HashSet<Object>();\r
+               for (Object r : obj)\r
+                       this.objs.add(r);\r
+       }\r
+       \r
+       public Set<Object> getObjects() {\r
+               return objs;\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       @Override\r
+       public <T> T getAdapter(Class<T> clazz) {\r
+               if (clazz.equals(String.class)) {\r
+                       String s = "";\r
+                       for (Object o : objs)\r
+                               s += o.toString() + " ";\r
+                       return (T)s;\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public int hashCode() {\r
+               return objs.hashCode();\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (arg0 == null)\r
+                       return false;\r
+               if (this.getClass() != arg0.getClass())\r
+                       return false;\r
+               ObjectSetIdentifiable other = (ObjectSetIdentifiable)arg0;\r
+               return objs.equals(other.objs);\r
+       }\r
+       \r
+       @Override\r
+       public Identifiable merge(Identifiable other) {\r
+               if (other instanceof ObjectIdentifiable) {\r
+                       Collection<Object> coll = new ArrayList<Object>();\r
+                       coll.addAll(this.objs);\r
+                       coll.add(((ObjectIdentifiable)other).getObject());\r
+                       ObjectSetIdentifiable i = new ObjectSetIdentifiable(coll);\r
+                       return i;\r
+               } else if (other instanceof ObjectSetIdentifiable) {\r
+                       Collection<Object> coll = new ArrayList<Object>();\r
+                       coll.addAll(this.objs);\r
+                       coll.addAll(((ObjectSetIdentifiable)other).getObjects());\r
+                       ObjectSetIdentifiable i = new ObjectSetIdentifiable(coll);\r
+                       return i;\r
+               }\r
+               return null;\r
+       }\r
+       \r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceIdentifiable.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceIdentifiable.java
new file mode 100644 (file)
index 0000000..4791d5b
--- /dev/null
@@ -0,0 +1,68 @@
+package org.simantics.interop.mapping.data;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public class ResourceIdentifiable implements Identifiable {\r
+\r
+       protected Resource resource;\r
+       \r
+       public ResourceIdentifiable(Resource resource) {\r
+               this.resource = resource;\r
+       }\r
+       \r
+       public Resource getResource() {\r
+               return resource;\r
+       }\r
+       \r
+       @Override\r
+       public int hashCode() {\r
+               return resource.hashCode();\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public <T> T getAdapter(Class<T> clazz) {\r
+               if (clazz.equals(Resource.class))\r
+                       return (T)resource;\r
+               if (clazz.equals(Resource[].class))\r
+                       return (T) new Resource[]{resource};\r
+               if (clazz.equals(String.class)) {\r
+                       // TODO : have to use org.simantics.db.common.utils.Transaction to get access to ReadGraph.\r
+                       return (T)resource.toString();//NameUtils.getSafeName(g,resource);\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (arg0 == null)\r
+                       return false;\r
+               if (this.getClass() != arg0.getClass())\r
+                       return false;\r
+               ResourceIdentifiable other = (ResourceIdentifiable)arg0;\r
+               return resource.equals(other.resource);\r
+       }\r
+       \r
+       @Override\r
+       public Identifiable merge(Identifiable other) {\r
+               if (other instanceof ResourceIdentifiable) {\r
+                       ResourceSetIdentifiable i = new ResourceSetIdentifiable(this.resource,((ResourceIdentifiable)other).resource);\r
+                       return i;\r
+               } else if (other instanceof ResourceSetIdentifiable) {\r
+                       Collection<Resource> coll = new ArrayList<Resource>();\r
+                       coll.add(this.resource);\r
+                       coll.addAll(((ResourceSetIdentifiable)other).getResources());\r
+                       ResourceSetIdentifiable i = new ResourceSetIdentifiable(resource,coll);\r
+                       return i;\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public String toString() {\r
+               return resource.toString();\r
+       }\r
+       \r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetIdentifiable.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetIdentifiable.java
new file mode 100644 (file)
index 0000000..84a383b
--- /dev/null
@@ -0,0 +1,110 @@
+package org.simantics.interop.mapping.data;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public class ResourceSetIdentifiable implements Identifiable {\r
+\r
+       private Resource primary;\r
+       private Set<Resource> resources;\r
+       \r
+       public ResourceSetIdentifiable(Resource resource) {\r
+               this.resources = new HashSet<Resource>();\r
+               this.resources.add(resource);\r
+               this.primary = resource;\r
+       }\r
+       \r
+       public ResourceSetIdentifiable(Resource primary, Resource... resource) {\r
+               this.resources = new HashSet<Resource>();\r
+               for (Resource r : resource)\r
+                       this.resources.add(r);\r
+               this.resources.add(primary);\r
+               this.primary = primary;\r
+       }\r
+       \r
+       public ResourceSetIdentifiable(Resource primary, Collection<Resource> resource) {\r
+               this.resources = new HashSet<Resource>();\r
+               for (Resource r : resource)\r
+                       this.resources.add(r);\r
+               this.resources.add(primary);\r
+               this.primary = primary;\r
+       }\r
+       \r
+       public ResourceSetIdentifiable(Collection<Resource> resource) {\r
+               this.resources = new HashSet<Resource>();\r
+               for (Resource r : resource)\r
+                       this.resources.add(r);\r
+               this.primary = resource.iterator().next();\r
+       }\r
+       \r
+       public Resource getPrimary() {\r
+               return primary;\r
+       }\r
+       \r
+       public Set<Resource> getResources() {\r
+               return resources;\r
+       }\r
+       \r
+       @Override\r
+       public int hashCode() {\r
+               return resources.hashCode();\r
+       }\r
+       \r
+       @SuppressWarnings("unchecked")\r
+       public <T> T getAdapter(Class<T> clazz) {\r
+               if (clazz.equals(Resource.class))\r
+                       return (T)primary;\r
+               if (clazz.equals(Resource[].class))\r
+                       return (T)resources.toArray(new Resource[resources.size()]);\r
+               if (clazz.equals(String.class)) {\r
+                       String s = "";\r
+                       for (Resource r : resources)\r
+                               s += r.toString() + " ";\r
+                       // TODO : have to use org.simantics.db.common.utils.Transaction to get access to ReadGraph.\r
+                       return (T)s;//NameUtils.getSafeName(g,resource);\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (arg0 == null)\r
+                       return false;\r
+               if (this.getClass() != arg0.getClass())\r
+                       return false;\r
+               ResourceSetIdentifiable other = (ResourceSetIdentifiable)arg0;\r
+               return resources.equals(other.resources);\r
+       }\r
+       \r
+       @Override\r
+       public Identifiable merge(Identifiable other) {\r
+               if (other instanceof ResourceIdentifiable) {\r
+                       Collection<Resource> coll = new ArrayList<Resource>();\r
+                       coll.addAll(this.resources);\r
+                       coll.add(((ResourceIdentifiable)other).getResource());\r
+                       ResourceSetIdentifiable i = new ResourceSetIdentifiable(primary,coll);\r
+                       return i;\r
+               } else if (other instanceof ResourceSetIdentifiable) {\r
+                       Collection<Resource> coll = new ArrayList<Resource>();\r
+                       coll.addAll(this.resources);\r
+                       coll.addAll(((ResourceSetIdentifiable)other).getResources());\r
+                       ResourceSetIdentifiable i = new ResourceSetIdentifiable(primary,coll);\r
+                       return i;\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public String toString() {\r
+               String s = "(";\r
+               for (Resource r : resources) {\r
+                       s += r.toString() + " ";\r
+               }\r
+               s = s.substring(0,s.length()-1) + ")";\r
+               return s;\r
+       }\r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetSplitIdentifiable.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetSplitIdentifiable.java
new file mode 100644 (file)
index 0000000..0a120a8
--- /dev/null
@@ -0,0 +1,86 @@
+package org.simantics.interop.mapping.data;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public class ResourceSetSplitIdentifiable extends ResourceSetIdentifiable {\r
+\r
+       private static int counter = 0;\r
+       \r
+       private int identifier;\r
+       private int index;\r
+       \r
+       \r
+       ResourceSetSplitIdentifiable(Resource resource, int index, int identifier) {\r
+               super(resource);\r
+               this.index = index;\r
+               this.identifier = identifier;\r
+       }\r
+       \r
+       public ResourceSetSplitIdentifiable(int index, int identifier, Resource primary, Resource... resource) {\r
+               super(primary,resource);\r
+               this.index = index;\r
+               this.identifier = identifier;\r
+       }\r
+       \r
+       public ResourceSetSplitIdentifiable(Resource primary, Collection<Resource> resources,int index, int identifier) {\r
+               super(primary,resources);\r
+               this.index = index;\r
+               this.identifier = identifier;\r
+       }\r
+       \r
+       public static List<Identifiable> createIdentifiables(ResourceSetIdentifiable identifiable, int count) {\r
+               List<Identifiable> result = new ArrayList<Identifiable>(count);\r
+               int identifier = counter++;\r
+               for (int i = 0; i < count; i++) {\r
+                       result.add(new ResourceSetSplitIdentifiable(identifiable.getPrimary(),identifiable.getResources(), i, identifier));\r
+               }\r
+               return result;\r
+       }\r
+       \r
+       public static List<Identifiable> createIdentifiables(Identifiable identifiable, int count) {\r
+               Resource res = identifiable.getAdapter(Resource.class);\r
+               if (res == null)\r
+                       return null;\r
+               \r
+               Resource resources[] = identifiable.getAdapter(Resource[].class);\r
+               if (resources.length > 1) {\r
+                       List<Identifiable> result = new ArrayList<Identifiable>(count);\r
+                       int identifier = counter++;\r
+                       for (int i = 0; i < count; i++) {\r
+                               result.add(new ResourceSetSplitIdentifiable(i, identifier, res, resources));\r
+                       }\r
+                       return result;\r
+               } else {\r
+                       return ResourceSplitIdentifiable.createIdentifiables(identifiable, count);\r
+               }\r
+\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (arg0 == null)\r
+                       return false;\r
+               if (this.getClass() != arg0.getClass())\r
+                       return false;\r
+               ResourceSetSplitIdentifiable other = (ResourceSetSplitIdentifiable)arg0;\r
+               if (identifier != other.identifier)\r
+                       return false;\r
+               if (index != other.index)\r
+                       return false;\r
+               return super.equals(arg0);\r
+       }\r
+       \r
+       @Override\r
+       public Identifiable merge(Identifiable other) {\r
+               throw new RuntimeException("Cannot be merged");\r
+       }\r
+       \r
+       \r
+       \r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetSplitIdentifiable2.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSetSplitIdentifiable2.java
new file mode 100644 (file)
index 0000000..fa5841d
--- /dev/null
@@ -0,0 +1,91 @@
+package org.simantics.interop.mapping.data;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public class ResourceSetSplitIdentifiable2 extends ResourceSetIdentifiable {\r
+\r
+       private String identifier;\r
+       \r
+       \r
+       public ResourceSetSplitIdentifiable2(Resource resource, String identifier) {\r
+               super(resource);\r
+               this.identifier =identifier;\r
+       }\r
+       \r
+       public ResourceSetSplitIdentifiable2(String identifier, Resource primary, Resource... resource) {\r
+               super(primary,resource);\r
+               this.identifier = identifier;\r
+       }\r
+       \r
+       public ResourceSetSplitIdentifiable2(Resource primary, Collection<Resource> resources, String identifier) {\r
+               super(primary,resources);\r
+               this.identifier = identifier;\r
+       }\r
+       \r
+       public static Identifiable createIdentifiable(ResourceSetIdentifiable identifiable, String identifier) {\r
+               return new ResourceSetSplitIdentifiable2(identifiable.getPrimary(),identifiable.getResources(), identifier);\r
+       }\r
+       \r
+       public static Identifiable createIdentifiable(Identifiable identifiable, String identifier) {\r
+               Resource res = identifiable.getAdapter(Resource.class);\r
+               if (res == null)\r
+                       return null;\r
+               \r
+               Resource resources[] = identifiable.getAdapter(Resource[].class);\r
+               if (resources.length > 1) {\r
+                       return new ResourceSetSplitIdentifiable2(identifier, res, resources);\r
+\r
+               } else {\r
+                       return ResourceSplitIdentifiable2.createIdentifiable(identifiable, identifier);\r
+               }\r
+\r
+               \r
+       }\r
+       \r
+       public String getIdentifier() {\r
+               return identifier;\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (arg0 == null)\r
+                       return false;\r
+               if (this.getClass() != arg0.getClass())\r
+                       return false;\r
+               ResourceSetSplitIdentifiable2 other = (ResourceSetSplitIdentifiable2)arg0;\r
+               if (!identifier.equals(other.identifier))\r
+                       return false;\r
+               return super.equals(arg0);\r
+       }\r
+       \r
+       @Override\r
+       public Identifiable merge(Identifiable other) {\r
+               if (other instanceof ResourceSplitIdentifiable2) {\r
+                       ResourceSplitIdentifiable2 o = (ResourceSplitIdentifiable2)other;\r
+                       if (!o.getIdentifier().equals(identifier))\r
+                               throw new RuntimeException("Cannot be merged, Identifiers do not match " + identifier + " " + o.getIdentifier());\r
+                       Collection<Resource> resources = new ArrayList<Resource>();\r
+                       resources.addAll(getResources());\r
+                       resources.add(o.getResource());\r
+                       ResourceSetSplitIdentifiable2 id = new ResourceSetSplitIdentifiable2(getPrimary(), resources,identifier);\r
+                       return id;\r
+               }\r
+               if (other instanceof ResourceSetSplitIdentifiable2) {\r
+                       ResourceSetSplitIdentifiable2 o = (ResourceSetSplitIdentifiable2)other;\r
+                       if (!o.getIdentifier().equals(identifier))\r
+                               throw new RuntimeException("Cannot be merged, Identifiers do not match " + identifier + " " + o.getIdentifier());\r
+                       Collection<Resource> resources = new ArrayList<Resource>();\r
+                       resources.addAll(getResources());\r
+                       resources.addAll(o.getResources());\r
+                       ResourceSetSplitIdentifiable2 id = new ResourceSetSplitIdentifiable2(getPrimary(), resources,identifier);\r
+                       return id;\r
+               }\r
+               throw new RuntimeException("Cannot be merged");\r
+       }\r
+       \r
+       \r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSplitIdentifiable.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSplitIdentifiable.java
new file mode 100644 (file)
index 0000000..1b62899
--- /dev/null
@@ -0,0 +1,74 @@
+package org.simantics.interop.mapping.data;\r
+\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public class ResourceSplitIdentifiable extends ResourceIdentifiable {\r
+\r
+       private static int counter = 0;\r
+       \r
+       //private Resource resource;\r
+       private int identifier;\r
+       private int index;\r
+       \r
+       \r
+       ResourceSplitIdentifiable(Resource resource, int index, int identifier) {\r
+               super(resource);\r
+               this.index = index;\r
+               this.identifier = identifier;\r
+       }\r
+       \r
+       public static List<Identifiable> createIdentifiables(ResourceIdentifiable identifiable, int count) {\r
+               List<Identifiable> result = new ArrayList<Identifiable>(count);\r
+               int identifier = counter++;\r
+               for (int i = 0; i < count; i++) {\r
+                       result.add(new ResourceSplitIdentifiable(identifiable.getResource(), i, identifier));\r
+               }\r
+               return result;\r
+       }\r
+       \r
+       public static List<Identifiable> createIdentifiables(Identifiable identifiable, int count) {\r
+               Resource res = identifiable.getAdapter(Resource.class);\r
+               if (res == null)\r
+                       return null;\r
+\r
+               Resource resources[] = identifiable.getAdapter(Resource[].class);\r
+               \r
+               if (resources.length > 1) {\r
+                       return ResourceSetSplitIdentifiable.createIdentifiables(identifiable, count);   \r
+               } else {\r
+                       List<Identifiable> result = new ArrayList<Identifiable>(count);\r
+                       int identifier = counter++;\r
+                       for (int i = 0; i < count; i++) {\r
+                               result.add(new ResourceSplitIdentifiable(res, i, identifier));\r
+                       }\r
+                       return result;\r
+               }\r
+\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (arg0 == null)\r
+                       return false;\r
+               if (this.getClass() != arg0.getClass())\r
+                       return false;\r
+               ResourceSplitIdentifiable other = (ResourceSplitIdentifiable)arg0;\r
+               if (identifier != other.identifier)\r
+                       return false;\r
+               if (index != other.index)\r
+                       return false;\r
+               return resource.equals(other.resource);\r
+       }\r
+       \r
+       @Override\r
+       public Identifiable merge(Identifiable other) {\r
+               throw new RuntimeException("Cannot be merged");\r
+       }\r
+       \r
+       \r
+       \r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSplitIdentifiable2.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/data/ResourceSplitIdentifiable2.java
new file mode 100644 (file)
index 0000000..a9094ec
--- /dev/null
@@ -0,0 +1,72 @@
+package org.simantics.interop.mapping.data;\r
+\r
+\r
+import org.simantics.db.Resource;\r
+\r
+public class ResourceSplitIdentifiable2 extends ResourceIdentifiable {\r
+\r
+\r
+       private String identifier;\r
+       \r
+       \r
+       public ResourceSplitIdentifiable2(Resource resource, String identifier) {\r
+               super(resource);\r
+               this.identifier = identifier;\r
+       }\r
+       \r
+       public static Identifiable createIdentifiable(ResourceIdentifiable identifiable, String identifier) {\r
+               return new ResourceSplitIdentifiable2(identifiable.getResource(), identifier);\r
+\r
+       }\r
+       \r
+       public static Identifiable createIdentifiable(Identifiable identifiable, String identifier) {\r
+               Resource res = identifiable.getAdapter(Resource.class);\r
+               if (res == null)\r
+                       return null;\r
+\r
+               Resource resources[] = identifiable.getAdapter(Resource[].class);\r
+               \r
+               if (resources.length > 1) {\r
+                       return ResourceSetSplitIdentifiable2.createIdentifiable(identifiable, identifier);      \r
+               } else {\r
+                       return new ResourceSplitIdentifiable2(res, identifier);\r
+               }\r
+\r
+       }\r
+       \r
+       @Override\r
+       public boolean equals(Object arg0) {\r
+               if (arg0 == null)\r
+                       return false;\r
+               if (this.getClass() != arg0.getClass())\r
+                       return false;\r
+               ResourceSplitIdentifiable2 other = (ResourceSplitIdentifiable2)arg0;\r
+               if (!identifier.equals(other.identifier))\r
+                       return false;\r
+               return resource.equals(other.resource);\r
+       }\r
+       \r
+       public String getIdentifier() {\r
+               return identifier;\r
+       }\r
+       \r
+       @Override\r
+       public Identifiable merge(Identifiable other) {\r
+               if (other instanceof ResourceSplitIdentifiable2) {\r
+                       ResourceSplitIdentifiable2 o = (ResourceSplitIdentifiable2)other;\r
+                       if (!o.identifier.equals(identifier))\r
+                               throw new RuntimeException("Cannot be merged, Identifiers do not match " + identifier + " " + o.identifier);\r
+                       ResourceSetSplitIdentifiable2 id = new ResourceSetSplitIdentifiable2(identifier, resource, o.resource);\r
+                       return id;\r
+               }\r
+               if (other instanceof ResourceSetSplitIdentifiable2) {\r
+                       ResourceSetSplitIdentifiable2 o = (ResourceSetSplitIdentifiable2)other;\r
+                       if (!o.getIdentifier().equals(identifier))\r
+                               throw new RuntimeException("Cannot be merged, Identifiers do not match " + identifier + " " + o.getIdentifier());\r
+                       ResourceSetSplitIdentifiable2 id = new ResourceSetSplitIdentifiable2(resource, o.getResources(),identifier);\r
+                       return id;\r
+               }\r
+               throw new RuntimeException("Cannot be merged");\r
+       }\r
+       \r
+}\r
diff --git a/org.simantics.interop.mapping/src/org/simantics/interop/mapping/internal/Activator.java b/org.simantics.interop.mapping/src/org/simantics/interop/mapping/internal/Activator.java
new file mode 100644 (file)
index 0000000..66f486a
--- /dev/null
@@ -0,0 +1,50 @@
+package org.simantics.interop.mapping.internal;\r
+\r
+import org.eclipse.ui.plugin.AbstractUIPlugin;\r
+import org.osgi.framework.BundleContext;\r
+\r
+/**\r
+ * The activator class controls the plug-in life cycle\r
+ */\r
+public class Activator extends AbstractUIPlugin {\r
+\r
+       // The plug-in ID\r
+       public static final String PLUGIN_ID = "org.simantics.interop.mapping"; //$NON-NLS-1$\r
+\r
+       // The shared instance\r
+       private static Activator plugin;\r
+       \r
+       /**\r
+        * The constructor\r
+        */\r
+       public Activator() {\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)\r
+        */\r
+       public void start(BundleContext context) throws Exception {\r
+               super.start(context);\r
+               plugin = this;\r
+       }\r
+\r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)\r
+        */\r
+       public void stop(BundleContext context) throws Exception {\r
+               plugin = null;\r
+               super.stop(context);\r
+       }\r
+\r
+       /**\r
+        * Returns the shared instance\r
+        *\r
+        * @return the shared instance\r
+        */\r
+       public static Activator getDefault() {\r
+               return plugin;\r
+       }\r
+\r
+}\r