X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;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%2FNamespaceIndex.java;h=9f24ba64023a62b439c8c5bdc84345b826fae4ed;hb=3850fec72035293b9a4ede780d01aedc5fbc9056;hp=884f3f6d4e7ad37c0a124486a50f26173cefda37;hpb=1e957fc9da518f3bef8a2c19cad72772087e1b6a;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/NamespaceIndex.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMap.java similarity index 59% rename from bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/NamespaceIndex.java rename to bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMap.java index 884f3f6d4..9f24ba640 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/NamespaceIndex.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ChildMap.java @@ -13,33 +13,37 @@ package org.simantics.db.impl.query; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.serialization.Serializer; -import org.simantics.databoard.util.URIStringUtils; +import org.simantics.db.ObjectResourceIdMap; import org.simantics.db.common.WriteBindings; import org.simantics.db.common.exception.DebugException; import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.procedure.InternalProcedure; +import org.simantics.db.service.CollectionSupport; -import gnu.trove.map.hash.TObjectIntHashMap; - -final public class NamespaceIndex extends StringQuery>> { +final public class ChildMap extends UnaryQuery>> { - NamespaceIndex(final String id) { - super(id); + ChildMap(final int r) { + super(r); } @Override final public void removeEntry(QueryProcessor provider) { provider.cache.remove(this); } - - final static private void index(ReadGraphImpl graph, int root, NamespaceIndex entry, final InternalProcedure> procedure) throws DatabaseException { + + @Override + public Object compute(ReadGraphImpl graph, final InternalProcedure> procedure) throws DatabaseException { + computeForEach(graph, id, this, procedure); + return getResult(); + } + + 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); procedure.execute(graph, null); -// System.err.println("NamespaceIndex[" + id + "]->null"); return; } @@ -48,7 +52,7 @@ final public class NamespaceIndex extends StringQuery result = new TObjectIntHashMap(); + ObjectResourceIdMap result = graph.getService(CollectionSupport.class).createObjectResourceMap(String.class); QueryCache.runnerObjects(graph, root, consistsOf, entry, null, new SyncIntProcedure() { @@ -67,8 +71,6 @@ final public class NamespaceIndex extends StringQuery " + obj); inc(); @@ -91,12 +93,7 @@ final public class NamespaceIndex extends StringQuery> procedure) throws DatabaseException { - computeForEach(graph, id, this, procedure); - return getResult(); - } - - public static void computeForEach(ReadGraphImpl graph, final String id, final NamespaceIndex entry, final InternalProcedure> procedure) throws DatabaseException { - - QueryProcessor processor = graph.processor; - -// System.err.println("NamespaceIndex " + id); - - if("http://".equals(id) || "http:/".equals(id)) { - index(graph, processor.getRootLibrary(), entry, procedure); - } else { - final String[] parts = URIStringUtils.splitURI(id); - if(parts != null) { - QueryCache.runnerNamespaceIndex(graph, parts[0], entry, null, new InternalProcedure>() { - - @Override - public void execute(ReadGraphImpl graph, TObjectIntHashMap index) throws DatabaseException { - - if(index != null) { - index(graph, index.get(parts[1]), entry, procedure); - } else { - if(entry != null) entry.add2(graph, null); - procedure.execute(graph, null); -// System.err.println("NamespaceIndex[" + id + "]->null"); - } - - } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { - if(DebugException.DEBUG) new DebugException(t).printStackTrace(); - if(entry != null) entry.except(t); - procedure.exception(graph, t); - } - - }); - } else { - if(entry != null) entry.add2(graph, null); - procedure.execute(graph, null); -// System.err.println("NamespaceIndex[" + id + "]->null"); - } - - } - - } - @Override public String toString() { - return "NamespaceIndex[" + id + "]"; + return "ChildMap[" + id + "]"; } - private void add2(ReadGraphImpl graph, TObjectIntHashMap result) { - - if(!isPending()) { - new Exception(""+hashCode()).printStackTrace(); - } + private void add2(ReadGraphImpl graph, ObjectResourceIdMap result) { assert(isPending()); @@ -211,13 +153,13 @@ final public class NamespaceIndex extends StringQuery> procedure) throws DatabaseException { + public Object performFromCache(ReadGraphImpl graph, InternalProcedure> procedure) throws DatabaseException { assert(isReady()); if(handleException(graph, procedure)) return (Throwable)statusOrException; - TObjectIntHashMap result = (TObjectIntHashMap)getResult(); + ObjectResourceIdMap result = (ObjectResourceIdMap)getResult(); procedure.execute(graph, result); @@ -228,10 +170,10 @@ final public class NamespaceIndex extends StringQuery>() { + compute(graph, new InternalProcedure>() { @Override - public void execute(ReadGraphImpl graph, TObjectIntHashMap result) { + public void execute(ReadGraphImpl graph, ObjectResourceIdMap result) { } @Override