package org.simantics.db.impl.query;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import org.simantics.databoard.Bindings;
}
@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
- final public Iterable<CacheEntry<?>> getParents(QueryProcessor processor) {
+ final public Collection<CacheEntry<?>> getParents(QueryProcessor processor) {
ArrayList<CacheEntry<?>> result = new ArrayList<CacheEntry<?>>();
if(p1 != null) result.add(p1);
@Override
void prepareRecompute(QuerySupport querySupport) {
- setPending();
- clearResult(querySupport);
+ setPending(querySupport);
}
@Override
public CacheEntryBase() {
}
+
+ public String classId() {
+ return getClass().getName();
+ }
+
+ public void serializeKey(QuerySerializer serializer) {
+ throw new IllegalStateException("Cannot serialize query key for " + this);
+ }
+
+ public void serializeValue(QuerySerializer serializer) {
+ throw new IllegalStateException("Cannot serialize query value for " + this);
+ }
+
+ public void serializeParents(QuerySerializer serializer) {
+ Collection<CacheEntry<?>> ps = getParents(serializer.getQueryProcessor());
+ int sizePos = serializer.writeUnknownSize();
+ int actual = 0;
+ for(CacheEntry<?> entry : ps) {
+ CacheEntryBase b = (CacheEntryBase)entry;
+ String cid = b.classId();
+ if(cid == null)
+ continue;
+ serializer.serializeId(b.classId());
+ b.serializeKey(serializer);
+ actual++;
+ }
+ serializer.setUnknownSize(sizePos, actual);
+ }
+
+ public long cluster(QueryProcessor processor) {
+ throw new IllegalStateException("Cannot compute query cluster for " + this);
+ }
+
+ public void serialize(QuerySerializer serializer) {
+ serializer.serializeId(classId());
+ serializeKey(serializer);
+ serializeValue(serializer);
+ serializeParents(serializer);
+ }
}