X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Frequest%2Fcombinations%2FCombinators.java;h=1eea49e26d466cf582e79bdd0b0245afd9bc96cb;hp=bd2409f5d9b2eecde6a5f369562a141365938adb;hb=0d9b90834ce56b292c00b1a39850ed842c3e4d42;hpb=e5db6157fd8722c946613d4e46d7aaf6bfa92609 diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java index bd2409f5d..1eea49e26 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/request/combinations/Combinators.java @@ -17,9 +17,10 @@ import java.util.Map; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ParametrizedRead; +import org.simantics.db.common.request.ResourceRead; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.procedure.AsyncMultiProcedure; import org.simantics.db.procedure.Procedure; +import org.simantics.db.procedure.SyncMultiProcedure; import org.simantics.db.request.MultiRead; import org.simantics.db.request.Read; import org.simantics.layer0.Layer0; @@ -41,9 +42,11 @@ public class Combinators { } @Override public void perform(ReadGraph graph, - AsyncMultiProcedure callback) + SyncMultiProcedure callback) throws DatabaseException { - graph.forEachObject(subject, relation, callback); + for(Resource object : graph.getObjects(subject, relation)) { + callback.execute(graph, object); + } } @Override public int hashCode() { @@ -138,9 +141,7 @@ public class Combinators { } @Override public Resource perform(ReadGraph graph) throws DatabaseException { - SynchronizationProcedure procedure = new SynchronizationProcedure(); - graph.forPossibleObject(subject, relation, procedure); - return procedure.getResult(); + return graph.getPossibleObject(subject, relation); } @Override public int hashCode() { @@ -204,9 +205,7 @@ public class Combinators { } @Override public Resource perform(ReadGraph graph) throws DatabaseException { - SynchronizationProcedure procedure = new SynchronizationProcedure(); - graph.forSingleObject(subject, relation, procedure); - return procedure.getResult(); + return graph.getSingleObject(subject, relation); } @Override public int hashCode() { @@ -327,7 +326,7 @@ public class Combinators { this.f = f; this.g = g; } - public void perform(ReadGraph graph, final AsyncMultiProcedure callback) throws DatabaseException { + public void perform(ReadGraph graph, final SyncMultiProcedure callback) throws DatabaseException { try { for(X x : graph.syncRequest(g)) callback.execute(graph, graph.syncRequest(f.get(x))); @@ -410,7 +409,7 @@ public class Combinators { this.g = g; } @Override - public void perform(ReadGraph graph, AsyncMultiProcedure callback) + public void perform(ReadGraph graph, SyncMultiProcedure callback) throws DatabaseException { graph.syncRequest(f.get(graph.syncRequest(g)), callback); } @@ -469,7 +468,7 @@ public class Combinators { this.f = f; this.g = g; } - public void perform(ReadGraph graph, final AsyncMultiProcedure callback) throws DatabaseException { + public void perform(ReadGraph graph, final SyncMultiProcedure callback) throws DatabaseException { try { for(X x : graph.syncRequest(g)) for(Y y : graph.syncRequest(f.get(x))) @@ -614,7 +613,7 @@ public class Combinators { this.value = value; } @Override - public void perform(ReadGraph graph, AsyncMultiProcedure callback) + public void perform(ReadGraph graph, SyncMultiProcedure callback) throws DatabaseException { callback.execute(graph, value); callback.finished(graph); @@ -640,29 +639,18 @@ public class Combinators { // ------------------------------------------------------------------------ - private static class Name implements Read { - Resource resource; + private static class Name extends ResourceRead { + public Name(Resource resource) { - this.resource = resource; + super(resource); } + @Override public String perform(ReadGraph graph) throws DatabaseException { Layer0 L0 = Layer0.getInstance(graph); - SynchronizationProcedure procedure = new SynchronizationProcedure(); - graph.forRelatedValue(resource, L0.HasName, procedure); - return procedure.getResult(); + return graph.getRelatedValue(resource, L0.HasName); } - @Override - public int hashCode() { - return getClass().hashCode() + 31 * resource.hashCode(); - } - @Override - public boolean equals(Object obj) { - if(obj == this) return true; - if(obj == null || obj.getClass() != getClass()) return false; - Name other = (Name)obj; - return resource.equals(other.resource); - } + } public static Read name(Resource resource) { return new Name(resource);