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=547264f4b0c99fb75368e5c448d82965038994a1;hb=de8b6e194da6d56c410101d9c72763078b0e8717;hp=78ae0d12d0ba0a147ca79b7ac65f894952e2bf47;hpb=3850fec72035293b9a4ede780d01aedc5fbc9056;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 78ae0d12d..547264f4b 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 @@ -15,10 +15,11 @@ 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; -public class URIToResource extends StringQuery> { +public class URIToResource extends StringQuery> implements InternalProcedure { URIToResource(final String id) { super(id); @@ -29,18 +30,19 @@ public class URIToResource extends StringQuery> { provider.cache.remove(this); } - @Override + //@Override public Object compute(ReadGraphImpl graph, final InternalProcedure procedure) throws DatabaseException { computeForEach(graph, id, this, procedure); return getResult(); } - static void computeForEach(ReadGraphImpl graph, String id, final URIToResource entry, final InternalProcedure procedure) throws DatabaseException { + static void computeForEach(ReadGraphImpl graph, String id, final URIToResource entry, final InternalProcedure procedure_) throws DatabaseException { + + InternalProcedure procedure = entry != null ? entry : procedure_; if("http://".equals(id) || "http:/".equals(id)) { QueryProcessor processor = graph.processor; - if(entry != null) entry.addOrSet(graph, processor, processor.getRootLibrary()); procedure.execute(graph, processor.getRootLibrary()); } else { @@ -48,30 +50,42 @@ public class URIToResource extends StringQuery> { final String[] parts = URIStringUtils.splitURI(id); if (parts != null) { - Integer parentId = QueryCache.resultURIToResource(graph, parts[0], entry, null); - ObjectResourceIdMap map = QueryCache.resultChildMap(graph, parentId, entry, null); - if(map == null) { - procedure.execute(graph, 0); - if(entry != null) entry.addOrSet(graph, graph.processor, 0); - } else { - int result = map.getId(URIStringUtils.unescape(parts[1])); - if(entry != null) entry.addOrSet(graph, graph.processor, result); - procedure.execute(graph, result); - } + 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); + int result = map.getId(URIStringUtils.unescape(parts[1])); + if (result == 0) { + ResourceNotFoundException e = new ResourceNotFoundException("No resource for URI: " + id); + procedure.exception(graph, e); + } else { + procedure.execute(graph, result); + } + } + + @Override + public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException { + procedure.exception(graph, throwable); + } + + }); + } else { - - DatabaseException e = new DatabaseException("No URI for " + id); - if(entry != null) entry.except(e); - procedure.exception(graph, e); - + ResourceNotFoundException e = new ResourceNotFoundException("No resource for URI: " + id); + procedure.exception(graph, e); } } + if(entry != null) entry.performFromCache(graph, procedure_); + } - public void addOrSet(ReadGraphImpl graph, QueryProcessor provider, Integer result) { + public void addOrSet(Integer result) { assert(isPending()); @@ -92,7 +106,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); @@ -118,5 +132,18 @@ public class URIToResource extends StringQuery> { }); } + + @Override + public void execute(ReadGraphImpl graph, Integer result) throws DatabaseException { + synchronized(this) { + setResult(result); + setReady(); + } + } + + @Override + public void exception(ReadGraphImpl graph, Throwable throwable) throws DatabaseException { + except(throwable); + } }