X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FTypes.java;h=35c43885adc83161416041709b83e10f5abcb6d2;hb=de8b6e194da6d56c410101d9c72763078b0e8717;hp=512045e17be63f354fd12a41a9d87cfd17d1afca;hpb=880a8a4927805afbbf47005a807cef3f39406866;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Types.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Types.java index 512045e17..35c43885a 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Types.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/Types.java @@ -19,154 +19,156 @@ import org.simantics.db.impl.procedure.InternalProcedure; import gnu.trove.procedure.TIntProcedure; -final public class Types extends UnaryQuery> { - +final public class Types extends UnaryQueryP { + Types(final int resource) { super(resource); } - @Override - final public void removeEntry(QueryProcessor provider) { - provider.cache.remove(this); - } + @Override + final public void removeEntry(QueryProcessor provider) { + provider.cache.remove(this); + } - //@Override - public Object compute(final ReadGraphImpl graph, final InternalProcedure procedure) throws DatabaseException { - computeForEach(graph, id, this, procedure); - return getResult(); - } + @Override + public void compute(final ReadGraphImpl graph, final InternalProcedure procedure) throws DatabaseException { + computeForEach(graph, id, this, procedure); + } - public static void computeForEach(final ReadGraphImpl graph, int id, Types entry, final InternalProcedure procedure) throws DatabaseException { + public static void computeForEach(final ReadGraphImpl graph, int id, Types entry, + final InternalProcedure procedure_) throws DatabaseException { - assert(procedure != null); + InternalProcedure procedure = entry != null ? entry : procedure_; + + computeForEach2(graph, id, entry, procedure); + + if (entry != null) + entry.performFromCache(graph, procedure_); + + } - QueryProcessor processor = graph.processor; + public static void computeForEach2(final ReadGraphImpl graph, int id, Types parent, + final InternalProcedure procedure) throws DatabaseException { - processor.querySupport.ensureLoaded(graph, id); - - int ret = processor.querySupport.getSingleInstance(id); - if(ret > 0) { + QueryProcessor processor = graph.processor; - TypeHierarchy.queryEach(graph, ret, processor, entry, null, new InternalProcedure() { + processor.querySupport.ensureLoaded(graph, id); - @Override - public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException { + int ret = processor.querySupport.getSingleInstance(id); + if (ret > 0) { - if(entry != null) { - entry.addOrSet(graph, types, processor); - entry.finish(); - } - procedure.execute(graph, types); + TypeHierarchy.queryEach(graph, ret, processor, parent, null, new InternalProcedure() { - } + @Override + public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException { + procedure.execute(graph, types); + } - @Override - public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { - procedure.exception(graph, t); - } + @Override + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { + procedure.exception(graph, t); + } - }); - - return; + }); - } - - final int instanceOf = processor.getInstanceOf(); + return; + + } + + final int instanceOf = processor.getInstanceOf(); final int inherits = processor.getInherits(); final int subrelationOf = processor.getSubrelationOf(); final IntSet result = new IntSet(processor.querySupport); - + final TIntProcedure addToResult = new TIntProcedure() { @Override public boolean execute(int r) { - synchronized(result) { - result.add(r); - } + synchronized (result) { + result.add(r); + } return true; } }; - + final AtomicInteger finishes = new AtomicInteger(0); - + SyncIntProcedure instanceOfProcedure = new SyncIntProcedure() { - + @Override public void run(ReadGraphImpl graph) throws DatabaseException { - - if(finishes.addAndGet(1) == 3) { - if(entry != null) entry.addOrSet(graph, result, processor); + + if (finishes.addAndGet(1) == 3) { procedure.execute(graph, result); - } - + } + } - + @Override public void execute(ReadGraphImpl graph, int i) throws DatabaseException { - - result.add(i); - + + result.add(i); + inc(); - QueryCache.runnerSuperTypes(graph, i, entry, null, new InternalProcedure() { + QueryCache.runnerSuperTypes(graph, i, parent, null, new InternalProcedure() { @Override public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException { types.forEach(addToResult); dec(graph); } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { - procedure.exception(graph, t); + + @Override + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { + procedure.exception(graph, t); dec(graph); - } + } }); - + } @Override public void finished(ReadGraphImpl graph) throws DatabaseException { dec(graph); } - - }; - + + }; + SyncIntProcedure inheritsProcedure = new SyncIntProcedure() { - + @Override public void run(ReadGraphImpl graph) throws DatabaseException { - int current = finishes.addAndGet(1); - if(current == 3) { - if(entry != null) entry.addOrSet(graph, result, processor); + int current = finishes.addAndGet(1); + if (current == 3) { procedure.execute(graph, result); - } - + } + } - + @Override public void execute(ReadGraphImpl graph, int i) throws DatabaseException { - + inc(); - QueryCache.runnerTypes(graph, i, entry, null, new InternalProcedure() { + QueryCache.runnerTypes(graph, i, parent, null, new InternalProcedure() { @Override public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException { types.forEach(addToResult); dec(graph); } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { - procedure.exception(graph, t); + + @Override + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { + procedure.exception(graph, t); dec(graph); - } + } }); - + } @Override @@ -175,124 +177,67 @@ final public class Types extends UnaryQuery> { dec(graph); } - - }; + + }; SyncIntProcedure subrelationOfProcedure = new SyncIntProcedure() { @Override public void run(ReadGraphImpl graph) throws DatabaseException { - int current = finishes.addAndGet(1); - if(current == 3) { - if(entry != null) entry.addOrSet(graph, result, processor); + int current = finishes.addAndGet(1); + if (current == 3) { procedure.execute(graph, result); - } - + } + } - + @Override public void execute(ReadGraphImpl graph, int i) throws DatabaseException { - + inc(); - - QueryCache.runnerTypes(graph, i, entry, null, new InternalProcedure() { + + QueryCache.runnerTypes(graph, i, parent, null, new InternalProcedure() { @Override public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException { types.forEach(addToResult); dec(graph); - + } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { - procedure.exception(graph, t); + + @Override + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { + procedure.exception(graph, t); dec(graph); - } + } }); - + } @Override public void finished(ReadGraphImpl graph) throws DatabaseException { - + dec(graph); } - - }; - + + }; + processor.querySupport.getObjects(graph, id, instanceOf, instanceOfProcedure); instanceOfProcedure.finished(graph); processor.querySupport.getObjects(graph, id, inherits, inheritsProcedure); inheritsProcedure.finished(graph); processor.querySupport.getObjects(graph, id, subrelationOf, subrelationOfProcedure); subrelationOfProcedure.finished(graph); - - if(entry != null) entry.finish(); - - } - - @Override - public String toString() { - return "Types[" + id + "]"; - } - - private void addOrSet(ReadGraphImpl graph, final IntSet value, QueryProcessor provider) { - - assert(!isReady()); - setResult(value); - } - - void finish() { - IntSet result = getResult(); - result.trim(); - setReady(); - - } - - @Override - final public Object performFromCache(ReadGraphImpl graph, InternalProcedure procedure) throws DatabaseException { - - assert(isReady()); - - if(handleException(graph, procedure)) return EXCEPTED; - - IntSet result = getResult(); - - procedure.execute(graph, result); - - return result; - - } - @Override - public void recompute(ReadGraphImpl graph) throws DatabaseException { - - compute(graph, new InternalProcedure() { - - @Override - public void execute(ReadGraphImpl graph, IntSet result) { - } - - @Override - public void exception(ReadGraphImpl graph, Throwable t) { - new Error("Error in recompute.", t).printStackTrace(); - } - - }); - + public String toString() { + return "Types[" + id + "]"; } - @Override - boolean isImmutable(ReadGraphImpl graph) { - return graph.processor.isImmutable(id); - } - }