]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Running comparison algorithm in multiple transactions. refs #3181
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 1 Feb 2012 12:15:45 +0000 (12:15 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 09:22:18 +0000 (11:22 +0200)
git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@24121 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java

index 5ba622b620f9379d0c6deec0ebe07a46f5780cc9..f7c4ea69667cc479d014a931cdecfbe2e9ee81b0 100644 (file)
@@ -25,7 +25,9 @@ import java.util.Stack;
 \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.common.request.ReadRequest;\r
 import org.simantics.db.common.utils.NameUtils;\r
 import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.db.exception.DoesNotContainValueException;\r
@@ -202,6 +204,56 @@ public class GraphComparator {
                }\r
                \r
                \r
+       }\r
+       \r
+       public void test(Session session) throws DatabaseException {\r
+               \r
+               comparator.setComparator(this);\r
+               \r
+               final Stack<Resource> objectsLeft = new Stack<Resource>();\r
+               final Stack<Resource> objectsRight = new Stack<Resource>();\r
+               objectsLeft.push(r1);\r
+               objectsRight.push(r2);\r
+               \r
+               final Set<Statement> unreliableLeft = new HashSet<Statement>();\r
+               final Set<Statement> unreliableRight = new HashSet<Statement>();\r
+               \r
+               while (true) {\r
+                       if (objectsLeft.isEmpty())\r
+                               break;\r
+                       session.syncRequest(new ReadRequest() {\r
+                               \r
+                               @Override\r
+                               public void run(ReadGraph graph) throws DatabaseException {\r
+                                       g = graph;\r
+                                       b = Layer0.getInstance(graph);\r
+                                       // process compares objects that are identified and searches for more resources to process. \r
+                                       process(objectsLeft, objectsRight, unreliableLeft, unreliableRight);\r
+                                       // process unreliable handles cases where unidentified statements subject and object have been identified \r
+                                       processUnreliable(unreliableLeft, unreliableRight);\r
+                                       // process unreliable handles cases where unidentified resources have path of length one to identified resource\r
+                                       processUnreliable(unreliableLeft, unreliableRight,objectsLeft,objectsRight);\r
+                                       if (objectsLeft.isEmpty() && unreliableLeft.size() > 0 && unreliableRight.size() > 0) {\r
+                                               // comparison is ending, but we have still unprocessed unidentified resources left.\r
+                                               // These cases have longer path than one to identified objects.\r
+                                               processUnreliableDeep(unreliableLeft, unreliableRight, objectsLeft, objectsRight);\r
+                                       }\r
+                               }\r
+                       });\r
+                       \r
+                       \r
+                       \r
+               }\r
+               for (Statement s : unreliableLeft) {\r
+                       if (!comparableStatements.containsLeft(s))\r
+                               addDeletion(s);\r
+               }\r
+               for (Statement s : unreliableRight) {\r
+                       if (!comparableStatements.containsRight(s))\r
+                               addAddition(s);\r
+               }\r
+               \r
+               \r
        }\r
        \r
        private void process(Stack<Resource> objectsLeft, Stack<Resource> objectsRight, Set<Statement> unreliableLeft, Set<Statement> unreliableRight) throws DatabaseException {\r