X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FPrincipalTypes.java;fp=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FPrincipalTypes.java;h=af4d20ebca440dca89c2cdedef24bf11248f02f4;hb=d0e8f57df83c175bac2098412ee71646fb9ff0e9;hp=25e2b6fe3d317e682d41ebf42f60c2f6a628a83d;hpb=bdab0adcee131a18290393e1c2fca72de48c10d2;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PrincipalTypes.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PrincipalTypes.java index 25e2b6fe3..af4d20ebc 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PrincipalTypes.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/PrincipalTypes.java @@ -11,87 +11,29 @@ *******************************************************************************/ package org.simantics.db.impl.query; -import gnu.trove.procedure.TIntProcedure; -import gnu.trove.set.hash.TIntHashSet; - import java.util.ArrayList; import java.util.Arrays; import java.util.concurrent.Semaphore; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.procedure.IntProcedureAdapter; import org.simantics.db.impl.procedure.InternalProcedure; import org.simantics.db.procedure.ListenerBase; -final public class PrincipalTypes extends CollectionUnaryQuery { +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.set.hash.TIntHashSet; -// public ArrayList procs = null; +final public class PrincipalTypes extends CollectionUnaryQuery { - private PrincipalTypes(final int resource) { + PrincipalTypes(final int resource) { super(resource); } - final static PrincipalTypes entry(final QueryProcessor provider, final int r) { - return (PrincipalTypes)provider.principalTypesMap.get(r); - } - - final static void runner(ReadGraphImpl graph, final int r, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) { - - QueryProcessor processor = graph.processor; - - PrincipalTypes entry = (PrincipalTypes)processor.principalTypesMap.get(r); - if(entry == null) { - - entry = new PrincipalTypes(r); - entry.setPending(); - entry.clearResult(processor.querySupport); - entry.putEntry(processor); - - processor.performForEach(graph, entry, parent, listener, procedure); - - } else { - - if(entry.isPending()) { - synchronized(entry) { - if(entry.isPending()) { - throw new IllegalStateException(); -// if(entry.procs == null) entry.procs = new ArrayList(1); -// entry.procs.add(procedure); -// processor.registerDependencies(graph, entry, parent, listener, procedure, false); -// return; - } - } - } - processor.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 IntProcedure procedure) { - - assert(r != 0); - - if(parent == null && listener == null) { - PrincipalTypes.computeForEach(graph, r, null, graph.processor, procedure); - } else { - runner(graph, r, parent, listener, procedure); - } - - } - - @Override - public UnaryQuery getEntry(QueryProcessor provider) { - return provider.principalTypesMap.get(id); - } - - @Override - public void putEntry(QueryProcessor provider) { - provider.principalTypesMap.put(id, this); - } - @Override final public void removeEntry(QueryProcessor provider) { - provider.principalTypesMap.remove(id); + provider.cache.remove(this); } static class Koss { @@ -133,14 +75,14 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } - @Override - public Object computeForEach(final ReadGraphImpl procedureGraph, final QueryProcessor provider, final IntProcedure proc, final boolean store) { - - return computeForEach(procedureGraph, id, this, provider, proc); - + //@Override + public Object compute(final ReadGraphImpl graph, final IntProcedure proc) throws DatabaseException { + return computeForEach(graph, id, this, proc); } - public static Object computeForEach(final ReadGraphImpl graph, final int id, final PrincipalTypes entry, final QueryProcessor provider, final IntProcedure proc) { + public static Object computeForEach(final ReadGraphImpl graph, final int id, final PrincipalTypes entry, final IntProcedure proc) throws DatabaseException { + + QueryProcessor provider = graph.processor; provider.querySupport.ensureLoaded(graph, id); assert(id != 0); @@ -171,7 +113,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } @Override - public void exception(ReadGraphImpl graph, Throwable t) { + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { proc.exception(graph, t); } @@ -189,7 +131,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } @Override - public void exception(ReadGraphImpl graph, Throwable t) { + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { proc.exception(graph, t); } @@ -232,6 +174,15 @@ final public class PrincipalTypes extends CollectionUnaryQuery { @Override public boolean execute(final int arg0) { + try { + return execute0(arg0); + } catch (DatabaseException e) { + Logger.defaultLogError(e); + } + return false; + } + + public boolean execute0(final int arg0) throws DatabaseException { // No self-loops! if(arg0 == id) { @@ -259,7 +210,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { return true; } - PrincipalTypes.queryEach(graph, arg0, provider, entry, null, new IntProcedure() { + QueryCache.runnerPrincipalTypes(graph, arg0, entry, null, new IntProcedure() { @Override public void execute(ReadGraphImpl graph, int i) { @@ -269,7 +220,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } @Override - public void finished(ReadGraphImpl graph) { + public void finished(ReadGraphImpl graph) throws DatabaseException { int current = (++finishes); if(current == indirect.size()) { @@ -296,7 +247,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } @Override - public void exception(ReadGraphImpl graph, Throwable t) { + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { proc.exception(graph, t); } @@ -312,7 +263,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } - private static void finish(ReadGraphImpl graph, final TIntHashSet rejects, final int[] material, final PrincipalTypes entry, final QueryProcessor provider, final IntProcedure proc) { + private static void finish(ReadGraphImpl graph, final TIntHashSet rejects, final int[] material, final PrincipalTypes entry, final QueryProcessor provider, final IntProcedure proc) throws DatabaseException { if(entry != null) { for(int i : material) { @@ -335,7 +286,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } - private static void addPrincipalType(final ReadGraphImpl graph, final TIntHashSet rejects, final int[] material, int index, final QueryProcessor provider, final PrincipalTypes entry, final IntProcedure proc) { + private static void addPrincipalType(final ReadGraphImpl graph, final TIntHashSet rejects, final int[] material, int index, final QueryProcessor provider, final PrincipalTypes entry, final IntProcedure proc) throws DatabaseException { // if((counter++ % 500) == 0) System.out.println("PT " + counter + " mat = " + material.length); @@ -354,10 +305,10 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } final int nextIndex = index; - SuperTypes.queryEach(graph, type, provider, entry, null, new InternalProcedure() { + QueryCache.runnerSuperTypes(graph, type, entry, null, new InternalProcedure() { @Override - public void execute(ReadGraphImpl graph, IntSet supers) { + public void execute(ReadGraphImpl graph, IntSet supers) throws DatabaseException { synchronized(rejects) { @@ -378,7 +329,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } @Override - public void exception(ReadGraphImpl graph, Throwable t) { + public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException { proc.exception(graph, t); } @@ -400,41 +351,14 @@ final public class PrincipalTypes extends CollectionUnaryQuery { final private void finish(ReadGraphImpl graph, QueryProcessor provider) { assert(isPending()); - -// ArrayList p = null; - synchronized(this) { - setReady(); -// p = procs; -// procs = null; - } -// if(p != null) { -// -// IntArray v = (IntArray)getResult(); -// if(v != null) { -// if(v.data == null) { -// if(v.sizeOrData != IntArray.NO_DATA) { -// for(IntProcedure proc : p) proc.execute(graph, v.sizeOrData); -// } -// } else { -// for(IntProcedure proc : p) { -// for(int i = 0;i < v.sizeOrData ; i++) proc.execute(graph, v.data[i]); -// } -// } -// } -// -// for(IntProcedure proc : p) proc.finished(graph); -// -// } - - } @Override - public Object performFromCache(ReadGraphImpl graph, QueryProcessor provider, final IntProcedure procedure) { + public Object performFromCache(ReadGraphImpl graph, final IntProcedure procedure) throws DatabaseException { assert(isReady()); @@ -454,28 +378,20 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } @Override - public void recompute(ReadGraphImpl graph, QueryProcessor provider) { + public void recompute(ReadGraphImpl graph) throws DatabaseException { - final Semaphore s = new Semaphore(0); - - computeForEach(graph, provider, new IntProcedureAdapter() { + compute(graph, new IntProcedureAdapter() { @Override public void finished(ReadGraphImpl graph) { - 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); - } + }); } @@ -486,8 +402,7 @@ final public class PrincipalTypes extends CollectionUnaryQuery { } @Override - protected void fillImpliedParents(QueryProcessor processor, ArrayList result) { -// for(Objects o : Objects.entries(processor, id)) result.add(o); + protected void fillImpliedParents(QueryProcessor processor, ArrayList> result) { } }