X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FChildMap.java;fp=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FChildMap.java;h=19c36c77c67491483d2d0d48b4505522e5007968;hb=de8b6e194da6d56c410101d9c72763078b0e8717;hp=7dd00d29ba7815443809c556070647c78d8a6ebc;hpb=880a8a4927805afbbf47005a807cef3f39406866;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMap.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMap.java index 7dd00d29b..19c36c77c 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMap.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMap.java @@ -21,170 +21,130 @@ import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.procedure.InternalProcedure; import org.simantics.db.service.CollectionSupport; -final public class ChildMap extends UnaryQuery>> { - +final public class ChildMap extends UnaryQueryP> { + ChildMap(final int r) { super(r); } - - @Override - final public void removeEntry(QueryProcessor provider) { - provider.cache.remove(this); - } - - //@Override - public Object compute(ReadGraphImpl graph, final InternalProcedure> procedure) throws DatabaseException { - computeForEach(graph, id, this, procedure); - return getResult(); + + @Override + final public void removeEntry(QueryProcessor provider) { + provider.cache.remove(this); } - public static void computeForEach(ReadGraphImpl graph, final int root, final ChildMap entry, final InternalProcedure> procedure) throws DatabaseException { - - if(root == 0) { - if(entry != null) - entry.add2(graph, null); + @Override + public void compute(ReadGraphImpl graph, final InternalProcedure> procedure) + throws DatabaseException { + computeForEach(graph, id, this, procedure); + } + + public static void computeForEach(ReadGraphImpl graph, final int root, final ChildMap entry, + final InternalProcedure> procedure_) throws DatabaseException { + + InternalProcedure> procedure = entry != null ? entry : procedure_; + + computeForEach2(graph, root, entry, procedure); + + if (entry != null) + entry.performFromCache(graph, procedure_); + + } + + public static void computeForEach2(ReadGraphImpl graph, final int root, final ChildMap parent, + final InternalProcedure> procedure) throws DatabaseException { + + if (root == 0) { procedure.execute(graph, null); return; - } - - QueryProcessor processor = graph.processor; - - final int consistsOf = processor.getConsistsOf(); - final int hasName = processor.getHasName(); - - ObjectResourceIdMap result = graph.getService(CollectionSupport.class).createObjectResourceMap(String.class); - - QueryCache.runnerObjects(graph, root, consistsOf, entry, null, new SyncIntProcedure() { - - @Override - public void run(ReadGraphImpl graph) throws DatabaseException { - - if(entry != null) entry.add2(graph, result); - procedure.execute(graph, result); - - } - - @Override - public void finished(ReadGraphImpl graph) throws DatabaseException { - dec(graph); - } - - @Override - public void execute(ReadGraphImpl graph, final int obj) throws DatabaseException { - - inc(); - - QueryCache.runnerObjects(graph, obj, hasName, entry, null, new IntProcedure() { - - @Override - public void execute(ReadGraphImpl graph, int i) throws DatabaseException { - - inc(); - - QueryCache.runnerValueQuery(graph, i, entry, null, new InternalProcedure() { - - @Override - public void execute(ReadGraphImpl graph, byte[] value) throws DatabaseException { - - if(value != null) { - - try { - - Binding b = WriteBindings.STRING; - Serializer serializer = b.serializer(); - final String part = (String)serializer.deserialize(value); - result.putId(part, obj); - - } catch (Throwable e) { - if(DebugException.DEBUG) new DebugException(e).printStackTrace(); - } - - } - - dec(graph); - - } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { - if(entry != null) entry.except(t); - dec(graph); + } + + QueryProcessor processor = graph.processor; + + final int consistsOf = processor.getConsistsOf(); + final int hasName = processor.getHasName(); + + ObjectResourceIdMap result = graph.getService(CollectionSupport.class) + .createObjectResourceMap(String.class); + + QueryCache.runnerObjects(graph, root, consistsOf, parent, null, new SyncIntProcedure() { + + @Override + public void run(ReadGraphImpl graph) throws DatabaseException { + procedure.execute(graph, result); + } + + @Override + public void finished(ReadGraphImpl graph) throws DatabaseException { + dec(graph); + } + + @Override + public void execute(ReadGraphImpl graph, final int obj) throws DatabaseException { + + inc(); + + QueryCache.runnerObjects(graph, obj, hasName, parent, null, new IntProcedure() { + + @Override + public void execute(ReadGraphImpl graph, int i) throws DatabaseException { + + inc(); + + QueryCache.runnerValueQuery(graph, i, parent, null, new InternalProcedure() { + + @Override + public void execute(ReadGraphImpl graph, byte[] value) throws DatabaseException { + + if (value != null) { + + try { + + Binding b = WriteBindings.STRING; + Serializer serializer = b.serializer(); + final String part = (String) serializer.deserialize(value); + result.putId(part, obj); + + } catch (Throwable e) { + if (DebugException.DEBUG) + new DebugException(e).printStackTrace(); + } + + } + + dec(graph); + + } + + @Override + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { + dec(graph); } - }); - - } - - @Override - public void finished(ReadGraphImpl graph) throws DatabaseException { - dec(graph); - } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { - if(entry != null) entry.except(t); + }); + + } + + @Override + public void finished(ReadGraphImpl graph) throws DatabaseException { + dec(graph); + } + + @Override + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { dec(graph); } }); - } - + } + }); - - } - @Override - public String toString() { - return "ChildMap[" + id + "]"; } - private void add2(ReadGraphImpl graph, ObjectResourceIdMap result) { - - assert(isPending()); - - synchronized(this) { - - setResult(result); - setReady(); - - } - - } - @Override - public Object performFromCache(ReadGraphImpl graph, InternalProcedure> procedure) throws DatabaseException { - - assert(isReady()); - - if(handleException(graph, procedure)) return (Throwable)statusOrException; - - ObjectResourceIdMap result = (ObjectResourceIdMap)getResult(); - - procedure.execute(graph, result); - - return result; - + public String toString() { + return "ChildMap[" + id + "]"; } - - @Override - public void recompute(ReadGraphImpl graph) throws DatabaseException { - - compute(graph, new InternalProcedure>() { - - @Override - public void execute(ReadGraphImpl graph, ObjectResourceIdMap result) { - } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) { - if(DebugException.DEBUG) new DebugException(t).printStackTrace(); - throw new Error("Error in recompute.", t); - } - }); - - } - } -