From: luukkainen Date: Wed, 1 Feb 2012 12:15:45 +0000 (+0000) Subject: Running comparison algorithm in multiple transactions. refs #3181 X-Git-Tag: v1.31.0~93 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;ds=sidebyside;h=766d1dd7b040939224a60d435c2ad2805374a772;p=simantics%2Finterop.git Running comparison algorithm in multiple transactions. refs #3181 git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@24121 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java index 5ba622b..f7c4ea6 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphComparator.java @@ -25,7 +25,9 @@ import java.util.Stack; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.Session; import org.simantics.db.Statement; +import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.exception.DoesNotContainValueException; @@ -202,6 +204,56 @@ public class GraphComparator { } + } + + public void test(Session session) throws DatabaseException { + + comparator.setComparator(this); + + final Stack objectsLeft = new Stack(); + final Stack objectsRight = new Stack(); + objectsLeft.push(r1); + objectsRight.push(r2); + + final Set unreliableLeft = new HashSet(); + final Set unreliableRight = new HashSet(); + + while (true) { + if (objectsLeft.isEmpty()) + break; + session.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + g = graph; + b = Layer0.getInstance(graph); + // process compares objects that are identified and searches for more resources to process. + process(objectsLeft, objectsRight, unreliableLeft, unreliableRight); + // process unreliable handles cases where unidentified statements subject and object have been identified + processUnreliable(unreliableLeft, unreliableRight); + // process unreliable handles cases where unidentified resources have path of length one to identified resource + processUnreliable(unreliableLeft, unreliableRight,objectsLeft,objectsRight); + if (objectsLeft.isEmpty() && unreliableLeft.size() > 0 && unreliableRight.size() > 0) { + // comparison is ending, but we have still unprocessed unidentified resources left. + // These cases have longer path than one to identified objects. + processUnreliableDeep(unreliableLeft, unreliableRight, objectsLeft, objectsRight); + } + } + }); + + + + } + for (Statement s : unreliableLeft) { + if (!comparableStatements.containsLeft(s)) + addDeletion(s); + } + for (Statement s : unreliableRight) { + if (!comparableStatements.containsRight(s)) + addAddition(s); + } + + } private void process(Stack objectsLeft, Stack objectsRight, Set unreliableLeft, Set unreliableRight) throws DatabaseException {