X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FTypeHierarchy.java;h=ad4581bb6a3e6045c877193dd9aecf8e6c316fd7;hb=68ce0966a57f5153b133c6283fdbae10f683b745;hp=6a96e11eaf65f857789740f77caa5e22ec48de91;hpb=e3290cc52342e783a2617f3009fff8e6f3e54560;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchy.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchy.java index 6a96e11ea..ad4581bb6 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchy.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/TypeHierarchy.java @@ -11,85 +11,34 @@ *******************************************************************************/ package org.simantics.db.impl.query; -import gnu.trove.procedure.TIntProcedure; - -import java.util.concurrent.Semaphore; - +import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.procedure.InternalProcedure; import org.simantics.db.procedure.ListenerBase; +import gnu.trove.procedure.TIntProcedure; + final public class TypeHierarchy extends UnaryQuery> { -// public ArrayList> procs = null; - - private TypeHierarchy(final int resource) { + TypeHierarchy(final int resource) { super(resource); } - final static void runner(ReadGraphImpl graph, final int r, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final InternalProcedure procedure) { - - TypeHierarchy entry = (TypeHierarchy)provider.cache.typeHierarchyMap.get(r); - if(entry == null) { - - entry = new TypeHierarchy(r); - entry.setPending(); - entry.clearResult(provider.querySupport); - entry.putEntry(provider); - - provider.performForEach(graph, entry, parent, listener, procedure); - - } else { - - if(!entry.isReady()) { - synchronized(entry) { - if(!entry.isReady()) { - throw new IllegalStateException(); -// if(entry.procs == null) entry.procs = new ArrayList>(); -// entry.procs.add(procedure); -// provider.registerDependencies(graph, entry, parent, listener, procedure, false); -// return; - } - } - } - provider.performForEach(graph, entry, parent, listener, procedure); - } - + final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { + QueryCache.runnerTypeHierarchy(graph, r, parent, listener, procedure); } - - final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure procedure) { - - if(parent == null && listener == null) { - TypeHierarchy entry = (TypeHierarchy)provider.cache.typeHierarchyMap.get(r); - if(entry != null && entry.isReady()) { - entry.performFromCache(graph, provider, procedure); - return; - } - } - - runner(graph, r, parent, provider, listener, procedure); - - } - - @Override - public UnaryQuery> getEntry(QueryProcessor provider) { - return provider.cache.typeHierarchyMap.get(id); - } - - @Override - public void putEntry(QueryProcessor provider) { - provider.cache.typeHierarchyMap.put(id, this); - } @Override final public void removeEntry(QueryProcessor provider) { - provider.cache.typeHierarchyMap.remove(id); + provider.cache.remove(this); } - @Override - public IntSet computeForEach(ReadGraphImpl graph, final QueryProcessor provider, final InternalProcedure procedure, boolean store) { + //@Override + public IntSet compute(ReadGraphImpl graph, final InternalProcedure procedure) throws DatabaseException { - final IntSet result = new IntSet(provider.querySupport, id); + QueryProcessor processor = graph.processor; + + final IntSet result = new IntSet(processor.querySupport, id); final TIntProcedure addToResult = new TIntProcedure() { @Override @@ -99,19 +48,19 @@ final public class TypeHierarchy extends UnaryQuery> { } }; - SuperTypes.queryEach(graph, id, provider, TypeHierarchy.this, null, new InternalProcedure() { + QueryCache.runnerSuperTypes(graph, id, TypeHierarchy.this, null, new InternalProcedure() { @Override - public void execute(ReadGraphImpl graph, IntSet types) { + public void execute(ReadGraphImpl graph, IntSet types) throws DatabaseException { types.forEach(addToResult); - addOrSet(graph, result, provider); + addOrSet(graph, result, processor); procedure.execute(graph, result); } @Override - public void exception(ReadGraphImpl graph, Throwable t) { + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { procedure.exception(graph, t); } @@ -130,29 +79,18 @@ final public class TypeHierarchy extends UnaryQuery> { assert(!isReady()); -// ArrayList> p = null; - synchronized(this) { value.trim(); setResult(value); setReady(); -// p = procs; -// procs = null; } - -// if(p != null) { -// IntSet v = (IntSet)getResult(); -// if(v != null) { -// for(InternalProcedure proc : p) proc.execute(graph, v); -// } -// } } @Override - public Object performFromCache(ReadGraphImpl graph, QueryProcessor provider, InternalProcedure procedure) { + public Object performFromCache(ReadGraphImpl graph, InternalProcedure procedure) throws DatabaseException { assert(isReady()); @@ -167,33 +105,26 @@ final public class TypeHierarchy extends UnaryQuery> { } @Override - public void recompute(ReadGraphImpl graph, QueryProcessor provider) { - - final Semaphore s = new Semaphore(0); - - computeForEach(graph, provider, new InternalProcedure() { + public void recompute(ReadGraphImpl graph) throws DatabaseException { + + compute(graph, new InternalProcedure() { @Override public void execute(ReadGraphImpl graph, IntSet result) { - s.release(); } @Override public void exception(ReadGraphImpl graph, Throwable t) { - s.release(); new Error("Error in recompute.", t).printStackTrace(); } - }, true); - - while(!s.tryAcquire()) { - provider.resume(graph); - } + }); } @Override boolean isImmutable(ReadGraphImpl graph) { return graph.processor.isImmutable(id); - } + } + }