import java.util.ArrayList;
import java.util.Iterator;
+import org.simantics.databoard.Bindings;
+import org.simantics.db.DevelopmentKeys;
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.utils.Development;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final public static CacheEntryBase[] NONE = new CacheEntryBase[0];
- static Object NO_RESULT = new Object();
- static protected Object INVALID_RESULT = new Object();
+ static Object NO_RESULT = new Object() { public String toString() { return "NO_RESULT"; }};
+ static protected Object INVALID_RESULT = new Object() { public String toString() { return "INVALID_RESULT"; }};
// // Just created
// static protected Object FRESH = new Object() { public String toString() { return "CREATED"; }};
}
public void setReady() {
+ assert(result != NO_RESULT);
statusOrException = READY;
}
@Override
public void discard() {
- if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: discarded " + this);
+ if (Development.DEVELOPMENT) {
+ if(Development.<Boolean>getProperty(DevelopmentKeys.CACHE_ENTRY_STATE, Bindings.BOOLEAN)) {
+ System.err.println("[QUERY STATE]: discarded " + this);
+ }
+ }
statusOrException = DISCARDED;
}
@Override
final public void refute() {
- if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: refuted " + this);
+ if (Development.DEVELOPMENT) {
+ if(Development.<Boolean>getProperty(DevelopmentKeys.CACHE_ENTRY_STATE, Bindings.BOOLEAN)) {
+ System.err.println("[QUERY STATE]: refuted " + this);
+ }
+ }
statusOrException = REQUIRES_COMPUTATION;
}
@Override
public void except(Throwable throwable) {
- if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: excepted " + this);
+ if (Development.DEVELOPMENT) {
+ if(Development.<Boolean>getProperty(DevelopmentKeys.CACHE_ENTRY_STATE, Bindings.BOOLEAN)) {
+ System.err.println("[QUERY STATE]: excepted " + this);
+ }
+ }
if(statusOrException != DISCARDED) {
statusOrException = EXCEPTED;
result = throwable;
}
@Override
- public void setPending() {
- statusOrException = PENDING;
+ public void setPending(QuerySupport querySupport) {
+ statusOrException = PENDING;
+ clearResult(querySupport);
}
@Override
}
}
-
+
+ @Override
+ void pruneParentSet() {
+ // First parent is discarded => look for more parents
+ if(p2OrParents instanceof QueryIdentityHashSet) {
+
+ QueryIdentityHashSet set = (QueryIdentityHashSet)p2OrParents;
+ set.removeDiscardedReally();
+ if(set.isEmpty()) p2OrParents = null;
+
+ } else if(p2OrParents instanceof CacheEntry) {
+
+ CacheEntry entry = (CacheEntry)p2OrParents;
+ if(entry.isDiscarded()) {
+ // Second entry is also discarded => all empty
+ p2OrParents = null;
+ }
+
+ } else {
+
+ // Nothing left
+
+ }
+ }
+
@Override
final public void removeParent(CacheEntry entry) {
@Override
void prepareRecompute(QuerySupport querySupport) {
- setPending();
- clearResult(querySupport);
+ setPending(querySupport);
}
@Override