X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FURIToResource.java;h=918f882f179c2acd4ba8b79677f473abacf67deb;hb=4af843556485409e1c018e58eb2409f116e4d40c;hp=5a44fc2eb608a273139501ac827a264265f1f5d3;hpb=9fcf23f51b59d737a05178832760a8dab950eb8d;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java index 5a44fc2eb..918f882f1 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/URIToResource.java @@ -12,13 +12,12 @@ package org.simantics.db.impl.query; import org.simantics.databoard.util.URIStringUtils; +import org.simantics.db.ObjectResourceIdMap; import org.simantics.db.common.exception.DebugException; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.exception.ResourceNotFoundException; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.procedure.InternalProcedure; -import org.simantics.db.procedure.ListenerBase; - -import gnu.trove.map.hash.TObjectIntHashMap; public class URIToResource extends StringQuery> { @@ -30,40 +29,8 @@ public class URIToResource extends StringQuery> { final public void removeEntry(QueryProcessor provider) { provider.cache.remove(this); } - - private static void lookup(ReadGraphImpl graph, final URIToResource entry, final InternalProcedure procedure, final String namespace, final String name) throws DatabaseException { - - QueryCache.runnerNamespaceIndex(graph, namespace, entry, null, new InternalProcedure>() { - - @Override - public void execute(ReadGraphImpl graph, TObjectIntHashMap index) throws DatabaseException { - - if(index != null) { - int result = index.get(name); - if(result != 0) { - if(entry != null) entry.addOrSet(graph, graph.processor, result); - procedure.execute(graph, result); - return; - } - } - - Integer zero = 0; - if(entry != null) entry.addOrSet(graph, graph.processor, zero); - procedure.execute(graph, zero); - - } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { - if(entry != null) entry.except(t); - procedure.exception(graph, t); - } - - }); - - } - @Override + //@Override public Object compute(ReadGraphImpl graph, final InternalProcedure procedure) throws DatabaseException { computeForEach(graph, id, this, procedure); return getResult(); @@ -81,9 +48,53 @@ public class URIToResource extends StringQuery> { final String[] parts = URIStringUtils.splitURI(id); if (parts != null) { - lookup(graph, entry, procedure, parts[0], parts[1]); + + //Integer parentId = QueryCache.resultURIToResource(graph, parts[0], entry, null); + + QueryCache.runnerURIToResource(graph, parts[0], entry, null, new InternalProcedure() { + + @Override + public void execute(ReadGraphImpl graph, Integer parentId) throws DatabaseException { + + ObjectResourceIdMap map = QueryCache.resultChildMap(graph, parentId, entry, null); + assert(map != null); +// if(map == null) { +// throw new DatabaseException("Internal Error, contact application support."); +// if(entry != null) entry.except(e); +// procedure.exception(graph, e); +//// procedure.execute(graph, 0); +//// if(entry != null) entry.addOrSet(graph, graph.processor, 0); +// } else { + int result = map.getId(URIStringUtils.unescape(parts[1])); + if(result == 0) { + ResourceNotFoundException e = new ResourceNotFoundException("No resource for URI: " + id); + if(entry != null) entry.except(e); + procedure.exception(graph, e); + } else { + if(entry != null) entry.addOrSet(graph, graph.processor, result); + procedure.execute(graph, result); + } +// } + + // TODO Auto-generated method stub + + } + + @Override + public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException { + if(entry != null) entry.except(throwable); + procedure.exception(graph, throwable); + } + + }); + + } else { - lookup(graph, entry, procedure, "http://", id.replaceFirst("http://", "")); + + ResourceNotFoundException e = new ResourceNotFoundException("No resource for URI: " + id); + if(entry != null) entry.except(e); + procedure.exception(graph, e); + } } @@ -111,7 +122,7 @@ public class URIToResource extends StringQuery> { assert(isReady()); - if(handleException(graph, procedure)) return (Throwable)statusOrException; + if(handleException(graph, procedure)) return (Throwable)getResult(); Integer result = (Integer)getResult(); procedure.execute(graph, result);