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<InternalProcedure<TObjectIntHashMap<String>>> {
+final public class ChildMap extends UnaryQuery<InternalProcedure<ObjectResourceIdMap<String>>> {
- 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<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+
+ @Override
+ public Object compute(ReadGraphImpl graph, final InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
+ computeForEach(graph, id, this, procedure);
+ return getResult();
+ }
+
+ public static void computeForEach(ReadGraphImpl graph, final int root, final ChildMap entry, final InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
if(root == 0) {
if(entry != null)
entry.add2(graph, null);
procedure.execute(graph, null);
-// System.err.println("NamespaceIndex[" + id + "]->null");
return;
}
final int consistsOf = processor.getConsistsOf();
final int hasName = processor.getHasName();
- final TObjectIntHashMap<String> result = new TObjectIntHashMap<String>();
+ ObjectResourceIdMap<String> result = graph.getService(CollectionSupport.class).createObjectResourceMap(String.class);
QueryCache.runnerObjects(graph, root, consistsOf, entry, null, new SyncIntProcedure() {
@Override
public void execute(ReadGraphImpl graph, final int obj) throws DatabaseException {
-
- //System.out.println(id + " => " + obj);
inc();
Binding b = WriteBindings.STRING;
Serializer serializer = b.serializer();
final String part = (String)serializer.deserialize(value);
-
- synchronized(result) {
- Object previous = result.put(URIStringUtils.escape(part), obj);
- // TODO: this is not the most elegant solution
- if(previous != null) previous = "";
- }
+ result.putId(part, obj);
} catch (Throwable e) {
if(DebugException.DEBUG) new DebugException(e).printStackTrace();
}
-
- @Override
- public Object compute(ReadGraphImpl graph, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
- computeForEach(graph, id, this, procedure);
- return getResult();
- }
-
- public static void computeForEach(ReadGraphImpl graph, final String id, final NamespaceIndex entry, final InternalProcedure<TObjectIntHashMap<String>> 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<TObjectIntHashMap<String>>() {
-
- @Override
- public void execute(ReadGraphImpl graph, TObjectIntHashMap<String> 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<String> result) {
-
- if(!isPending()) {
- new Exception(""+hashCode()).printStackTrace();
- }
+ private void add2(ReadGraphImpl graph, ObjectResourceIdMap<String> result) {
assert(isPending());
}
@Override
- public Object performFromCache(ReadGraphImpl graph, InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+ public Object performFromCache(ReadGraphImpl graph, InternalProcedure<ObjectResourceIdMap<String>> procedure) throws DatabaseException {
assert(isReady());
if(handleException(graph, procedure)) return (Throwable)statusOrException;
- TObjectIntHashMap<String> result = (TObjectIntHashMap<String>)getResult();
+ ObjectResourceIdMap<String> result = (ObjectResourceIdMap<String>)getResult();
procedure.execute(graph, result);
@Override
public void recompute(ReadGraphImpl graph) throws DatabaseException {
- compute(graph, new InternalProcedure<TObjectIntHashMap<String>>() {
+ compute(graph, new InternalProcedure<ObjectResourceIdMap<String>>() {
@Override
- public void execute(ReadGraphImpl graph, TObjectIntHashMap<String> result) {
+ public void execute(ReadGraphImpl graph, ObjectResourceIdMap<String> result) {
}
@Override