X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FCacheEntryBase.java;h=dea5de5a78d791799a63ae9898fb48dfdee6c84f;hb=68ce0966a57f5153b133c6283fdbae10f683b745;hp=4070e060d0090e96969520ce2a0dad0ab7647df0;hpb=a1dd54cd8e3595e66c83ad0e2d935470a3567481;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java index 4070e060d..dea5de5a7 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/CacheEntryBase.java @@ -14,15 +14,17 @@ package org.simantics.db.impl.query; import java.util.ArrayList; import java.util.Iterator; -import org.simantics.db.AsyncReadGraph; +import org.simantics.db.RelationInfo; import org.simantics.db.exception.DatabaseException; import org.simantics.db.impl.DebugPolicy; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.procedure.InternalProcedure; +import org.simantics.db.impl.query.QueryProcessor.Runner2Procedure; +import org.simantics.db.procedure.ListenerBase; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -abstract public class CacheEntryBase extends CacheEntry { +abstract public class CacheEntryBase extends CacheEntry { private static final Logger LOGGER = LoggerFactory.getLogger(CacheEntryBase.class); @@ -35,11 +37,11 @@ abstract public class CacheEntryBase extends CacheEntry { final public static CacheEntryBase[] NONE = new CacheEntryBase[0]; - static private Object NO_RESULT = new Object(); + static Object NO_RESULT = new Object(); static protected Object INVALID_RESULT = new Object(); - // Just created - static protected Object FRESH = new Object() { public String toString() { return "CREATED"; }}; +// // Just created +// static protected Object FRESH = new Object() { public String toString() { return "CREATED"; }}; // Result is computed - no exception static protected Object READY = new Object() { public String toString() { return "READY"; }}; // Computation is under way @@ -47,12 +49,12 @@ abstract public class CacheEntryBase extends CacheEntry { // Entry is discarded and is waiting for garbage collect static protected Object DISCARDED = new Object() { public String toString() { return "DISCARDED"; }}; // The result has been invalidated - static protected Object REFUTED = new Object() { public String toString() { return "REFUTED"; }}; + static protected Object REQUIRES_COMPUTATION = new Object() { public String toString() { return "REFUTED"; }}; // The computation has excepted - the exception is in the result static protected Object EXCEPTED = new Object() { public String toString() { return "EXCEPTED"; }}; // This indicates the status of the entry - public Object statusOrException = FRESH; + public Object statusOrException = REQUIRES_COMPUTATION; private CacheEntry p1 = null; private Object p2OrParents = null; @@ -68,10 +70,10 @@ abstract public class CacheEntryBase extends CacheEntry { abstract int makeHash(); // This can be tested to see if the result is finished - private Object result = NO_RESULT; + Object result = NO_RESULT; final public boolean isFresh() { - return FRESH == statusOrException; + return REQUIRES_COMPUTATION == statusOrException; } public void setReady() { @@ -97,16 +99,16 @@ abstract public class CacheEntryBase extends CacheEntry { @Override final public void refute() { if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: refuted " + this); - statusOrException = REFUTED; + statusOrException = REQUIRES_COMPUTATION; } @Override final public boolean isRefuted() { - return REFUTED == statusOrException; + return REQUIRES_COMPUTATION == statusOrException; } @Override - final public void except(Throwable t) { + public void except(Throwable t) { if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: excepted " + this); if(statusOrException != DISCARDED) { statusOrException = EXCEPTED; @@ -131,7 +133,7 @@ abstract public class CacheEntryBase extends CacheEntry { } @Override - final public void setPending() { + public void setPending() { statusOrException = PENDING; } @@ -140,6 +142,10 @@ abstract public class CacheEntryBase extends CacheEntry { return PENDING == statusOrException; } + final public boolean requiresComputation() { + return REQUIRES_COMPUTATION == statusOrException; + } + final public boolean assertPending() { boolean result = isPending(); if(!result) { @@ -320,9 +326,9 @@ abstract public class CacheEntryBase extends CacheEntry { } @Override - final public Iterable getParents(QueryProcessor processor) { + final public Iterable> getParents(QueryProcessor processor) { - ArrayList result = new ArrayList(); + ArrayList> result = new ArrayList>(); if(p1 != null) result.add(p1); if(p2OrParents != null) { if(p2OrParents instanceof QueryIdentityHashSet) { @@ -362,8 +368,7 @@ abstract public class CacheEntryBase extends CacheEntry { } - protected void fillImpliedParents(QueryProcessor processor, ArrayList result) { - + protected void fillImpliedParents(QueryProcessor processor, ArrayList> result) { } protected String internalError() { @@ -371,7 +376,7 @@ abstract public class CacheEntryBase extends CacheEntry { } - protected boolean handleException(ReadGraphImpl graph, IntProcedure procedure) { + protected boolean handleException(ReadGraphImpl graph, IntProcedure procedure) throws DatabaseException { if(isExcepted()) { procedure.exception(graph, (Throwable)getResult()); return true; @@ -380,7 +385,7 @@ abstract public class CacheEntryBase extends CacheEntry { } } - protected boolean handleException(ReadGraphImpl graph, TripleIntProcedure procedure) { + protected boolean handleException(ReadGraphImpl graph, TripleIntProcedure procedure) throws DatabaseException { if(isExcepted()) { procedure.exception(graph, (Throwable)getResult()); return true; @@ -389,7 +394,7 @@ abstract public class CacheEntryBase extends CacheEntry { } } - protected boolean handleException(ReadGraphImpl graph, InternalProcedure procedure) { + protected boolean handleException(ReadGraphImpl graph, InternalProcedure procedure) throws DatabaseException { if(isExcepted()) { procedure.exception(graph, (Throwable)getResult()); return true; @@ -426,10 +431,6 @@ abstract public class CacheEntryBase extends CacheEntry { clearResult(querySupport); } - /* - * - * - */ @Override int getGCStatus() { return GCStatus; @@ -455,10 +456,10 @@ abstract public class CacheEntryBase extends CacheEntry { // This is the original request for all built-in queries return getQuery(); } - -// abstract public void addOrSet(AsyncReadGraph graph, Object item); -// abstract public void except(AsyncReadGraph graph, Throwable t); - - //abstract public void perform(AsyncReadGraph graph, Object query, Object procedure); + + public CacheEntryBase() { + } + + //abstract public Object compute(ReadGraphImpl graph, Procedure procedure) throws DatabaseException; }