*******************************************************************************/
package org.simantics.db.common.primitiverequest;
+import java.util.Collection;
+
import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.ReadGraph;
import org.simantics.db.Resource;
-import org.simantics.db.common.request.ResourceAsyncMultiRead2;
+import org.simantics.db.common.request.ResourceRead2;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.AsyncMultiProcedure;
+import org.simantics.db.service.CollectionSupport;
+import org.simantics.utils.DataContainer;
-final public class ForEachAssertedObject extends ResourceAsyncMultiRead2<Resource> {
+final public class ForEachAssertedObject extends ResourceRead2<Collection<Resource>> {
public ForEachAssertedObject(Resource subject, Resource relation) {
super(subject, relation);
}
@Override
- public void perform(AsyncReadGraph graph, AsyncMultiProcedure<Resource> procedure) {
- graph.forEachAssertedObject(resource, resource2, procedure);
+ public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
+ CollectionSupport cs = graph.getService(CollectionSupport.class);
+ Collection<Resource> result = cs.createSet();
+ DataContainer<Throwable> throwable = new DataContainer<Throwable>(null);
+ graph.forEachAssertedObject(resource, resource2, new AsyncMultiProcedure<Resource>() {
+
+ @Override
+ public void finished(AsyncReadGraph graph) {
+ }
+
+ @Override
+ public void execute(AsyncReadGraph graph, Resource r) {
+ result.add(r);
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable t) {
+ throwable.set(t);
+ }
+ });
+ Throwable t = throwable.get();
+ if(t != null)
+ if(t instanceof DatabaseException)
+ throw (DatabaseException)t;
+ else throw new DatabaseException(t);
+ return result;
}
}
public int hashCode() {
return resource.hashCode();
}
-
- @Override
- final public int threadHash() {
- return resource.getThreadHash();
- }
@Override
public boolean equals(Object object) {
import org.simantics.db.procedure.SyncProcedure;
import org.simantics.db.request.AsyncRead;
import org.simantics.db.request.ReadInterface;
-import org.simantics.db.request.Request;
-public abstract class ResourceAsyncRead2<T> implements AsyncRead<T>, Request, ReadInterface<T> {
+public abstract class ResourceAsyncRead2<T> implements AsyncRead<T>, ReadInterface<T> {
final protected Resource resource;
final protected Resource resource2;
final public class AssertedPredicates extends CollectionUnaryQuery<IntProcedure> {
-// public ArrayList<IntProcedure> procs = null;
-
public AssertedPredicates(final int r) {
super(r);
}
final static void runner(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {
- AssertedPredicates entry = (AssertedPredicates)provider.assertedPredicatesMap.get(r);
+ AssertedPredicates entry = (AssertedPredicates)provider.cache.assertedPredicatesMap.get(r);
if(entry == null) {
entry = new AssertedPredicates(r);
final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {
if(parent == null && listener == null) {
- AssertedPredicates entry = (AssertedPredicates)provider.assertedPredicatesMap.get(r);
+ AssertedPredicates entry = (AssertedPredicates)provider.cache.assertedPredicatesMap.get(r);
if(entry != null && entry.isReady()) {
entry.performFromCache(graph, provider, procedure);
return;
@Override
public UnaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
- return provider.assertedPredicatesMap.get(id);
+ return provider.cache.assertedPredicatesMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.assertedPredicatesMap.put(id, this);
+ provider.cache.assertedPredicatesMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.assertedPredicatesMap.remove(id);
+ provider.cache.assertedPredicatesMap.remove(id);
}
void computeInheritedAssertions(ReadGraphImpl graph, int type, final QueryProcessor queryProvider, final IntProcedure proc, final boolean store) {
final public class AssertedStatements extends CollectionBinaryQuery<TripleIntProcedure> {
-// public ArrayList<TripleIntProcedure> procs;
-
public AssertedStatements(final int r1, final int r2) {
super(r1, r2);
}
final static AssertedStatements runner(ReadGraphImpl graph, final int r1, final int r2, final QueryProcessor provider, final AssertedStatements cached, final CacheEntry parent, final ListenerBase listener, final TripleIntProcedure procedure) {
- AssertedStatements entry = cached != null ? cached : (AssertedStatements)provider.assertedStatementsMap.get(id(r1,r2));
+ AssertedStatements entry = cached != null ? cached : (AssertedStatements)provider.cache.assertedStatementsMap.get(id(r1,r2));
if(entry == null) {
entry = new AssertedStatements(r1, r2);
assert(r1 != 0);
assert(r2 != 0);
- final AssertedStatements entry = (AssertedStatements)provider.assertedStatementsMap.get(id(r1,r2));
+ final AssertedStatements entry = (AssertedStatements)provider.cache.assertedStatementsMap.get(id(r1,r2));
if(parent == null && !(listener != null)) {
if(entry != null && entry.isReady()) {
@Override
public BinaryQuery<TripleIntProcedure> getEntry(QueryProcessor provider) {
- return provider.assertedStatementsMap.get(id);
+ return provider.cache.assertedStatementsMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.assertedStatementsMap.put(id, this);
+ provider.cache.assertedStatementsMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.assertedStatementsMap.remove(id);
+ provider.cache.assertedStatementsMap.remove(id);
}
void computeInheritedAssertions(ReadGraphImpl graph, int type, final int predicate, final RelationInfo ri, final QueryProcessor queryProvider, final TripleIntProcedure proc) {
}
@Override
- public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, final TripleIntProcedure procedure) {
+ public Object performFromCache(ReadGraphImpl graph, QueryProcessor provider, final TripleIntProcedure procedure) {
assert(isReady());
- if(handleException(graph, procedure)) return;
+ if(handleException(graph, procedure)) return getResult();
final IntArray value = (IntArray)getResult();
for(int i=0;i<value.size();i+=3) {
procedure.finished(graph);
+ return value;
+
}
@Override
@Override
public void removeEntry(QueryProcessor processor) {
- processor.asyncMultiReadMap.remove(request);
+ processor.cache.asyncMultiReadMap.remove(request);
}
@Override
@SuppressWarnings("unchecked")
@Override
- public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+ public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
final AsyncMultiProcedure<T> proc = (AsyncMultiProcedure<T>)procedure;
}
-
+ return getResult();
}
@Override
public void removeEntry(QueryProcessor qp) {
- qp.asyncReadMap.remove(request);
+ qp.cache.asyncReadMap.remove(request);
}
@Override
}
- @SuppressWarnings("unchecked")
- public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+ public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
AsyncProcedure<T> proc = (AsyncProcedure<T>)procedure;
}
+ return getResult();
+
}
@Override
@SuppressWarnings("unchecked")
@Override
- public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
- performFromCache(graph, (QueryProcessor)provider, (Procedure)procedure);
+ public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+ return performFromCache(graph, (QueryProcessor)provider, (Procedure)procedure);
}
abstract public void recompute(ReadGraphImpl graph, QueryProcessor provider);
abstract public void computeForEach(ReadGraphImpl graph, QueryProcessor provider, Procedure procedure, boolean store);
- abstract public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, Procedure procedure);
+ abstract public Object performFromCache(ReadGraphImpl graph, QueryProcessor provider, Procedure procedure);
abstract public void putEntry(QueryProcessor provider);
abstract public void removeEntry(QueryProcessor provider);
abstract public BinaryQuery<Procedure> getEntry(QueryProcessor provider);
throw new Error("Not possible!");
}
-// @Override
-// public void reset() {
-// throw new Error("Not possible!");
-// }
-
@Override
- public void performFromCache(ReadGraphImpl graph, QueryProcessor provider,
+ public Object performFromCache(ReadGraphImpl graph, QueryProcessor provider,
Procedure procedure) {
throw new Error("Not possible!");
}
-// @Override
-// public void performFromCache(int callerThread, Object provider,
-// Object procedure) {
-// throw new Error("Not possible!");
-// }
-
@Override
- public void performFromCache(ReadGraphImpl graph, Object provider,
+ public Object performFromCache(ReadGraphImpl graph, Object provider,
Object procedure) {
throw new Error("Not possible!");
}
abstract boolean moreThanOneParent(QueryProcessor processor);
abstract int parentCount(QueryProcessor processor);
- abstract void performFromCache(ReadGraphImpl graph, Object provider, Object procedure);
+ abstract Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure);
abstract boolean isImmutable(ReadGraphImpl graph) throws DatabaseException;
import java.util.ArrayList;
import java.util.Iterator;
+import org.simantics.db.AsyncReadGraph;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.impl.DebugPolicy;
import org.simantics.db.impl.graph.ReadGraphImpl;
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);
+
}
final static DirectObjects entry(final QueryProcessor provider, final int r1, final int r2) {
- return (DirectObjects)provider.directObjectsMap.get(id(r1,r2));
+ return (DirectObjects)provider.cache.directObjectsMap.get(id(r1,r2));
}
final static Collection<DirectObjects> entries(final QueryProcessor processor, final int r1) {
- DoubleKeyQueryHashMap<IntProcedure> hash = processor.directObjectsMap;
+ DoubleKeyQueryHashMap<IntProcedure> hash = processor.cache.directObjectsMap;
return hash.values(r1);
}
QueryProcessor processor = graph.processor;
- DirectObjects entry = (DirectObjects)processor.directObjectsMap.get(id(r1,r2));
+ DirectObjects entry = (DirectObjects)processor.cache.directObjectsMap.get(id(r1,r2));
if(entry == null) {
entry = new DirectObjects(r1, r2);
@Override
public BinaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
- return provider.directObjectsMap.get(id);
+ return provider.cache.directObjectsMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.directObjectsMap.put(id, this);
+ provider.cache.directObjectsMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.directObjectsMap.remove(id);
+ provider.cache.directObjectsMap.remove(id);
}
@Override
}
@Override
- public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, IntProcedure procedure) {
+ public Object performFromCache(ReadGraphImpl graph, QueryProcessor provider, IntProcedure procedure) {
assert(isReady());
computeForEach(graph, provider, procedure, false);
+ return null;
}
final static DirectPredicates entry(final QueryProcessor provider, final int r) {
- return (DirectPredicates)provider.directPredicatesMap.get(r);
+ return (DirectPredicates)provider.cache.directPredicatesMap.get(r);
}
final static void runner(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {
- DirectPredicates entry = (DirectPredicates)provider.directPredicatesMap.get(r);
+ DirectPredicates entry = (DirectPredicates)provider.cache.directPredicatesMap.get(r);
if(entry == null) {
entry = new DirectPredicates(r);
final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {
if(parent == null && listener == null) {
- DirectPredicates entry = (DirectPredicates)provider.directPredicatesMap.get(r);
+ DirectPredicates entry = (DirectPredicates)provider.cache.directPredicatesMap.get(r);
if(entry != null && entry.isReady()) {
entry.performFromCache(graph, provider, procedure);
return;
@Override
public UnaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
- return provider.directPredicatesMap.get(id);
+ return provider.cache.directPredicatesMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.directPredicatesMap.put(id, this);
+ provider.cache.directPredicatesMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.directPredicatesMap.remove(id);
+ provider.cache.directPredicatesMap.remove(id);
}
@Override
final public class ExternalReadEntry<T> extends CacheEntryBase {
final LinkedList<T> items = new LinkedList<T>();
-
-// public ArrayList<Procedure<T>> procs;
protected ExternalRead<T> request;
@Override
public void removeEntry(QueryProcessor processor) {
- processor.externalReadMap.remove(request);
+ processor.cache.externalReadMap.remove(request);
}
@Override
}
- public void performFromCache(Object procedure) {
+ public Object performFromCache(Object procedure) {
Procedure<T> proc = (Procedure<T>)procedure;
proc.execute((T)getResult());
}
+
+ return getResult();
}
}
@Override
- public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
- performFromCache(procedure);
+ public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+ return performFromCache(procedure);
}
@Override
@Override
public void removeEntry(QueryProcessor processor) {
- processor.multiReadMap.remove(request);
+ processor.cache.multiReadMap.remove(request);
}
@Override
}
@Override
- public void performFromCache(ReadGraphImpl graph, Object provider,
+ public Object performFromCache(ReadGraphImpl graph, Object provider,
Object procedure) {
final AsyncMultiProcedure<T> proc = (AsyncMultiProcedure<T>)procedure;
}
-
+ return null;
}
import org.simantics.db.procedure.ListenerBase;
final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectIntHashMap<String>>> {
-
-// public ArrayList<InternalProcedure<TObjectIntHashMap<String>>> procs = null;
private NamespaceIndex(final String id) {
super(id);
final static void runner(ReadGraphImpl graph, final String id, final QueryProcessor provider, NamespaceIndex cached, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<TObjectIntHashMap<String>> procedure) {
- NamespaceIndex entry = cached != null ? cached : (NamespaceIndex)provider.namespaceIndexMap22.get(id);
+ NamespaceIndex entry = cached != null ? cached : (NamespaceIndex)provider.cache.namespaceIndexMap22.get(id);
if(entry == null) {
entry = new NamespaceIndex(id);
final public static void queryEach(ReadGraphImpl graph, final String id, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<TObjectIntHashMap<String>> procedure) {
- final NamespaceIndex entry = (NamespaceIndex)provider.namespaceIndexMap22.get(id);
+ final NamespaceIndex entry = (NamespaceIndex)provider.cache.namespaceIndexMap22.get(id);
if(parent == null && listener == null && entry != null && entry.isReady()) {
entry.performFromCache(graph, provider, procedure);
@Override
public NamespaceIndex getEntry(QueryProcessor provider) {
- return provider.namespaceIndexMap22.get(id);
+ return provider.cache.namespaceIndexMap22.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.namespaceIndexMap22.put(id, this);
+ provider.cache.namespaceIndexMap22.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.namespaceIndexMap22.remove(id);
+ provider.cache.namespaceIndexMap22.remove(id);
}
final private void index(ReadGraphImpl graph, final QueryProcessor provider, int root, final InternalProcedure<TObjectIntHashMap<String>> procedure) {
}
final static Objects entry(final QueryProcessor provider, final int r1, final int r2) {
- return (Objects)provider.objectsMap.get(r1,r2);
+ return (Objects)provider.cache.objectsMap.get(r1,r2);
}
final static Collection<Objects> entries(final QueryProcessor processor, final int r1) {
- return processor.objectsMap.values(r1);
+ return processor.cache.objectsMap.values(r1);
}
public final static void runner(ReadGraphImpl graph, final int r1, final int r2, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) {
QueryProcessor processor = graph.processor;
- Objects entry = (Objects)processor.objectsMap.get(r1,r2);
+ Objects entry = (Objects)processor.cache.objectsMap.get(r1,r2);
if(entry == null) {
entry = new Objects(r1, r2);
QueryProcessor processor = graph.processor;
- Objects entry = (Objects)processor.objectsMap.get(r1,r2);
+ Objects entry = (Objects)processor.cache.objectsMap.get(r1,r2);
if(entry == null) {
entry = new Objects(r1, r2);
@Override
public BinaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
- return provider.objectsMap.get(id);
+ return provider.cache.objectsMap.get(id);
}
@Override
System.err.println("put " + this);
}
}
- provider.objectsMap.put(id, this);
+ provider.cache.objectsMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.objectsMap.remove(id);
+ provider.cache.objectsMap.remove(id);
}
final static private IntArray getAssertionMap(ReadGraphImpl graph, final int r1, final int r2, final Objects entry) {
}
@Override
- public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, final IntProcedure procedure) {
+ public Object performFromCache(ReadGraphImpl graph, QueryProcessor provider, final IntProcedure procedure) {
assert(isReady());
- if(handleException(graph, procedure)) return;
+ if(handleException(graph, procedure)) return getResult();
final IntArray value = (IntArray)getResult();
if(value.data == null) {
}
procedure.finished(graph);
+
+ return value;
}
final public class OrderedSet extends CollectionUnaryQuery<IntProcedure> {
-// public ArrayList<IntProcedure> procs = null;
-
public OrderedSet(final int r) {
super(r);
}
final static OrderedSet entry(final QueryProcessor provider, final int r) {
- return (OrderedSet)provider.orderedSetMap.get(r);
+ return (OrderedSet)provider.cache.orderedSetMap.get(r);
}
final static void runner(ReadGraphImpl graph, final int r, final QueryProcessor provider, OrderedSet cached, final CacheEntry parent, ListenerBase listener, final IntProcedure procedure) {
- OrderedSet entry = cached != null ? cached : (OrderedSet)provider.orderedSetMap.get(r);
+ OrderedSet entry = cached != null ? cached : (OrderedSet)provider.cache.orderedSetMap.get(r);
if(entry == null) {
entry = new OrderedSet(r);
assert(r != 0);
- final OrderedSet entry = (OrderedSet)provider.orderedSetMap.get(r);
+ final OrderedSet entry = (OrderedSet)provider.cache.orderedSetMap.get(r);
if(parent == null && !(listener != null)) {
if(entry != null && entry.isReady()) {
@Override
public UnaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
- return provider.orderedSetMap.get(id);
+ return provider.cache.orderedSetMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.orderedSetMap.put(id, this);
+ provider.cache.orderedSetMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.orderedSetMap.remove(id);
+ provider.cache.orderedSetMap.remove(id);
}
private int current = 0;
import org.simantics.db.request.RequestFlags;
final public class Predicates extends UnaryQuery<IntProcedure> {
-
-// public ArrayList<IntProcedure> procs;
public Predicates(final int r) {
super(r);
final static Predicates entry(final QueryProcessor provider, final int r) {
- return (Predicates)provider.predicatesMap.get(r);
+ return (Predicates)provider.cache.predicatesMap.get(r);
}
final static void runner(ReadGraphImpl graph, final int r, final QueryProcessor provider, Predicates cached, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {
- Predicates entry = cached != null ? cached : (Predicates)provider.predicatesMap.get(r);
+ Predicates entry = cached != null ? cached : (Predicates)provider.cache.predicatesMap.get(r);
if(entry == null) {
entry = new Predicates(r);
final static IntSet runner2(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent) throws Throwable {
- Predicates entry = (Predicates)provider.predicatesMap.get(r);
+ Predicates entry = (Predicates)provider.cache.predicatesMap.get(r);
if(entry == null) {
entry = new Predicates(r);
assert(r != 0);
- final Predicates entry = (Predicates)provider.predicatesMap.get(r);
+ final Predicates entry = (Predicates)provider.cache.predicatesMap.get(r);
if(parent == null && listener == null) {
if(entry != null && entry.isReady()) {
final public static IntSet queryEach2(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent) throws Throwable {
if(parent == null) {
- final Predicates entry = (Predicates)provider.predicatesMap.get(r);
+ final Predicates entry = (Predicates)provider.cache.predicatesMap.get(r);
if(entry != null && entry.isReady()) {
return (IntSet)entry.get(graph, provider, null);
}
@Override
public UnaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
- return provider.predicatesMap.get(id);
+ return provider.cache.predicatesMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.predicatesMap.put(id, this);
+ provider.cache.predicatesMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.predicatesMap.remove(id);
+ provider.cache.predicatesMap.remove(id);
}
final private void forAssertions(ReadGraphImpl graph, final QueryProcessor queryProvider, final IntProcedure procedure, final boolean store) {
*******************************************************************************/
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.impl.procedure.InternalProcedure;
import org.simantics.db.procedure.ListenerBase;
-final public class PrincipalTypes extends CollectionUnaryQuery<IntProcedure> {
+import gnu.trove.procedure.TIntProcedure;
+import gnu.trove.set.hash.TIntHashSet;
-// public ArrayList<IntProcedure> procs = null;
+final public class PrincipalTypes extends CollectionUnaryQuery<IntProcedure> {
private PrincipalTypes(final int resource) {
super(resource);
}
final static PrincipalTypes entry(final QueryProcessor provider, final int r) {
- return (PrincipalTypes)provider.principalTypesMap.get(r);
+ return (PrincipalTypes)provider.cache.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);
+ PrincipalTypes entry = (PrincipalTypes)processor.cache.principalTypesMap.get(r);
if(entry == null) {
entry = new PrincipalTypes(r);
@Override
public UnaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
- return provider.principalTypesMap.get(id);
+ return provider.cache.principalTypesMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.principalTypesMap.put(id, this);
+ provider.cache.principalTypesMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.principalTypesMap.remove(id);
+ provider.cache.principalTypesMap.remove(id);
}
static class Koss {
--- /dev/null
+package org.simantics.db.impl.query;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.RelationInfo;
+import org.simantics.db.common.utils.Logger;
+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.procedure.AsyncMultiProcedure;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.procedure.Listener;
+import org.simantics.db.procedure.ListenerBase;
+import org.simantics.db.procedure.Procedure;
+import org.simantics.db.request.AsyncMultiRead;
+import org.simantics.db.request.AsyncRead;
+import org.simantics.db.request.ExternalRead;
+import org.simantics.db.request.MultiRead;
+import org.simantics.db.request.Read;
+
+import gnu.trove.map.hash.THashMap;
+
+public class QueryCache {
+
+ final public UnaryQueryHashMap<IntProcedure> directPredicatesMap;
+ final public UnaryQueryHashMap<IntProcedure> principalTypesMap;
+ final public THashMap<String, URIToResource> uriToResourceMap;
+ final public THashMap<String, NamespaceIndex> namespaceIndexMap22;
+ final public UnaryQueryHashMap<IntProcedure> projectsMap;
+ final public UnaryQueryHashMap<InternalProcedure<RelationInfo>> relationInfoMap;
+ final public UnaryQueryHashMap<InternalProcedure<IntSet>> superTypesMap;
+ final public UnaryQueryHashMap<InternalProcedure<IntSet>> typeHierarchyMap;
+ final public UnaryQueryHashMap<InternalProcedure<IntSet>> superRelationsMap;
+ final public UnaryQueryHashMap<InternalProcedure<IntSet>> typesMap;
+ final public UnaryQueryHashMap<InternalProcedure<byte[]>> valueMap;
+ final public DoubleKeyQueryHashMap<IntProcedure> directObjectsMap;
+ final public DoubleKeyQueryHashMap<IntProcedure> objectsMap;
+ final public UnaryQueryHashMap<IntProcedure> orderedSetMap;
+ final public UnaryQueryHashMap<IntProcedure> predicatesMap;
+ final public DoubleKeyQueryHashMap<TripleIntProcedure> statementsMap;
+ final public UnaryQueryHashMap<IntProcedure> assertedPredicatesMap;
+ final public BinaryQueryHashMap<TripleIntProcedure> assertedStatementsMap;
+ final public StableHashMap<ExternalRead, ExternalReadEntry> externalReadMap;
+ final public StableHashMap<AsyncRead, AsyncReadEntry> asyncReadMap;
+ final public StableHashMap<Read, ReadEntry> readMap;
+ final public StableHashMap<AsyncMultiRead, AsyncMultiReadEntry> asyncMultiReadMap;
+ final public StableHashMap<MultiRead, MultiReadEntry> multiReadMap;
+
+ final THashMap<CacheEntry, ArrayList<ListenerEntry>> listeners;
+
+ public QueryCache() {
+ directPredicatesMap = new UnaryQueryHashMap();
+ valueMap = new UnaryQueryHashMap();
+ principalTypesMap = new UnaryQueryHashMap();
+ uriToResourceMap = new THashMap<String, URIToResource>();
+ namespaceIndexMap22 = new THashMap<String, NamespaceIndex>();
+ projectsMap = new UnaryQueryHashMap();
+ relationInfoMap = new UnaryQueryHashMap();
+ typeHierarchyMap = new UnaryQueryHashMap();
+ superTypesMap = new UnaryQueryHashMap();
+ superRelationsMap = new UnaryQueryHashMap();
+ typesMap = new UnaryQueryHashMap();
+ objectsMap = new DoubleKeyQueryHashMap();
+ orderedSetMap = new UnaryQueryHashMap();
+ predicatesMap = new UnaryQueryHashMap();
+ statementsMap = new DoubleKeyQueryHashMap();
+ directObjectsMap = new DoubleKeyQueryHashMap();
+ assertedPredicatesMap = new UnaryQueryHashMap();
+ assertedStatementsMap = new BinaryQueryHashMap();
+ asyncReadMap = new StableHashMap<AsyncRead, AsyncReadEntry>();
+ readMap = new StableHashMap<Read, ReadEntry>();
+ asyncMultiReadMap = new StableHashMap<AsyncMultiRead, AsyncMultiReadEntry>();
+ multiReadMap = new StableHashMap<MultiRead, MultiReadEntry>();
+ externalReadMap = new StableHashMap<ExternalRead, ExternalReadEntry>();
+ listeners = new THashMap<CacheEntry, ArrayList<ListenerEntry>>(10, 0.75f);
+ }
+
+ public int requestHash(Object object) {
+ try {
+ return object.hashCode();
+ } catch (Throwable t) {
+ Logger.defaultLogError(t);
+ return 0;
+ }
+ }
+
+ private CacheEntryBase getCached(Object query, int hash) {
+ if (query instanceof AsyncRead)
+ return asyncReadMap.get(query, hash);
+ else if (query instanceof Read)
+ return readMap.get(query, hash);
+ else if (query instanceof ExternalRead)
+ return externalReadMap.get(query, hash);
+ else if (query instanceof AsyncMultiRead)
+ return asyncMultiReadMap.get(query, hash);
+ throw new IllegalStateException();
+ }
+
+ private CacheEntryBase createEntry(QuerySupport support, Object query, int hash) {
+
+ CacheEntryBase result;
+ if (query instanceof AsyncRead) {
+ AsyncReadEntry entry = new AsyncReadEntry((AsyncRead)query);
+ asyncReadMap.put((AsyncRead)query, entry, hash);
+ result = entry;
+ } else if (query instanceof Read) {
+ ReadEntry entry = new ReadEntry((Read)query);
+ readMap.put((Read)query, entry, hash);
+ result = entry;
+ } else if (query instanceof ExternalRead) {
+ ExternalReadEntry entry = new ExternalReadEntry((ExternalRead)query);
+ externalReadMap.put((ExternalRead)query, entry, hash);
+ result = entry;
+ } else if (query instanceof AsyncMultiRead) {
+ AsyncMultiReadEntry entry = new AsyncMultiReadEntry((AsyncMultiRead)query);
+ asyncMultiReadMap.put((AsyncMultiRead)query, entry, hash);
+ result = entry;
+ } else {
+ throw new IllegalStateException();
+ }
+
+ result.setPending();
+ result.clearResult(support);
+
+ return result;
+
+ }
+
+ public final <T> Object runQuery(final ReadGraphImpl graph, final Object query, final CacheEntry parent, final ListenerBase listener, final Object procedure) throws DatabaseException {
+
+ int hash = requestHash(query);
+
+ CacheEntryBase entry = getCached(query, hash);
+
+ if(parent == null && listener == null) {
+ if(entry != null && (entry.isReady() || entry.isExcepted())) {
+ return entry.performFromCache(graph, this, procedure);
+ } else {
+ return performQuery(graph, query, entry, null, procedure);
+ }
+ }
+
+ if(entry == null) {
+ entry = createEntry(graph.processor.querySupport, query, hash);
+ return performForEach(graph, query, entry, parent, listener, procedure, false);
+
+ } else {
+
+ if(entry.isPending()) {
+ synchronized(entry) {
+ if(entry.isPending()) {
+ throw new IllegalStateException();
+ // final AsyncBarrierImpl parentBarrier = graph.state.barrier;
+ // if(entry.procs == null) entry.procs = new ArrayList<AsyncProcedure<T>>();
+ // entry.procs.add(new AsyncProcedure<T>() {
+ //
+ // @Override
+ // public void execute(AsyncReadGraph graph, T result) {
+ // procedure.execute(graph, result);
+ // parentBarrier.dec(query);
+ // }
+ //
+ // @Override
+ // public void exception(AsyncReadGraph graph, Throwable throwable) {
+ // procedure.exception(graph, throwable);
+ // parentBarrier.dec(query);
+ // }
+ //
+ // });
+// if(graph.parent != null || listener != null) {
+// registerDependencies(graph, entry, parent, listener, procedure, false);
+// }
+//
+// query.perform(graph, procedure);
+//
+// return;
+
+ }
+ }
+ }
+
+ if(entry.isReady()) {
+ Object result = entry.performFromCache(graph, this, procedure);
+ registerDependencies(graph, entry, parent, listener, procedure, false);
+ return result;
+ } else {
+ return performForEach(graph, query, entry, parent, listener, procedure, false);
+ }
+
+ }
+
+ }
+
+ public <T> Object performQuery(ReadGraphImpl parentGraph, final Object query_, final CacheEntryBase entry_, ListenerEntry listenerEntry, Object procedure_) throws DatabaseException {
+
+ ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
+
+ if(query_ instanceof AsyncRead) {
+
+ AsyncRead<T> query = (AsyncRead<T>)query_;
+ AsyncReadEntry<T> entry = (AsyncReadEntry<T>)entry_;
+ AsyncProcedure<T> procedure = (AsyncProcedure<T>)procedure_;
+
+ try {
+
+ query.perform(queryGraph, new AsyncProcedure<T>() {
+
+ @Override
+ public void execute(AsyncReadGraph returnGraph, T result) {
+ ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+ entry.addOrSet(parentGraph, result);
+ if(listenerEntry != null) {
+ primeListenerEntry(listenerEntry, result);
+ }
+ try {
+ procedure.execute(parentGraph, result);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ // parentBarrier.dec(query);
+ }
+
+ @Override
+ public void exception(AsyncReadGraph returnGraph, Throwable t) {
+ ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+ // AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
+ entry.except(parentGraph, t);
+ try {
+ procedure.exception(parentGraph, t);
+ } catch (Throwable t2) {
+ t2.printStackTrace();
+ }
+ // parentBarrier.dec(query);
+ }
+
+ @Override
+ public String toString() {
+ return procedure.toString();
+ }
+
+ });
+
+ } catch (Throwable t) {
+
+ entry.except(t);
+ try {
+ procedure.exception(parentGraph, t);
+ } catch (Throwable t2) {
+ t2.printStackTrace();
+ }
+ // parentBarrier.dec(query);
+
+ }
+
+ return null;
+
+ } else if (query_ instanceof Read) {
+
+ Read query = (Read)query_;
+ ReadEntry entry = (ReadEntry)entry_;
+
+ entry.setPending();
+
+ try {
+
+ T result = (T)query.perform(queryGraph);
+ entry.addOrSet(queryGraph, result);
+
+ if(listenerEntry != null) primeListenerEntry(listenerEntry, result);
+
+ return (T)entry.get(parentGraph, parentGraph.processor, procedure_);
+
+ } catch (Throwable t) {
+
+ entry.except(t);
+ return (T)entry.get(parentGraph, parentGraph.processor, procedure_);
+
+ }
+
+ } else if (query_ instanceof ExternalRead) {
+
+ ExternalRead query = (ExternalRead)query_;
+ ExternalReadEntry entry = (ExternalReadEntry)entry_;
+ Procedure<T> procedure = (Procedure<T>)procedure_;
+
+ try {
+
+ query.register(parentGraph, new Listener<T>() {
+
+ AtomicBoolean used = new AtomicBoolean(false);
+
+ @Override
+ public void execute(T result) {
+
+ // Just for safety
+ if(entry.isDiscarded()) return;
+ if(entry.isExcepted()) entry.setPending();
+
+ if(used.compareAndSet(false, true)) {
+ entry.addOrSet(parentGraph.processor, result);
+ procedure.execute(result);
+ } else {
+ entry.queue(result);
+ parentGraph.processor.updatePrimitive(query);
+ }
+
+ }
+
+ @Override
+ public void exception(Throwable t) {
+
+ entry.except(t);
+
+ if(used.compareAndSet(false, true)) {
+ procedure.exception(t);
+ } else {
+// entry.queue(result);
+ parentGraph.processor.updatePrimitive(query);
+ }
+
+ }
+
+ @Override
+ public String toString() {
+ return procedure.toString();
+ }
+
+ @Override
+ public boolean isDisposed() {
+ return entry.isDiscarded() || !parentGraph.processor.isBound(entry);
+ }
+
+ });
+
+ return entry.getResult();
+
+ } catch (Throwable t) {
+
+ entry.except(t);
+ procedure.exception(t);
+ return entry.getResult();
+
+ }
+
+ } else if (query_ instanceof AsyncMultiRead) {
+
+ AsyncMultiRead query = (AsyncMultiRead)query_;
+ AsyncMultiReadEntry entry = (AsyncMultiReadEntry)entry_;
+ AsyncMultiProcedure<T> procedure = (AsyncMultiProcedure<T>)procedure_;
+
+ try {
+
+ query.perform(queryGraph, new AsyncMultiProcedure<T>() {
+
+ @Override
+ public void execute(AsyncReadGraph graph, T result) {
+ ReadGraphImpl impl = (ReadGraphImpl)graph;
+ entry.addOrSet(result);
+ try {
+ procedure.execute(parentGraph, result);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ @Override
+ public void finished(AsyncReadGraph graph) {
+ ReadGraphImpl impl = (ReadGraphImpl)graph;
+ entry.finish(parentGraph);
+ try {
+ procedure.finished(parentGraph);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+ @Override
+ public void exception(AsyncReadGraph graph, Throwable t) {
+ ReadGraphImpl impl = (ReadGraphImpl)graph;
+ entry.except(parentGraph, t);
+ try {
+ procedure.exception(parentGraph, t);
+ } catch (Throwable t2) {
+ t2.printStackTrace();
+ }
+ }
+
+ });
+
+ return entry.getResult();
+
+ } catch (Throwable t) {
+
+ entry.except(t);
+ try {
+ procedure.exception(parentGraph, t);
+ } catch (Throwable t2) {
+ t2.printStackTrace();
+ }
+
+ return entry.getResult();
+
+ }
+
+ } else {
+
+ throw new IllegalStateException();
+
+ }
+
+ }
+
+ public <T> Object performFromCache(ReadGraphImpl parentGraph, Object query, CacheEntryBase entry_, ListenerEntry listenerEntry, Object procedure_) throws DatabaseException {
+
+ Object result = entry_.performFromCache(parentGraph, this, procedure_);
+ if(listenerEntry != null) {
+ primeListenerEntry(listenerEntry, result);
+ }
+ return result;
+
+// if(query instanceof AsyncRead) {
+//
+// AsyncProcedure<T> procedure = (AsyncProcedure<T>)procedure_;
+//
+//
+// return null;
+//
+// } else if(query instanceof Read) {
+//
+// ReadEntry entry = (ReadEntry)entry_;
+//
+// T result = (T)entry.get(parentGraph, parentGraph.processor, procedure_);
+//
+// if(listenerEntry != null) primeListenerEntry(listenerEntry, result);
+//
+// return result;
+//
+// } else if(query instanceof ExternalRead) {
+//
+// ExternalReadEntry entry = (ExternalReadEntry)entry_;
+// Procedure<T> procedure = (Procedure<T>)procedure_;
+//
+// return entry.performFromCache(procedure);
+//
+// } else if (query instanceof AsyncMultiRead) {
+//
+// AsyncMultiReadEntry entry = (AsyncMultiReadEntry)entry_;
+// AsyncMultiProcedure<T> procedure = (AsyncMultiProcedure<T>)procedure_;
+//
+// return entry.performFromCache(parentGraph, this, procedure);
+//
+// } else {
+//
+// throw new IllegalStateException();
+//
+// }
+
+ }
+
+ public <T> Object performForEach(ReadGraphImpl parentGraph, final Object query, final CacheEntryBase entry, final CacheEntry parent, final ListenerBase base, final Object procedure,
+ boolean inferredDependency) throws DatabaseException {
+
+// if (DebugPolicy.PERFORM)
+// System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
+
+// assert (!dirty);
+// assert (!collecting);
+
+ assert(!entry.isDiscarded());
+
+ final ListenerEntry listenerEntry = registerDependencies(parentGraph, entry, parent, base, procedure, inferredDependency);
+
+ // FRESH, REFUTED, EXCEPTED go here
+ if (!entry.isReady()) {
+
+ entry.setPending();
+
+// size++;
+
+ return performQuery(parentGraph, query, entry, listenerEntry, procedure);
+
+// misses++;
+
+ } else {
+
+ return performFromCache(parentGraph, query, entry, listenerEntry, procedure);
+
+// parentBarrier.dec(query);
+
+// hits++;
+
+ }
+
+ }
+
+ synchronized public ListenerEntry registerDependencies(ReadGraphImpl graph, CacheEntry child, CacheEntry parent, ListenerBase listener, Object procedure, boolean inferred) {
+
+ if (parent != null && !inferred) {
+ try {
+ if(!child.isImmutable(graph))
+ child.addParent(parent);
+ } catch (DatabaseException e) {
+ Logger.defaultLogError(e);
+ }
+ if(DebugPolicy.DEPENDENCIES) System.out.println(child + " -> " + parent);
+ }
+
+ if (listener != null) {
+ return registerListener(child, listener, procedure);
+ } else {
+ return null;
+ }
+
+ }
+
+ public ListenerEntry registerListener(final CacheEntry entry, final ListenerBase base, final Object procedure) {
+
+ assert (entry != null);
+
+ if (base.isDisposed())
+ return null;
+
+ return addListener(entry, base, procedure);
+
+ }
+
+ private void primeListenerEntry(final ListenerEntry entry, final Object result) {
+ entry.setLastKnown(result);
+ }
+
+ private ListenerEntry addListener(CacheEntry entry, ListenerBase base, Object procedure) {
+
+ assert (entry != null);
+ assert (procedure != null);
+
+ ArrayList<ListenerEntry> list = listeners.get(entry);
+ if (list == null) {
+ list = new ArrayList<ListenerEntry>(1);
+ listeners.put(entry, list);
+ }
+
+ ListenerEntry result = new ListenerEntry(entry, base, procedure);
+ int currentIndex = list.indexOf(result);
+ // There was already a listener
+ if(currentIndex > -1) {
+ ListenerEntry current = list.get(currentIndex);
+ if(!current.base.isDisposed()) return null;
+ list.set(currentIndex, result);
+ } else {
+ list.add(result);
+ }
+
+ if(DebugPolicy.LISTENER) {
+ new Exception().printStackTrace();
+ System.out.println("addListener -> " + list.size() + " " + entry + " " + base + " " + procedure);
+ }
+
+ return result;
+
+ }
+
+
+ public Collection<CacheEntry> getRootList() {
+
+ ArrayList<CacheEntry> result = new ArrayList<CacheEntry>();
+
+ for (Object e : valueMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : directPredicatesMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : objectsMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : directObjectsMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : principalTypesMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : superRelationsMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : superTypesMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : typesMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : objectsMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : assertedStatementsMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : readMap.values()) {
+ if(e instanceof CacheEntry) {
+ result.add((CacheEntry) e);
+ } else {
+ System.err.println("e=" + e);
+ }
+ }
+ for (Object e : asyncReadMap.values()) {
+ if(e instanceof CacheEntry) {
+ result.add((CacheEntry) e);
+ } else {
+ System.err.println("e=" + e);
+ }
+ }
+ for (Object e : externalReadMap.values()) {
+ result.add((CacheEntry) e);
+ }
+ for (Object e : orderedSetMap.values()) {
+ result.add((CacheEntry) e);
+ }
+
+ return result;
+
+ }
+
+ public int calculateCurrentSize() {
+
+ int realSize = 0;
+
+ realSize += directPredicatesMap.size();
+ realSize += principalTypesMap.size();
+ realSize += uriToResourceMap.size();
+ realSize += namespaceIndexMap22.size();
+ realSize += projectsMap.size();
+
+ realSize += relationInfoMap.size();
+ realSize += superTypesMap.size();
+ realSize += typeHierarchyMap.size();
+ realSize += superRelationsMap.size();
+ realSize += typesMap.size();
+
+ realSize += valueMap.size();
+ realSize += directObjectsMap.size();
+ realSize += objectsMap.size();
+ realSize += orderedSetMap.size();
+ realSize += predicatesMap.size();
+
+ realSize += statementsMap.size();
+ realSize += assertedPredicatesMap.size();
+ realSize += assertedStatementsMap.size();
+ realSize += externalReadMap.size();
+ realSize += asyncReadMap.size();
+
+ realSize += readMap.size();
+ realSize += asyncMultiReadMap.size();
+ realSize += multiReadMap.size();
+
+ return realSize;
+
+ }
+
+ CacheCollectionResult allCaches(CacheCollectionResult result) {
+
+ int level = Integer.MAX_VALUE;
+ directPredicatesMap.values(level, result);
+ principalTypesMap.values(level, result);
+ for(CacheEntryBase e : uriToResourceMap.values())
+ if(e.getLevel() <= level)
+ result.add(e);
+ for(CacheEntryBase e : namespaceIndexMap22.values())
+ if(e.getLevel() <= level)
+ result.add(e);
+ projectsMap.values(level, result);
+
+ relationInfoMap.values(level, result);
+ superTypesMap.values(level, result);
+ typeHierarchyMap.values(level, result);
+ superRelationsMap.values(level, result);
+ typesMap.values(level, result);
+
+ valueMap.values(level, result);
+ directObjectsMap.values(level, result);
+ objectsMap.values(level, result);
+ orderedSetMap.values(level, result);
+ predicatesMap.values(level, result);
+
+ statementsMap.values(level, result);
+ assertedPredicatesMap.values(level, result);
+ assertedStatementsMap.values(level, result);
+ externalReadMap.values(level, result);
+ asyncReadMap.values(level, result);
+
+ readMap.values(level, result);
+ asyncMultiReadMap.values(level, result);
+ multiReadMap.values(level, result);
+
+ return result;
+
+ }
+
+ public void scanPending() {
+
+ ArrayList<CacheEntry> entries = new ArrayList<CacheEntry>();
+
+ entries.addAll(directPredicatesMap.values());
+ entries.addAll(principalTypesMap.values());
+ entries.addAll(uriToResourceMap.values());
+ entries.addAll(namespaceIndexMap22.values());
+ entries.addAll(projectsMap.values());
+ entries.addAll(relationInfoMap.values());
+ entries.addAll(superTypesMap.values());
+ entries.addAll(superRelationsMap.values());
+ entries.addAll(typesMap.values());
+ entries.addAll(valueMap.values());
+ entries.addAll(directObjectsMap.values());
+ entries.addAll(objectsMap.values());
+ entries.addAll(orderedSetMap.values());
+ entries.addAll(predicatesMap.values());
+ entries.addAll(orderedSetMap.values());
+ entries.addAll(statementsMap.values());
+ // entries.addAll(assertedObjectsMap.values());
+ entries.addAll(assertedPredicatesMap.values());
+ entries.addAll(assertedStatementsMap.values());
+ entries.addAll(externalReadMap.values());
+ entries.addAll(asyncReadMap.values());
+ entries.addAll(externalReadMap.values());
+ entries.addAll(readMap.values());
+ entries.addAll(asyncMultiReadMap.values());
+ entries.addAll(multiReadMap.values());
+ entries.addAll(readMap.values());
+ System.out.println(entries.size() + " entries.");
+ for(Object e : entries) {
+ if(e instanceof CacheEntry) {
+ CacheEntry en = (CacheEntry)e;
+ if(en.isPending()) System.out.println("pending " + e);
+ if(en.isExcepted()) System.out.println("excepted " + e);
+ if(en.isDiscarded()) System.out.println("discarded " + e);
+ if(en.isRefuted()) System.out.println("refuted " + e);
+ if(en.isFresh()) System.out.println("fresh " + e);
+ } else {
+ //System.out.println("Unknown object " + e);
+ }
+ }
+ }
+
+}
}
@Override
- public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
- // TODO Auto-generated method stub
-
+ public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+ return null;
}
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
final public class QueryProcessor extends AbstractDisposable implements ReadGraphSupport {
- final public UnaryQueryHashMap<IntProcedure> directPredicatesMap;
- final public UnaryQueryHashMap<IntProcedure> principalTypesMap;
- final public THashMap<String, URIToResource> uriToResourceMap;
- final public THashMap<String, NamespaceIndex> namespaceIndexMap22;
- final public UnaryQueryHashMap<IntProcedure> projectsMap;
- final public UnaryQueryHashMap<InternalProcedure<RelationInfo>> relationInfoMap;
- final public UnaryQueryHashMap<InternalProcedure<IntSet>> superTypesMap;
- final public UnaryQueryHashMap<InternalProcedure<IntSet>> typeHierarchyMap;
- final public UnaryQueryHashMap<InternalProcedure<IntSet>> superRelationsMap;
- final public UnaryQueryHashMap<InternalProcedure<IntSet>> typesMap;
- final public UnaryQueryHashMap<InternalProcedure<byte[]>> valueMap;
- final public DoubleKeyQueryHashMap<IntProcedure> directObjectsMap;
- final public DoubleKeyQueryHashMap<IntProcedure> objectsMap;
- final public UnaryQueryHashMap<IntProcedure> orderedSetMap;
- final public UnaryQueryHashMap<IntProcedure> predicatesMap;
- final public DoubleKeyQueryHashMap<TripleIntProcedure> statementsMap;
- final public UnaryQueryHashMap<IntProcedure> assertedPredicatesMap;
- final public BinaryQueryHashMap<TripleIntProcedure> assertedStatementsMap;
- final public StableHashMap<ExternalRead, ExternalReadEntry> externalReadMap;
- final public StableHashMap<AsyncRead, AsyncReadEntry> asyncReadMap;
- final public StableHashMap<Read, ReadEntry> readMap;
- final public StableHashMap<AsyncMultiRead, AsyncMultiReadEntry> asyncMultiReadMap;
- final public StableHashMap<MultiRead, MultiReadEntry> multiReadMap;
-
- final private THashMap<CacheEntry, ArrayList<ListenerEntry>> listeners;
+ final public QueryCache cache = new QueryCache();
public static int indent = 0;
}
- directPredicatesMap = new UnaryQueryHashMap();
- valueMap = new UnaryQueryHashMap();
- principalTypesMap = new UnaryQueryHashMap();
- uriToResourceMap = new THashMap<String, URIToResource>();
- namespaceIndexMap22 = new THashMap<String, NamespaceIndex>();
- projectsMap = new UnaryQueryHashMap();
- relationInfoMap = new UnaryQueryHashMap();
- typeHierarchyMap = new UnaryQueryHashMap();
- superTypesMap = new UnaryQueryHashMap();
- superRelationsMap = new UnaryQueryHashMap();
- typesMap = new UnaryQueryHashMap();
- objectsMap = new DoubleKeyQueryHashMap();
- orderedSetMap = new UnaryQueryHashMap();
- predicatesMap = new UnaryQueryHashMap();
- statementsMap = new DoubleKeyQueryHashMap();
- directObjectsMap = new DoubleKeyQueryHashMap();
- assertedPredicatesMap = new UnaryQueryHashMap();
- assertedStatementsMap = new BinaryQueryHashMap();
- asyncReadMap = new StableHashMap<AsyncRead, AsyncReadEntry>();
- readMap = new StableHashMap<Read, ReadEntry>();
- asyncMultiReadMap = new StableHashMap<AsyncMultiRead, AsyncMultiReadEntry>();
- multiReadMap = new StableHashMap<MultiRead, MultiReadEntry>();
- externalReadMap = new StableHashMap<ExternalRead, ExternalReadEntry>();
- listeners = new THashMap<CacheEntry, ArrayList<ListenerEntry>>(10, 0.75f);
-
// Now start threads
for (int i = 0; i < THREADS; i++) {
executors[i].start();
public final <T> void runAsyncRead(final ReadGraphImpl graph, final AsyncRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncProcedure<T> procedure) {
- int hash = requestHash(query);
-
- AsyncReadEntry<T> entry = asyncReadMap.get(query, hash);
-
- if(parent == null && listener == null) {
- if(entry != null && (entry.isReady() || entry.isExcepted())) {
- System.out.println("ready " + query);
- entry.performFromCache(graph, this, procedure);
-// graph.state.barrier.dec(query);
- return;
- } else {
- query.perform(graph, procedure);
-// graph.state.barrier.dec(query);
- return;
- }
+ try {
+ cache.runQuery(graph, query, parent, listener, procedure);
+ } catch (DatabaseException e) {
+ throw new IllegalStateException(e);
}
-
- if(entry == null) {
-
- entry = new AsyncReadEntry<T>(query);
- entry.setPending();
- entry.clearResult(querySupport);
- asyncReadMap.put(query, entry, hash);
-
- performForEach(graph, query, entry, parent, listener, procedure, false);
-
- } else {
-
- if(entry.isPending()) {
- synchronized(entry) {
- if(entry.isPending()) {
- throw new IllegalStateException();
- // final AsyncBarrierImpl parentBarrier = graph.state.barrier;
- // if(entry.procs == null) entry.procs = new ArrayList<AsyncProcedure<T>>();
- // entry.procs.add(new AsyncProcedure<T>() {
- //
- // @Override
- // public void execute(AsyncReadGraph graph, T result) {
- // procedure.execute(graph, result);
- // parentBarrier.dec(query);
- // }
- //
- // @Override
- // public void exception(AsyncReadGraph graph, Throwable throwable) {
- // procedure.exception(graph, throwable);
- // parentBarrier.dec(query);
- // }
- //
- // });
-// if(graph.parent != null || listener != null) {
-// registerDependencies(graph, entry, parent, listener, procedure, false);
-// }
+
+// int hash = requestHash(query);
//
-// query.perform(graph, procedure);
+// AsyncReadEntry<T> entry = asyncReadMap.get(query, hash);
//
-// return;
-
- }
- }
- }
-
- if(entry.isReady()) {
- entry.performFromCache(graph, this, procedure);
- registerDependencies(graph, entry, parent, listener, procedure, false);
- } else {
- performForEach(graph, query, entry, parent, listener, procedure, false);
- }
-
- }
+// if(parent == null && listener == null) {
+// if(entry != null && (entry.isReady() || entry.isExcepted())) {
+// System.out.println("ready " + query);
+// entry.performFromCache(graph, this, procedure);
+//// graph.state.barrier.dec(query);
+// return;
+// } else {
+// query.perform(graph, procedure);
+//// graph.state.barrier.dec(query);
+// return;
+// }
+// }
+//
+// if(entry == null) {
+//
+// entry = new AsyncReadEntry<T>(query);
+// entry.setPending();
+// entry.clearResult(querySupport);
+// asyncReadMap.put(query, entry, hash);
+//
+// performForEach(graph, query, entry, parent, listener, procedure, false);
+//
+// } else {
+//
+// if(entry.isPending()) {
+// synchronized(entry) {
+// if(entry.isPending()) {
+// throw new IllegalStateException();
+// // final AsyncBarrierImpl parentBarrier = graph.state.barrier;
+// // if(entry.procs == null) entry.procs = new ArrayList<AsyncProcedure<T>>();
+// // entry.procs.add(new AsyncProcedure<T>() {
+// //
+// // @Override
+// // public void execute(AsyncReadGraph graph, T result) {
+// // procedure.execute(graph, result);
+// // parentBarrier.dec(query);
+// // }
+// //
+// // @Override
+// // public void exception(AsyncReadGraph graph, Throwable throwable) {
+// // procedure.exception(graph, throwable);
+// // parentBarrier.dec(query);
+// // }
+// //
+// // });
+//// if(graph.parent != null || listener != null) {
+//// registerDependencies(graph, entry, parent, listener, procedure, false);
+//// }
+////
+//// query.perform(graph, procedure);
+////
+//// return;
+//
+// }
+// }
+// }
+//
+// if(entry.isReady()) {
+// entry.performFromCache(graph, this, procedure);
+// registerDependencies(graph, entry, parent, listener, procedure, false);
+// } else {
+// performForEach(graph, query, entry, parent, listener, procedure, false);
+// }
+//
+// }
}
- final static <T> void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) {
-
- MultiReadEntry entry = cached != null ? cached : provider.multiReadMap.get(query);
- if(entry == null) {
-
- entry = new MultiReadEntry(query);
- entry.setPending();
- entry.clearResult(provider.querySupport);
-
- provider.multiReadMap.put(query, entry);
-
- provider.performForEach(graph, query, entry, parent, listener, procedure, false);
-
- } else {
-
- if(entry.isPending()) {
+ final <T> void runMultiRead(final ReadGraphImpl graph, MultiReadEntry cached, final MultiRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) {
- synchronized(entry) {
-
- if(entry.isPending()) {
- throw new IllegalStateException();
-
-// if(entry.procs == null) entry.procs = new ArrayList<Pair<AsyncMultiProcedure<T>, AsyncBarrier>>();
-// entry.procs.add(new Pair(procedure, parentBarrier));
-// if(graph.parent != null || listener != null) {
-// provider.registerDependencies(graph, entry, parent, listener, procedure, false);
-// }
+ try {
+ cache.runQuery(graph, query, parent, listener, procedure);
+ } catch (DatabaseException e) {
+ throw new IllegalStateException(e);
+ }
- // If this was synchronized we must wait here until completion
- // if(graph.state.synchronizedExecution) {
- // while(entry.isPending()) {
- // graph.resumeTasks(graph.callerThread, null, null);
- // }
- // }
+// MultiReadEntry entry = cached != null ? cached : provider.multiReadMap.get(query);
+// if(entry == null) {
//
-// return;
-
- }
- }
-
- entry.performFromCache(graph, provider, procedure);
-// graph.state.barrier.dec(query);
- return;
-
- } else {
-
- provider.performForEach(graph, query, entry, parent, listener, procedure, false);
-
- }
-
- }
+// entry = new MultiReadEntry(query);
+// entry.setPending();
+// entry.clearResult(provider.querySupport);
+//
+// provider.multiReadMap.put(query, entry);
+//
+// provider.performForEach(graph, query, entry, parent, listener, procedure, false);
+//
+// } else {
+//
+// if(entry.isPending()) {
+//
+// synchronized(entry) {
+//
+// if(entry.isPending()) {
+// throw new IllegalStateException();
+//
+//// if(entry.procs == null) entry.procs = new ArrayList<Pair<AsyncMultiProcedure<T>, AsyncBarrier>>();
+//// entry.procs.add(new Pair(procedure, parentBarrier));
+//// if(graph.parent != null || listener != null) {
+//// provider.registerDependencies(graph, entry, parent, listener, procedure, false);
+//// }
+//
+// // If this was synchronized we must wait here until completion
+// // if(graph.state.synchronizedExecution) {
+// // while(entry.isPending()) {
+// // graph.resumeTasks(graph.callerThread, null, null);
+// // }
+// // }
+////
+//// return;
+//
+// }
+// }
+//
+// entry.performFromCache(graph, provider, procedure);
+//// graph.state.barrier.dec(query);
+// return;
+//
+// } else {
+//
+// provider.performForEach(graph, query, entry, parent, listener, procedure, false);
+//
+// }
+//
+// }
}
public final <T> void runAsyncMultiRead(final ReadGraphImpl graph, final AsyncMultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) {
- int hash = requestHash(query);
-
- AsyncMultiReadEntry entry = asyncMultiReadMap.get(query, hash);
-
- if(parent == null && listener == null) {
- if(entry != null && (entry.isReady() || entry.isExcepted())) {
- System.out.println("ready " + query);
- entry.performFromCache(graph, this, procedure);
- return;
- } else {
- query.perform(graph, procedure);
- return;
- }
+
+ try {
+ cache.runQuery(graph, query, parent, listener, procedure);
+ } catch (DatabaseException e) {
+ throw new IllegalStateException(e);
}
- if(entry == null) {
-
- entry = new AsyncMultiReadEntry<T>(query);
- entry.setPending();
- entry.clearResult(querySupport);
-
- asyncMultiReadMap.put(query, entry, hash);
- performForEach(graph, query, entry, parent, listener, procedure, false);
-
- } else {
-
- if(entry.isPending()) {
-
- synchronized(entry) {
- if(entry.isPending()) {
- throw new IllegalStateException();
-// if(entry.procs == null) entry.procs = new ArrayList<AsyncMultiProcedure<T>>();
-// entry.procs.add(procedure);
-// if(graph.parent != null || listener != null) {
-// registerDependencies(graph, entry, parent, listener, procedure, false);
-// }
-// return;
- }
- }
- }
-
- performForEach(graph, query, entry, parent, listener, procedure, false);
-
- }
+// int hash = requestHash(query);
+//
+// AsyncMultiReadEntry entry = asyncMultiReadMap.get(query, hash);
+//
+// if(parent == null && listener == null) {
+// if(entry != null && (entry.isReady() || entry.isExcepted())) {
+// System.out.println("ready " + query);
+// entry.performFromCache(graph, this, procedure);
+// return;
+// } else {
+// query.perform(graph, procedure);
+// return;
+// }
+// }
+//
+// if(entry == null) {
+//
+// entry = new AsyncMultiReadEntry<T>(query);
+// entry.setPending();
+// entry.clearResult(querySupport);
+//
+// asyncMultiReadMap.put(query, entry, hash);
+//
+// performForEach(graph, query, entry, parent, listener, procedure, false);
+//
+// } else {
+//
+// if(entry.isPending()) {
+//
+// synchronized(entry) {
+// if(entry.isPending()) {
+// throw new IllegalStateException();
+//// if(entry.procs == null) entry.procs = new ArrayList<AsyncMultiProcedure<T>>();
+//// entry.procs.add(procedure);
+//// if(graph.parent != null || listener != null) {
+//// registerDependencies(graph, entry, parent, listener, procedure, false);
+//// }
+//// return;
+// }
+// }
+// }
+//
+// performForEach(graph, query, entry, parent, listener, procedure, false);
+//
+// }
}
- final static <T> void runPrimitiveRead(ReadGraphImpl graph, ExternalReadEntry cached, final ExternalRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final Procedure<T> procedure) {
+ final <T> void runPrimitiveRead(ReadGraphImpl graph, ExternalReadEntry cached, final ExternalRead<T> query, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final Procedure<T> procedure) throws DatabaseException {
- final ExternalReadEntry<T> entry = cached != null ? cached : provider.externalReadMap.get(query);
- if(entry == null) {
- provider.performForEach(graph, query, new ExternalReadEntry<T>(query), parent, listener, procedure, false);
- } else {
- if(entry.isPending()) {
- synchronized(entry) {
- if(entry.isPending()) {
- throw new IllegalStateException();
-// if(entry.procs == null) entry.procs = new ArrayList<Procedure<T>>();
-// entry.procs.add(procedure);
-// return;
- }
- }
- }
- provider.performForEach(graph, query, entry, parent, listener, procedure, false);
- }
+ cache.runQuery(graph, query, parent, listener, procedure);
+
+// final ExternalReadEntry<T> entry = cached != null ? cached : provider.externalReadMap.get(query);
+// if(entry == null) {
+// provider.performForEach(graph, query, new ExternalReadEntry<T>(query), parent, listener, procedure, false);
+// } else {
+// if(entry.isPending()) {
+// synchronized(entry) {
+// if(entry.isPending()) {
+// throw new IllegalStateException();
+//// if(entry.procs == null) entry.procs = new ArrayList<Procedure<T>>();
+//// entry.procs.add(procedure);
+//// return;
+// }
+// }
+// }
+// provider.performForEach(graph, query, entry, parent, listener, procedure, false);
+// }
}
@Override
public <T> T queryRead(final ReadGraphImpl graph, final Read<T> query, final CacheEntry parent, final AsyncProcedure<T> procedure, final ListenerBase listener) throws Throwable {
- assert(query != null);
-
- ReadEntry entry = readMap.get(query);
-
- if(entry != null) {
- if(parent == null && (listener == null || listener.isDisposed()) && entry.isReady()) {
- return (T)entry.get(graph, this, procedure);
- } else if (entry.isPending()) {
- throw new IllegalStateException();
- }
- }
-
- if(entry == null) {
-
- entry = new ReadEntry(query);
- entry.setPending();
- entry.clearResult(querySupport);
-
- readMap.put(query, entry);
-
- return (T)performForEach(graph, query, entry, parent, listener, procedure, false);
-
- } else {
-
- if(entry.isPending()) {
- throw new IllegalStateException();
- } else {
- return (T)performForEach(graph, query, entry, parent, listener, procedure, false);
- }
-
- }
-
- }
-
- public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) {
-
- assert(query != null);
- assert(procedure != null);
-
- final MultiReadEntry entry = multiReadMap.get(query);
-
- if(parent == null && !(listener != null)) {
- if(entry != null && entry.isReady()) {
- entry.performFromCache(graph, this, procedure);
- return;
- }
- }
-
- runMultiRead(graph, entry, query, parent, this, listener, procedure);
-
- }
-
- public <T> void queryPrimitiveRead(final ReadGraphImpl graph, final ExternalRead<T> query, final CacheEntry parent, final ListenerBase listener, final Procedure<T> procedure) {
-
- assert(query != null);
- assert(procedure != null);
-
- final ExternalReadEntry entry = externalReadMap.get(query);
-
- if(parent == null && !(listener != null)) {
- if(entry != null && entry.isReady()) {
- entry.performFromCache(procedure);
- return;
- }
- }
-
- runPrimitiveRead(graph, entry, query, parent, this, listener, procedure);
-
- }
-
- public <T> void performForEach(ReadGraphImpl parentGraph, final AsyncRead<T> query, final AsyncReadEntry<T> entry, final CacheEntry parent, final ListenerBase base, final AsyncProcedure<T> procedure,
- boolean inferredDependency) {
-
- if (DebugPolicy.PERFORM)
- System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
-
- assert (!dirty);
- assert (!collecting);
-
- assert(!entry.isDiscarded());
-
- final ListenerEntry listenerEntry = registerDependencies(parentGraph, entry, parent, base, procedure, inferredDependency);
-
- // FRESH, REFUTED, EXCEPTED go here
- if (!entry.isReady()) {
-
- entry.setPending();
+ return (T)cache.runQuery(graph, query, parent, listener, procedure);
- size++;
-
- try {
-
- final ReadGraphImpl finalParentGraph = parentGraph;
-
- query.perform(parentGraph.withParent(entry), new AsyncProcedure<T>() {
-
- @Override
- public void execute(AsyncReadGraph returnGraph, T result) {
- ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
- //AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
- entry.addOrSet(finalParentGraph, result);
- if(listenerEntry != null) {
- primeListenerEntry(listenerEntry, result);
- }
- try {
- procedure.execute(finalParentGraph, result);
- } catch (Throwable t) {
- t.printStackTrace();
- }
-// parentBarrier.dec(query);
- }
-
- @Override
- public void exception(AsyncReadGraph returnGraph, Throwable t) {
- ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
-// AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
- entry.except(finalParentGraph, t);
- try {
- procedure.exception(finalParentGraph, t);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
-// parentBarrier.dec(query);
- }
-
- @Override
- public String toString() {
- return procedure.toString();
- }
-
- });
-
- } catch (Throwable t) {
-
- entry.except(t);
- try {
- procedure.exception(parentGraph, t);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
-// parentBarrier.dec(query);
-
- }
-
- misses++;
-
- } else {
-
- entry.performFromCache(parentGraph, this, new AsyncProcedure<T>() {
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable throwable) {
- procedure.exception(graph, throwable);
- }
-
- @Override
- public void execute(AsyncReadGraph graph, T result) {
- procedure.execute(graph, result);
- if(listenerEntry != null) {
- primeListenerEntry(listenerEntry, result);
- }
- }
-
- });
-
-// parentBarrier.dec(query);
-
- hits++;
-
- }
-
- assert (!entry.isDiscarded());
-
- }
-
- public <T> T performForEach(final ReadGraphImpl graph, final Read<T> query, final ReadEntry<T> entry, final CacheEntry parent, final ListenerBase listener, final AsyncProcedure<T> procedure,
- boolean inferredDependency) throws Throwable {
-
- if (DebugPolicy.PERFORM)
- System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
-
- assert (!dirty);
- assert (!collecting);
-
- entry.assertNotDiscarded();
-
- if(entry.isReady()) {
-
- // EXCEPTED goes here
-
-// if(procedure != null) entry.performFromCache(graph, this, procedure);
-// parentBarrier.dec(query);
- hits++;
-
- ListenerEntry listenerEntry = registerDependencies(graph, entry, parent, listener, procedure, inferredDependency);
-
- T result = (T)entry.get(graph, this, procedure);
-
- if(listenerEntry != null) primeListenerEntry(listenerEntry, result);
-
- return result;
-
- } else {
-
- // FRESH, REFUTED, PENDING go here
-
- entry.setPending();
-
- size++;
- misses++;
-
- ListenerEntry listenerEntry = registerDependencies(graph, entry, parent, listener, procedure, inferredDependency);
-
- final ReadGraphImpl performGraph = graph.newSync(entry);
-
- try {
-
- if(Development.DEVELOPMENT)
- Development.recordHistogram("run " + query);
-
- T result = query.perform(performGraph);
- entry.addOrSet(performGraph, result);
-
- if(listenerEntry != null) primeListenerEntry(listenerEntry, result);
-
- return (T)entry.get(graph, this, procedure);
-
- } catch (Throwable t) {
-
- entry.except(t);
- return (T)entry.get(graph, this, procedure);
-
- }
-
- }
+// assert(query != null);
+//
+// ReadEntry entry = readMap.get(query);
+//
+// if(entry != null) {
+// if(parent == null && (listener == null || listener.isDisposed()) && entry.isReady()) {
+// return (T)entry.get(graph, this, procedure);
+// } else if (entry.isPending()) {
+// throw new IllegalStateException();
+// }
+// }
+//
+// if(entry == null) {
+//
+// entry = new ReadEntry(query);
+// entry.setPending();
+// entry.clearResult(querySupport);
+//
+// readMap.put(query, entry);
+//
+// return (T)performForEach(graph, query, entry, parent, listener, procedure, false);
+//
+// } else {
+//
+// if(entry.isPending()) {
+// throw new IllegalStateException();
+// } else {
+// return (T)performForEach(graph, query, entry, parent, listener, procedure, false);
+// }
+//
+// }
}
- public <T> void performForEach(final ReadGraphImpl graph, final MultiRead<T> query, final MultiReadEntry<T> entry, CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure,
- boolean inferredDependency) {
-
- if (DebugPolicy.PERFORM)
- System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
-
- assert (!dirty);
- assert (!collecting);
-
- assert(!entry.isPending());
- assert(!entry.isDiscarded());
-
- // FRESH, REFUTED, EXCEPTED go here
- if (!entry.isReady()) {
-
- entry.setPending();
- entry.clearResult(querySupport);
-
- multiReadMap.put(query, entry);
- size++;
-
- final ReadGraphImpl newGraph = graph.newSync(entry);
-// newGraph.state.barrier.inc();
-
- try {
-
- query.perform(newGraph, new AsyncMultiProcedure<T>() {
+ public <T> void queryMultiRead(final ReadGraphImpl graph, final MultiRead<T> query, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure) throws DatabaseException {
- @Override
- public void execute(AsyncReadGraph graph, T result) {
- entry.addOrSet(result);
- try {
- procedure.execute(graph, result);
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
-
- @Override
- public void finished(AsyncReadGraph graph) {
- entry.finish(graph);
- try {
- procedure.finished(graph);
- } catch (Throwable t) {
- t.printStackTrace();
- }
-// newGraph.state.barrier.dec();
-// parentBarrier.dec();
- }
+ cache.runQuery(graph, query, parent, listener, procedure);
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- entry.except(t);
- try {
- procedure.exception(graph, t);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
-// newGraph.state.barrier.dec();
-// parentBarrier.dec();
- }
-
- });
-
- } catch (DatabaseException e) {
-
- entry.except(e);
- try {
- procedure.exception(graph, e);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
-// newGraph.state.barrier.dec();
-// parentBarrier.dec();
-
- } catch (Throwable t) {
-
- DatabaseException e = new DatabaseException(t);
-
- entry.except(e);
- try {
- procedure.exception(graph, e);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
-// newGraph.state.barrier.dec();
-// parentBarrier.dec();
-
- }
-
- misses++;
-
- } else {
-
- entry.performFromCache(graph, this, procedure);
- hits++;
-
-
- }
-
- assert (!entry.isDiscarded());
-
- registerDependencies(graph, entry, parent, listener, procedure, inferredDependency);
+// assert(query != null);
+// assert(procedure != null);
+//
+// final MultiReadEntry entry = multiReadMap.get(query);
+//
+// if(parent == null && !(listener != null)) {
+// if(entry != null && entry.isReady()) {
+// entry.performFromCache(graph, this, procedure);
+// return;
+// }
+// }
+//
+// runMultiRead(graph, entry, query, parent, this, listener, procedure);
}
+ public <T> void queryPrimitiveRead(final ReadGraphImpl graph, final ExternalRead<T> query, final CacheEntry parent, final ListenerBase listener, final Procedure<T> procedure) throws DatabaseException {
- public <T> void performForEach(final ReadGraphImpl callerGraph, AsyncMultiRead<T> query, final AsyncMultiReadEntry<T> entry, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure,
- boolean inferredDependency) {
-
- if (DebugPolicy.PERFORM)
- System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
-
- assert (!dirty);
- assert (!collecting);
-
- try {
-
- assert(!entry.isDiscarded());
-
- // FRESH, REFUTED, EXCEPTED go here
- if (!entry.isReady()) {
-
- size++;
-
- try {
-
- ReadGraphImpl performGraph = callerGraph.withAsyncParent(entry);
-
- query.perform(performGraph, new AsyncMultiProcedure<T>() {
-
- @Override
- public void execute(AsyncReadGraph graph, T result) {
- ReadGraphImpl impl = (ReadGraphImpl)graph;
-// ReadGraphImpl executeGraph = callerGraph.newAsync();
- entry.addOrSet(result);
- try {
- procedure.execute(callerGraph, result);
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
-
- @Override
- public void finished(AsyncReadGraph graph) {
- ReadGraphImpl impl = (ReadGraphImpl)graph;
-// ReadGraphImpl executeGraph = callerGraph.newAsync();
- entry.finish(callerGraph);
- try {
- procedure.finished(callerGraph);
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
-
- @Override
- public void exception(AsyncReadGraph graph, Throwable t) {
- ReadGraphImpl impl = (ReadGraphImpl)graph;
-// ReadGraphImpl executeGraph = callerGraph.newAsync();
- entry.except(callerGraph, t);
- try {
- procedure.exception(callerGraph, t);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
- }
-
- });
-
- } catch (Throwable t) {
-
- entry.except(t);
- try {
- procedure.exception(callerGraph, t);
- } catch (Throwable t2) {
- t2.printStackTrace();
- }
-
- }
-
-
- misses++;
+ cache.runQuery(graph, query, parent, listener, procedure);
- } else {
-
- entry.performFromCache(callerGraph, this, procedure);
-
- hits++;
-
- }
-
- assert (!entry.isDiscarded());
-
- registerDependencies(callerGraph, entry, parent, listener, procedure, inferredDependency);
-
- } catch (Throwable t) {
-
- Logger.defaultLogError(t);
-
- } finally {
-
- }
+// assert(query != null);
+// assert(procedure != null);
+//
+// final ExternalReadEntry entry = externalReadMap.get(query);
+//
+// if(parent == null && !(listener != null)) {
+// if(entry != null && entry.isReady()) {
+// entry.performFromCache(procedure);
+// return;
+// }
+// }
+//
+// runPrimitiveRead(graph, entry, query, parent, this, listener, procedure);
}
- public <T> void performForEach(ReadGraphImpl graph, final ExternalRead<T> query, final ExternalReadEntry<T> entry, final CacheEntry parent, final ListenerBase base, final Procedure<T> procedure,
- boolean inferredDependency) {
-
- if (DebugPolicy.PERFORM)
- System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
-
- assert (!dirty);
- assert (!collecting);
-
- assert(!entry.isPending());
- assert(!entry.isDiscarded());
-
- registerDependencies(graph, entry, parent, base, procedure, inferredDependency);
-
- // FRESH, REFUTED, EXCEPTED go here
- if (!entry.isReady()) {
-
- entry.setPending();
- entry.clearResult(querySupport);
-
- externalReadMap.put(query, entry);
- size++;
-
- try {
-
- query.register(graph, new Listener<T>() {
-
- AtomicBoolean used = new AtomicBoolean(false);
-
- @Override
- public void execute(T result) {
-
- // Just for safety
- if(entry.isDiscarded()) return;
- if(entry.isExcepted()) entry.setPending();
-
- if(used.compareAndSet(false, true)) {
- entry.addOrSet(QueryProcessor.this, result);
- procedure.execute(result);
- } else {
- entry.queue(result);
- updatePrimitive(query);
- }
-
- }
+// public <T> void performForEach(ReadGraphImpl parentGraph, final AsyncRead<T> query, final AsyncReadEntry<T> entry, final CacheEntry parent, final ListenerBase base, final AsyncProcedure<T> procedure,
+// boolean inferredDependency) {
+//
+// if (DebugPolicy.PERFORM)
+// System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
+//
+// assert (!dirty);
+// assert (!collecting);
+//
+// assert(!entry.isDiscarded());
+//
+// final ListenerEntry listenerEntry = registerDependencies(parentGraph, entry, parent, base, procedure, inferredDependency);
+//
+// // FRESH, REFUTED, EXCEPTED go here
+// if (!entry.isReady()) {
+//
+// entry.setPending();
+//
+// size++;
+//
+// try {
+//
+// final ReadGraphImpl finalParentGraph = parentGraph;
+//
+// query.perform(parentGraph.withParent(entry), new AsyncProcedure<T>() {
+//
+// @Override
+// public void execute(AsyncReadGraph returnGraph, T result) {
+// ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+// //AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
+// entry.addOrSet(finalParentGraph, result);
+// if(listenerEntry != null) {
+// primeListenerEntry(listenerEntry, result);
+// }
+// try {
+// procedure.execute(finalParentGraph, result);
+// } catch (Throwable t) {
+// t.printStackTrace();
+// }
+//// parentBarrier.dec(query);
+// }
+//
+// @Override
+// public void exception(AsyncReadGraph returnGraph, Throwable t) {
+// ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
+//// AsyncReadGraph resumeGraph = finalParentGraph.newAsync();
+// entry.except(finalParentGraph, t);
+// try {
+// procedure.exception(finalParentGraph, t);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+//// parentBarrier.dec(query);
+// }
+//
+// @Override
+// public String toString() {
+// return procedure.toString();
+// }
+//
+// });
+//
+// } catch (Throwable t) {
+//
+// entry.except(t);
+// try {
+// procedure.exception(parentGraph, t);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+//// parentBarrier.dec(query);
+//
+// }
+//
+// misses++;
+//
+// } else {
+//
+// entry.performFromCache(parentGraph, this, new AsyncProcedure<T>() {
+//
+// @Override
+// public void exception(AsyncReadGraph graph, Throwable throwable) {
+// procedure.exception(graph, throwable);
+// }
+//
+// @Override
+// public void execute(AsyncReadGraph graph, T result) {
+// procedure.execute(graph, result);
+// if(listenerEntry != null) {
+// primeListenerEntry(listenerEntry, result);
+// }
+// }
+//
+// });
+//
+//// parentBarrier.dec(query);
+//
+// hits++;
+//
+// }
+//
+// assert (!entry.isDiscarded());
+//
+// }
- @Override
- public void exception(Throwable t) {
-
- entry.except(t);
+// public <T> T performForEach(final ReadGraphImpl graph, final Read<T> query, final ReadEntry<T> entry, final CacheEntry parent, final ListenerBase listener, final AsyncProcedure<T> procedure,
+// boolean inferredDependency) throws Throwable {
+//
+// if (DebugPolicy.PERFORM)
+// System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
+//
+// assert (!dirty);
+// assert (!collecting);
+//
+// entry.assertNotDiscarded();
+//
+// if(entry.isReady()) {
+//
+// // EXCEPTED goes here
+//
+//// if(procedure != null) entry.performFromCache(graph, this, procedure);
+//// parentBarrier.dec(query);
+// hits++;
+//
+// ListenerEntry listenerEntry = registerDependencies(graph, entry, parent, listener, procedure, inferredDependency);
+//
+// T result = (T)entry.get(graph, this, procedure);
+//
+// if(listenerEntry != null) primeListenerEntry(listenerEntry, result);
+//
+// return result;
+//
+// } else {
+//
+// // FRESH, REFUTED, PENDING go here
+//
+// entry.setPending();
+//
+// size++;
+// misses++;
+//
+// ListenerEntry listenerEntry = registerDependencies(graph, entry, parent, listener, procedure, inferredDependency);
+//
+// final ReadGraphImpl performGraph = graph.newSync(entry);
+//
+// try {
+//
+// if(Development.DEVELOPMENT)
+// Development.recordHistogram("run " + query);
+//
+// T result = query.perform(performGraph);
+// entry.addOrSet(performGraph, result);
+//
+// if(listenerEntry != null) primeListenerEntry(listenerEntry, result);
+//
+// return (T)entry.get(graph, this, procedure);
+//
+// } catch (Throwable t) {
+//
+// entry.except(t);
+// return (T)entry.get(graph, this, procedure);
+//
+// }
+//
+// }
+//
+// }
- if(used.compareAndSet(false, true)) {
- procedure.exception(t);
- } else {
+// public <T> void performForEach(final ReadGraphImpl graph, final MultiRead<T> query, final MultiReadEntry<T> entry, CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure,
+// boolean inferredDependency) {
+//
+// if (DebugPolicy.PERFORM)
+// System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
+//
+// assert (!dirty);
+// assert (!collecting);
+//
+// assert(!entry.isPending());
+// assert(!entry.isDiscarded());
+//
+// // FRESH, REFUTED, EXCEPTED go here
+// if (!entry.isReady()) {
+//
+// entry.setPending();
+// entry.clearResult();
+//
+// multiReadMap.put(query, entry);
+// size++;
+//
+// final ReadGraphImpl newGraph = graph.newSync(entry);
+//// newGraph.state.barrier.inc();
+//
+// try {
+//
+// query.perform(newGraph, new AsyncMultiProcedure<T>() {
+//
+// @Override
+// public void execute(AsyncReadGraph graph, T result) {
+// entry.addOrSet(result);
+// try {
+// procedure.execute(graph, result);
+// } catch (Throwable t) {
+// t.printStackTrace();
+// }
+// }
+//
+// @Override
+// public void finished(AsyncReadGraph graph) {
+// entry.finish(graph);
+// try {
+// procedure.finished(graph);
+// } catch (Throwable t) {
+// t.printStackTrace();
+// }
+//// newGraph.state.barrier.dec();
+//// parentBarrier.dec();
+// }
+//
+// @Override
+// public void exception(AsyncReadGraph graph, Throwable t) {
+// entry.except(t);
+// try {
+// procedure.exception(graph, t);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+//// newGraph.state.barrier.dec();
+//// parentBarrier.dec();
+// }
+//
+// });
+//
+// } catch (DatabaseException e) {
+//
+// entry.except(e);
+// try {
+// procedure.exception(graph, e);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+//// newGraph.state.barrier.dec();
+//// parentBarrier.dec();
+//
+// } catch (Throwable t) {
+//
+// DatabaseException e = new DatabaseException(t);
+//
+// entry.except(e);
+// try {
+// procedure.exception(graph, e);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+//// newGraph.state.barrier.dec();
+//// parentBarrier.dec();
+//
+// }
+//
+// misses++;
+//
+// } else {
+//
+// entry.performFromCache(graph, this, procedure);
+// hits++;
+//
+//
+// }
+//
+// assert (!entry.isDiscarded());
+//
+// registerDependencies(graph, entry, parent, listener, procedure, inferredDependency);
+//
+// }
+//
+//
+// public <T> void performForEach(final ReadGraphImpl callerGraph, AsyncMultiRead<T> query, final AsyncMultiReadEntry<T> entry, final CacheEntry parent, final ListenerBase listener, final AsyncMultiProcedure<T> procedure,
+// boolean inferredDependency) {
+//
+// if (DebugPolicy.PERFORM)
+// System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
+//
+// assert (!dirty);
+// assert (!collecting);
+//
+// try {
+//
+// assert(!entry.isDiscarded());
+//
+// // FRESH, REFUTED, EXCEPTED go here
+// if (!entry.isReady()) {
+//
+// size++;
+//
+// try {
+//
+// ReadGraphImpl performGraph = callerGraph.withAsyncParent(entry);
+//
+// query.perform(performGraph, new AsyncMultiProcedure<T>() {
+//
+// @Override
+// public void execute(AsyncReadGraph graph, T result) {
+// ReadGraphImpl impl = (ReadGraphImpl)graph;
+//// ReadGraphImpl executeGraph = callerGraph.newAsync();
+// entry.addOrSet(result);
+// try {
+// procedure.execute(callerGraph, result);
+// } catch (Throwable t) {
+// t.printStackTrace();
+// }
+// }
+//
+// @Override
+// public void finished(AsyncReadGraph graph) {
+// ReadGraphImpl impl = (ReadGraphImpl)graph;
+//// ReadGraphImpl executeGraph = callerGraph.newAsync();
+// entry.finish(callerGraph);
+// try {
+// procedure.finished(callerGraph);
+// } catch (Throwable t) {
+// t.printStackTrace();
+// }
+// }
+//
+// @Override
+// public void exception(AsyncReadGraph graph, Throwable t) {
+// ReadGraphImpl impl = (ReadGraphImpl)graph;
+//// ReadGraphImpl executeGraph = callerGraph.newAsync();
+// entry.except(callerGraph, t);
+// try {
+// procedure.exception(callerGraph, t);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+// }
+//
+// });
+//
+// } catch (Throwable t) {
+//
+// entry.except(t);
+// try {
+// procedure.exception(callerGraph, t);
+// } catch (Throwable t2) {
+// t2.printStackTrace();
+// }
+//
+// }
+//
+//
+// misses++;
+//
+// } else {
+//
+// entry.performFromCache(callerGraph, this, procedure);
+//
+// hits++;
+//
+// }
+//
+// assert (!entry.isDiscarded());
+//
+// registerDependencies(callerGraph, entry, parent, listener, procedure, inferredDependency);
+//
+// } catch (Throwable t) {
+//
+// Logger.defaultLogError(t);
+//
+// } finally {
+//
+// }
+//
+// }
+//
+// public <T> void performForEach(ReadGraphImpl graph, final ExternalRead<T> query, final ExternalReadEntry<T> entry, final CacheEntry parent, final ListenerBase base, final Procedure<T> procedure,
+// boolean inferredDependency) {
+//
+// if (DebugPolicy.PERFORM)
+// System.out.println("PE[ " + (query.hashCode() & THREAD_MASK) + "] " + query);
+//
+// assert (!dirty);
+// assert (!collecting);
+//
+// assert(!entry.isPending());
+// assert(!entry.isDiscarded());
+//
+// registerDependencies(graph, entry, parent, base, procedure, inferredDependency);
+//
+// // FRESH, REFUTED, EXCEPTED go here
+// if (!entry.isReady()) {
+//
+// entry.setPending();
+// entry.clearResult(querySupport);
+//
+// externalReadMap.put(query, entry);
+// size++;
+//
+// try {
+//
+// query.register(graph, new Listener<T>() {
+//
+// AtomicBoolean used = new AtomicBoolean(false);
+//
+// @Override
+// public void execute(T result) {
+//
+// // Just for safety
+// if(entry.isDiscarded()) return;
+// if(entry.isExcepted()) entry.setPending();
+//
+// if(used.compareAndSet(false, true)) {
+// entry.addOrSet(QueryProcessor.this, result);
+// procedure.execute(result);
+// } else {
// entry.queue(result);
- updatePrimitive(query);
- }
-
- }
-
- @Override
- public String toString() {
- return procedure.toString();
- }
-
- @Override
- public boolean isDisposed() {
- return entry.isDiscarded() || !isBound(entry);
- }
-
- });
-
- } catch (Throwable t) {
-
- entry.except(t);
- procedure.exception(t);
-
- }
-
- misses++;
-
- } else {
-
- entry.performFromCache(procedure);
-
- hits++;
-
- }
-
- assert (!entry.isDiscarded());
-
- }
+// updatePrimitive(query);
+// }
+//
+// }
+//
+// @Override
+// public void exception(Throwable t) {
+//
+// entry.except(t);
+//
+// if(used.compareAndSet(false, true)) {
+// procedure.exception(t);
+// } else {
+//// entry.queue(result);
+// updatePrimitive(query);
+// }
+//
+// }
+//
+// @Override
+// public String toString() {
+// return procedure.toString();
+// }
+//
+// @Override
+// public boolean isDisposed() {
+// return entry.isDiscarded() || !isBound(entry);
+// }
+//
+// });
+//
+// } catch (Throwable t) {
+//
+// entry.except(t);
+// procedure.exception(t);
+//
+// }
+//
+// misses++;
+//
+// } else {
+//
+// entry.performFromCache(procedure);
+//
+// hits++;
+//
+// }
+//
+// assert (!entry.isDiscarded());
+//
+// }
- private boolean isBound(ExternalReadEntry<?> entry) {
+ boolean isBound(ExternalReadEntry<?> entry) {
if(entry.hasParents()) return true;
else if(hasListener(entry)) return true;
else return false;
}
public Collection<CacheEntry> getRootList() {
-
- ArrayList<CacheEntry> result = new ArrayList<CacheEntry>();
-
- for (Object e : valueMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : directPredicatesMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : objectsMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : directObjectsMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : principalTypesMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : superRelationsMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : superTypesMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : typesMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : objectsMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : assertedStatementsMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : readMap.values()) {
- if(e instanceof CacheEntry) {
- result.add((CacheEntry) e);
- } else {
- System.err.println("e=" + e);
- }
- }
- for (Object e : asyncReadMap.values()) {
- if(e instanceof CacheEntry) {
- result.add((CacheEntry) e);
- } else {
- System.err.println("e=" + e);
- }
- }
- for (Object e : externalReadMap.values()) {
- result.add((CacheEntry) e);
- }
- for (Object e : orderedSetMap.values()) {
- result.add((CacheEntry) e);
- }
-
- return result;
-
+ return cache.getRootList();
}
@Override
public int calculateCurrentSize() {
-
- int realSize = 0;
-
- realSize += directPredicatesMap.size();
- realSize += principalTypesMap.size();
- realSize += uriToResourceMap.size();
- realSize += namespaceIndexMap22.size();
- realSize += projectsMap.size();
-
- realSize += relationInfoMap.size();
- realSize += superTypesMap.size();
- realSize += typeHierarchyMap.size();
- realSize += superRelationsMap.size();
- realSize += typesMap.size();
-
- realSize += valueMap.size();
- realSize += directObjectsMap.size();
- realSize += objectsMap.size();
- realSize += orderedSetMap.size();
- realSize += predicatesMap.size();
-
- realSize += statementsMap.size();
- realSize += assertedPredicatesMap.size();
- realSize += assertedStatementsMap.size();
- realSize += externalReadMap.size();
- realSize += asyncReadMap.size();
-
- realSize += readMap.size();
- realSize += asyncMultiReadMap.size();
- realSize += multiReadMap.size();
-
- size = realSize;
-
- return realSize;
-
+ return cache.calculateCurrentSize();
}
@Override
assert (entry != null);
assert (procedure != null);
- ArrayList<ListenerEntry> list = listeners.get(entry);
+ ArrayList<ListenerEntry> list = cache.listeners.get(entry);
if (list == null) {
list = new ArrayList<ListenerEntry>(1);
- listeners.put(entry, list);
+ cache.listeners.put(entry, list);
}
ListenerEntry result = new ListenerEntry(entry, base, procedure);
private void removeListener(ListenerEntry entry) {
assert (entry != null);
- ArrayList<ListenerEntry> list = listeners.get(entry.entry);
+ ArrayList<ListenerEntry> list = cache.listeners.get(entry.entry);
if(list == null) return;
boolean success = list.remove(entry);
assert (success);
if (list.isEmpty())
- listeners.remove(entry.entry);
+ cache.listeners.remove(entry.entry);
}
private boolean hasListener(CacheEntry entry) {
- if(listeners.get(entry) != null) return true;
+ if(cache.listeners.get(entry) != null) return true;
return false;
}
boolean hasListenerAfterDisposing(CacheEntry entry) {
- if(listeners.get(entry) != null) {
- ArrayList<ListenerEntry> entries = listeners.get(entry);
+ if(cache.listeners.get(entry) != null) {
+ ArrayList<ListenerEntry> entries = cache.listeners.get(entry);
ArrayList<ListenerEntry> list = null;
for (ListenerEntry e : entries) {
if (e.base.isDisposed()) {
}
}
if (entries.isEmpty()) {
- listeners.remove(entry);
+ cache.listeners.remove(entry);
return false;
}
return true;
List<ListenerEntry> getListenerEntries(CacheEntry entry) {
hasListenerAfterDisposing(entry);
- if(listeners.get(entry) != null)
- return listeners.get(entry);
+ if(cache.listeners.get(entry) != null)
+ return cache.listeners.get(entry);
else
return Collections.emptyList();
}
// System.err.println(" => FOO " + type);
if (hasListener) {
- ArrayList<ListenerEntry> entries = listeners.get(entry);
+ ArrayList<ListenerEntry> entries = cache.listeners.get(entry);
if(entries != null) {
for (ListenerEntry le : entries) {
scheduleListener(le);
@Override
public boolean execute(Object arg0) {
- ExternalReadEntry query = (ExternalReadEntry)externalReadMap.get(arg0);
+ ExternalReadEntry query = (ExternalReadEntry)cache.externalReadMap.get(arg0);
if (query != null) {
boolean listening = update(graph, query);
if (!listening && !query.hasParents()) {
- externalReadMap.remove(arg0);
+ cache.externalReadMap.remove(arg0);
query.discard();
}
}
public Set<Long> getReferencedClusters() {
HashSet<Long> result = new HashSet<Long>();
- for (CacheEntry entry : objectsMap.values()) {
+ for (CacheEntry entry : cache.objectsMap.values()) {
Objects query = (Objects) entry.getQuery();
result.add(querySupport.getClusterId(query.r1()));
}
- for (CacheEntry entry : directPredicatesMap.values()) {
+ for (CacheEntry entry : cache.directPredicatesMap.values()) {
DirectPredicates query = (DirectPredicates) entry.getQuery();
result.add(querySupport.getClusterId(query.id));
}
- for (CacheEntry entry : valueMap.values()) {
+ for (CacheEntry entry : cache.valueMap.values()) {
ValueQuery query = (ValueQuery) entry.getQuery();
result.add(querySupport.getClusterId(query.id));
}
}
CacheCollectionResult allCaches(CacheCollectionResult result) {
-
- int level = Integer.MAX_VALUE;
- directPredicatesMap.values(level, result);
- principalTypesMap.values(level, result);
- for(CacheEntryBase e : uriToResourceMap.values())
- if(e.getLevel() <= level)
- result.add(e);
- for(CacheEntryBase e : namespaceIndexMap22.values())
- if(e.getLevel() <= level)
- result.add(e);
- projectsMap.values(level, result);
-
- relationInfoMap.values(level, result);
- superTypesMap.values(level, result);
- typeHierarchyMap.values(level, result);
- superRelationsMap.values(level, result);
- typesMap.values(level, result);
-
- valueMap.values(level, result);
- directObjectsMap.values(level, result);
- objectsMap.values(level, result);
- orderedSetMap.values(level, result);
- predicatesMap.values(level, result);
-
- statementsMap.values(level, result);
- assertedPredicatesMap.values(level, result);
- assertedStatementsMap.values(level, result);
- externalReadMap.values(level, result);
- asyncReadMap.values(level, result);
- readMap.values(level, result);
- asyncMultiReadMap.values(level, result);
- multiReadMap.values(level, result);
-
- return result;
+ return cache.allCaches(result);
}
public CacheEntryBase iterate(int level) {
if(iterator.hasNext()) {
ExternalRead<?> request = iterator.next();
- ExternalReadEntry entry = externalReadMap.get(request);
+ ExternalReadEntry entry = cache.externalReadMap.get(request);
if (entry != null) return entry;
else return iterate(level);
} else {
public Collection<CacheEntry> getRootList() {
ArrayList<CacheEntry> result = new ArrayList<CacheEntry>(requests.size());
for (ExternalRead<?> request : requests) {
- ExternalReadEntry entry = externalReadMap.get(request);
+ ExternalReadEntry entry = cache.externalReadMap.get(request);
if (entry != null)
result.add(entry);
}
}
public void scanPending() {
-
- ArrayList<CacheEntry> entries = new ArrayList<CacheEntry>();
-
- entries.addAll(directPredicatesMap.values());
- entries.addAll(principalTypesMap.values());
- entries.addAll(uriToResourceMap.values());
- entries.addAll(namespaceIndexMap22.values());
- entries.addAll(projectsMap.values());
- entries.addAll(relationInfoMap.values());
- entries.addAll(superTypesMap.values());
- entries.addAll(superRelationsMap.values());
- entries.addAll(typesMap.values());
- entries.addAll(valueMap.values());
- entries.addAll(directObjectsMap.values());
- entries.addAll(objectsMap.values());
- entries.addAll(orderedSetMap.values());
- entries.addAll(predicatesMap.values());
- entries.addAll(orderedSetMap.values());
- entries.addAll(statementsMap.values());
- // entries.addAll(assertedObjectsMap.values());
- entries.addAll(assertedPredicatesMap.values());
- entries.addAll(assertedStatementsMap.values());
- entries.addAll(externalReadMap.values());
- entries.addAll(asyncReadMap.values());
- entries.addAll(externalReadMap.values());
- entries.addAll(readMap.values());
- entries.addAll(asyncMultiReadMap.values());
- entries.addAll(multiReadMap.values());
- entries.addAll(readMap.values());
- System.out.println(entries.size() + " entries.");
- for(Object e : entries) {
- if(e instanceof CacheEntry) {
- CacheEntry en = (CacheEntry)e;
- if(en.isPending()) System.out.println("pending " + e);
- if(en.isExcepted()) System.out.println("excepted " + e);
- if(en.isDiscarded()) System.out.println("discarded " + e);
- if(en.isRefuted()) System.out.println("refuted " + e);
- if(en.isFresh()) System.out.println("fresh " + e);
- } else {
- //System.out.println("Unknown object " + e);
- }
- }
+
+ cache.scanPending();
}
assert(graph != null);
assert(request != null);
- final ReadEntry entry = readMap.get(request);
+ final ReadEntry entry = cache.readMap.get(request);
if(entry != null && entry.isReady()) {
return (T)entry.get(graph, this, null);
} else {
assert(graph != null);
assert(request != null);
- final ExternalReadEntry<T> entry = externalReadMap.get(request);
+ final ExternalReadEntry<T> entry = cache.externalReadMap.get(request);
if(entry != null && entry.isReady()) {
if(entry.isExcepted()) {
Throwable t = (Throwable)entry.getResult();
assert(graph != null);
assert(request != null);
- final AsyncReadEntry entry = asyncReadMap.get(request);
+ final AsyncReadEntry entry = cache.asyncReadMap.get(request);
if(entry != null && entry.isReady()) {
if(entry.isExcepted()) {
procedure.exception(graph, (Throwable)entry.getResult());
assert(request != null);
assert(procedure != null);
-// impl.state.barrier.inc(null, null);
+ try {
- queryMultiRead(impl, request, parent, listener, procedure);
+ queryMultiRead(impl, request, parent, listener, procedure);
+
+ } catch (DatabaseException e) {
+
+ throw new IllegalStateException(e);
+
+ }
}
assert(request != null);
assert(procedure != null);
- queryPrimitiveRead(impl, request, parent, listener, new Procedure<T>() {
-
- @Override
- public void execute(T result) {
- try {
- procedure.execute(result);
- } catch (Throwable t2) {
- Logger.defaultLogError(t2);
+ try {
+
+ queryPrimitiveRead(impl, request, parent, listener, new Procedure<T>() {
+
+ @Override
+ public void execute(T result) {
+ try {
+ procedure.execute(result);
+ } catch (Throwable t2) {
+ Logger.defaultLogError(t2);
+ }
}
- }
-
- @Override
- public String toString() {
- return procedure.toString();
- }
-
- @Override
- public void exception(Throwable t) {
- try {
- procedure.exception(t);
- } catch (Throwable t2) {
- Logger.defaultLogError(t2);
+
+ @Override
+ public String toString() {
+ return procedure.toString();
}
- }
-
- });
+
+ @Override
+ public void exception(Throwable t) {
+ try {
+ procedure.exception(t);
+ } catch (Throwable t2) {
+ Logger.defaultLogError(t2);
+ }
+ }
+
+ });
+
+ } catch (DatabaseException e) {
+
+ throw new IllegalStateException(e);
+
+ }
}
@Override
public void removeEntry(QueryProcessor processor) {
- processor.readMap.remove(request);
+ processor.cache.readMap.remove(request);
}
@Override
}
- public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+ public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
AsyncProcedure<T> proc = (AsyncProcedure<T>)procedure;
- if(isExcepted()) {
-
- try {
- proc.exception(graph, (Throwable)getResult());
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
- } else {
-
- try {
- proc.execute(graph, (T)getResult());
- } catch (Throwable t) {
- t.printStackTrace();
- }
-
- }
+ if(proc != null) {
+ if(isExcepted()) {
+ try {
+ proc.exception(graph, (Throwable)getResult());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ } else {
+ try {
+ proc.execute(graph, (T)getResult());
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+ }
+ return (T)getResult();
+
}
@Override
*******************************************************************************/
package org.simantics.db.impl.query;
-import java.util.ArrayList;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicBoolean;
import org.simantics.db.request.RequestFlags;
final public class RelationInfoQuery extends UnaryQuery<InternalProcedure<RelationInfo>> {
-
-// public ArrayList<InternalProcedure<RelationInfo>> procs = null;
private RelationInfoQuery(final int resource) {
super(resource);
final static RelationInfo runner(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<RelationInfo> procedure) {
- RelationInfoQuery entry = (RelationInfoQuery)provider.relationInfoMap.get(r);
+ RelationInfoQuery entry = (RelationInfoQuery)provider.cache.relationInfoMap.get(r);
if(entry == null) {
entry = new RelationInfoQuery(r);
final public static RelationInfo queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<RelationInfo> procedure) {
- RelationInfoQuery entry = (RelationInfoQuery)provider.relationInfoMap.get(r);
+ RelationInfoQuery entry = (RelationInfoQuery)provider.cache.relationInfoMap.get(r);
if(entry != null && entry.isReady()) {
entry.performFromCache(graph, provider, procedure);
return entry.getResult();
final public static RelationInfoQuery probe(ReadGraphImpl graph, int resource) {
final int thread = graph.thread(resource);
- RelationInfoQuery entry = (RelationInfoQuery)graph.processor.relationInfoMap.get(resource);
+ RelationInfoQuery entry = (RelationInfoQuery)graph.processor.cache.relationInfoMap.get(resource);
if(entry != null && entry.isReady()) {
return entry;
} else {
@Override
public UnaryQuery<InternalProcedure<RelationInfo>> getEntry(QueryProcessor provider) {
- return provider.relationInfoMap.get(id);
+ return provider.cache.relationInfoMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.relationInfoMap.put(id, this);
+ provider.cache.relationInfoMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.relationInfoMap.remove(id);
+ provider.cache.relationInfoMap.remove(id);
}
private void computeAssertions(ReadGraphImpl graph, final boolean isFinal, final boolean isFunctional, final QueryProcessor queryProvider, final InternalProcedure<RelationInfo> proc) {
final public class Statements extends CollectionBinaryQuery<TripleIntProcedure> {
-// public ArrayList<TripleIntProcedure> procs = null;
-
public Statements(final int r1, final int r2) {
super(r1, r2);
}
final static Statements entry(final QueryProcessor processor, final int r1, final int r2) {
- return (Statements)processor.statementsMap.get(id(r1,r2));
+ return (Statements)processor.cache.statementsMap.get(id(r1,r2));
}
final static Collection<Statements> entries(final QueryProcessor processor, final int r1) {
- return processor.statementsMap.values(r1);
+ return processor.cache.statementsMap.values(r1);
}
final static void runner(ReadGraphImpl graph, final int r1, final int r2, CacheEntry parent, final ListenerBase listener, final TripleIntProcedure procedure) {
QueryProcessor processor = graph.processor;
- Statements entry = (Statements)processor.statementsMap.get(id(r1,r2));
+ Statements entry = (Statements)processor.cache.statementsMap.get(id(r1,r2));
if(entry == null) {
entry = new Statements(r1, r2);
@Override
public BinaryQuery<TripleIntProcedure> getEntry(QueryProcessor provider) {
- return provider.statementsMap.get(id);
+ return provider.cache.statementsMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.statementsMap.put(id, this);
+ provider.cache.statementsMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.statementsMap.remove(id);
+ provider.cache.statementsMap.remove(id);
}
final static TripleIntProcedure NOPT = new TripleIntProcedure() {
}
@Override
- public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, final TripleIntProcedure procedure) {
+ public Object performFromCache(ReadGraphImpl graph, QueryProcessor provider, final TripleIntProcedure procedure) {
assert(isReady());
- if(handleException(graph, procedure)) return;
-
final IntArray value = (IntArray)getResult();
+
+ if(handleException(graph, procedure)) return value;
+
for(int i=0;i<value.size();i+=3) {
procedure.execute(graph, value.data[i], value.data[i+1], value.data[i+2]);
}
procedure.finished(graph);
+ return value;
+
}
@Override
}
@Override
- public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+ public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
throw new Error("Not possible.");
}
import org.simantics.db.procedure.ListenerBase;
final public class SuperRelations extends UnaryQuery<InternalProcedure<IntSet>> {
-
-// public ArrayList<InternalProcedure<IntSet>> procs = null;
private SuperRelations(final int resource) {
super(resource);
final static SuperRelations entry(final QueryProcessor provider, final int r) {
- return (SuperRelations)provider.superRelationsMap.get(r);
+ return (SuperRelations)provider.cache.superRelationsMap.get(r);
}
final static IntSet runner(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) {
- SuperRelations entry = (SuperRelations)provider.superRelationsMap.get(r);
+ SuperRelations entry = (SuperRelations)provider.cache.superRelationsMap.get(r);
if(entry == null) {
entry = new SuperRelations(r);
final static IntSet runner2(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) throws Throwable {
- SuperRelations entry = (SuperRelations)provider.superRelationsMap.get(r);
+ SuperRelations entry = (SuperRelations)provider.cache.superRelationsMap.get(r);
if(entry == null) {
entry = new SuperRelations(r);
final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) {
if(parent == null && listener == null) {
- SuperRelations entry = (SuperRelations)provider.superRelationsMap.get(r);
+ SuperRelations entry = (SuperRelations)provider.cache.superRelationsMap.get(r);
if(entry != null && entry.isReady()) {
entry.performFromCache(graph, provider, procedure);
return;
final public static IntSet queryEach2(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) throws Throwable {
if(parent == null && listener == null) {
- SuperRelations entry = (SuperRelations)provider.superRelationsMap.get(r);
+ SuperRelations entry = (SuperRelations)provider.cache.superRelationsMap.get(r);
if(entry != null && entry.isReady()) {
return (IntSet)entry.get(graph, provider, procedure);
}
@Override
public UnaryQuery<InternalProcedure<IntSet>> getEntry(QueryProcessor provider) {
- return provider.superRelationsMap.get(id);
+ return provider.cache.superRelationsMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.superRelationsMap.put(id, this);
+ provider.cache.superRelationsMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.superRelationsMap.remove(id);
+ provider.cache.superRelationsMap.remove(id);
}
static int histoCounter = 0;
import org.simantics.db.procedure.ListenerBase;
final public class SuperTypes extends UnaryQuery<InternalProcedure<IntSet>> {
-
-// public ArrayList<InternalProcedure<IntSet>> procs = null;
private SuperTypes(final int resource) {
super(resource);
final static SuperTypes runner(ReadGraphImpl graph, final int r, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final InternalProcedure<IntSet> procedure) {
- SuperTypes entry = (SuperTypes)provider.superTypesMap.get(r);
+ SuperTypes entry = (SuperTypes)provider.cache.superTypesMap.get(r);
if(entry == null) {
entry = new SuperTypes(r);
final public static SuperTypes queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) {
if(parent == null && listener == null) {
- SuperTypes entry = (SuperTypes)provider.superTypesMap.get(r);
+ SuperTypes entry = (SuperTypes)provider.cache.superTypesMap.get(r);
if(entry != null && entry.isReady()) {
entry.performFromCache(graph, provider, procedure);
return entry;
@Override
public UnaryQuery<InternalProcedure<IntSet>> getEntry(QueryProcessor provider) {
- return provider.superTypesMap.get(id);
+ return provider.cache.superTypesMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.superTypesMap.put(id, this);
+ provider.cache.superTypesMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.superTypesMap.remove(id);
+ provider.cache.superTypesMap.remove(id);
}
@Override
final static void runner(ReadGraphImpl graph, final int r, final CacheEntry parent, final QueryProcessor provider, final ListenerBase listener, final InternalProcedure<IntSet> procedure) {
- TypeHierarchy entry = (TypeHierarchy)provider.typeHierarchyMap.get(r);
+ TypeHierarchy entry = (TypeHierarchy)provider.cache.typeHierarchyMap.get(r);
if(entry == null) {
entry = new TypeHierarchy(r);
final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) {
if(parent == null && listener == null) {
- TypeHierarchy entry = (TypeHierarchy)provider.typeHierarchyMap.get(r);
+ TypeHierarchy entry = (TypeHierarchy)provider.cache.typeHierarchyMap.get(r);
if(entry != null && entry.isReady()) {
entry.performFromCache(graph, provider, procedure);
return;
@Override
public UnaryQuery<InternalProcedure<IntSet>> getEntry(QueryProcessor provider) {
- return provider.typeHierarchyMap.get(id);
+ return provider.cache.typeHierarchyMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.typeHierarchyMap.put(id, this);
+ provider.cache.typeHierarchyMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.typeHierarchyMap.remove(id);
+ provider.cache.typeHierarchyMap.remove(id);
}
@Override
}
final static Types entry(final QueryProcessor provider, final int r) {
- return (Types)provider.typesMap.get(r);
+ return (Types)provider.cache.typesMap.get(r);
}
final static void runner(ReadGraphImpl graph, final int r, final QueryProcessor provider, Types cached, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) {
- Types entry = cached != null ? cached : (Types)provider.typesMap.get(r);
+ Types entry = cached != null ? cached : (Types)provider.cache.typesMap.get(r);
if(entry == null) {
entry = new Types(r);
final static IntSet runner2(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent) throws Throwable {
- Types entry = (Types)provider.typesMap.get(r);
+ Types entry = (Types)provider.cache.typesMap.get(r);
if(entry == null) {
entry = new Types(r);
final public static void queryEach(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<IntSet> procedure) {
- final Types entry = (Types)provider.typesMap.get(r);
+ final Types entry = (Types)provider.cache.typesMap.get(r);
if(parent == null && listener == null) {
if(entry != null && entry.isReady()) {
final public static IntSet queryEach2(ReadGraphImpl graph, final int r, final QueryProcessor provider, final CacheEntry parent) throws Throwable {
if(parent == null) {
- Types entry = (Types)provider.typesMap.get(r);
+ Types entry = (Types)provider.cache.typesMap.get(r);
if(entry != null && entry.isReady()) {
return (IntSet)entry.get(graph, provider, null);
}
@Override
public UnaryQuery<InternalProcedure<IntSet>> getEntry(QueryProcessor provider) {
- return provider.typesMap.get(id);
+ return provider.cache.typesMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.typesMap.put(id, this);
+ provider.cache.typesMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.typesMap.remove(id);
+ provider.cache.typesMap.remove(id);
}
@Override
}
final static URIToResource entry(final QueryProcessor provider, final String id) {
- return (URIToResource)provider.uriToResourceMap.get(id);
+ return (URIToResource)provider.cache.uriToResourceMap.get(id);
}
final static void runner(ReadGraphImpl graph, final String id, CacheEntry parent, final ListenerBase listener, final InternalProcedure<Integer> procedure) {
QueryProcessor processor = graph.processor;
- URIToResource entry = (URIToResource)processor.uriToResourceMap.get(id);
+ URIToResource entry = (URIToResource)processor.cache.uriToResourceMap.get(id);
if(entry == null) {
entry = new URIToResource(id);
@Override
public URIToResource getEntry(QueryProcessor provider) {
- return provider.uriToResourceMap.get(id);
+ return provider.cache.uriToResourceMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.uriToResourceMap.put(id, this);
+ provider.cache.uriToResourceMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.uriToResourceMap.remove(id);
+ provider.cache.uriToResourceMap.remove(id);
}
private void lookup(ReadGraphImpl graph, final QueryProcessor processor, final InternalProcedure<Integer> procedure, final String namespace, final String name) {
}
@Override
- public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
- performFromCache(graph, (QueryProcessor)provider, (Procedure)procedure);
+ public Object performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+ return performFromCache(graph, (QueryProcessor)provider, (Procedure)procedure);
}
abstract public void recompute(ReadGraphImpl graph, QueryProcessor provider);
}
final static ValueQuery entry(final QueryProcessor provider, final int r) {
- return (ValueQuery)provider.valueMap.get(r);
+ return (ValueQuery)provider.cache.valueMap.get(r);
}
final static byte[] runner(final ReadGraphImpl graph, final int r, CacheEntry parent, final ListenerBase listener, final InternalProcedure<byte[]> procedure) {
QueryProcessor processor = graph.processor;
- ValueQuery entry = (ValueQuery)processor.valueMap.get(r);
+ ValueQuery entry = (ValueQuery)processor.cache.valueMap.get(r);
if(entry == null) {
entry = new ValueQuery(r);
@Override
public UnaryQuery<InternalProcedure<byte[]>> getEntry(QueryProcessor provider) {
- return provider.valueMap.get(id);
+ return provider.cache.valueMap.get(id);
}
@Override
public void putEntry(QueryProcessor provider) {
- provider.valueMap.put(id, this);
+ provider.cache.valueMap.put(id, this);
}
@Override
final public void removeEntry(QueryProcessor provider) {
- provider.valueMap.remove(id);
+ provider.cache.valueMap.remove(id);
}
@Override
public Set<CacheEntry> getParents(AsyncRead<?> request) {
HashSet<CacheEntry> result = new HashSet<CacheEntry>();
- CacheEntryBase entry = session.queryProvider2.asyncReadMap.get(request);
+ CacheEntryBase entry = session.queryProvider2.cache.asyncReadMap.get(request);
if(entry != null) {
for(CacheEntry parent : entry.getParents(session.queryProvider2)) result.add(parent);
}
@Override
public Set<CacheEntry> getParents(AsyncMultiRead<?> request) {
HashSet<CacheEntry> result = new HashSet<CacheEntry>();
- CacheEntryBase entry = session.queryProvider2.asyncMultiReadMap.get(request);
+ CacheEntryBase entry = session.queryProvider2.cache.asyncMultiReadMap.get(request);
if(entry != null) {
for(CacheEntry parent : entry.getParents(session.queryProvider2)) result.add(parent);
}
@Override
public Set<CacheEntry> getParents(Read<?> request) {
HashSet<CacheEntry> result = new HashSet<CacheEntry>();
- CacheEntryBase entry = session.queryProvider2.readMap.get(request);
+ CacheEntryBase entry = session.queryProvider2.cache.readMap.get(request);
if(entry != null) {
for(CacheEntry parent : entry.getParents(session.queryProvider2)) result.add(parent);
}
@Override
public Set<CacheEntry> getParents(MultiRead<?> request) {
HashSet<CacheEntry> result = new HashSet<CacheEntry>();
- CacheEntryBase entry = session.queryProvider2.multiReadMap.get(request);
+ CacheEntryBase entry = session.queryProvider2.cache.multiReadMap.get(request);
if(entry != null) {
for(CacheEntry parent : entry.getParents(session.queryProvider2)) result.add(parent);
}
* @see AsyncMultiProcedure
* @see Session
*/
-public interface AsyncMultiRead<Result> extends Request {
+public interface AsyncMultiRead<Result> {
/**
* When a <code>GraphRequest</code> is serviced by the database session
* @see AsyncProcedure
* @see Session
*/
-public interface AsyncRead<Result> extends Request {
+public interface AsyncRead<Result> {
/**
* When a <code>GraphRequest</code> is serviced by the database session
*/
void perform(AsyncReadGraph graph, AsyncProcedure<Result> procedure);
int getFlags();
+ int threadHash();
}
+++ /dev/null
-package org.simantics.db.request;
-
-public interface Request {
-
- /*
- * The integer value obtained from this method can be used to determine
- * the evaluation thread of the request.
- *
- * @return A non-negative integer value
- *
- */
- int threadHash();
-
-}
public void execute(RequestProcessor processor) throws DatabaseException {
AsyncMultiRead<Object> request = new AsyncMultiRead<Object>() {
-
- @Override
- public int threadHash() {
- return hashCode();
- }
@Override
public void perform(AsyncReadGraph graph,
QueryDebug debug = session.getService(QueryDebug.class);
class Request implements AsyncMultiRead<Object> {
-
- @Override
- public int threadHash() {
- return hashCode();
- }
@Override
public void perform(AsyncReadGraph graph, AsyncMultiProcedure<Object> callback) {