X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryCacheBase.java;h=f75cd9dcd80b790727383a5d078f84f9c374c994;hb=ded784594eb0e1fb318fbb931135288152691cf2;hp=e2737f891385911bdb321139dcd7b93a45ff518c;hpb=9fcf23f51b59d737a05178832760a8dab950eb8d;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java index e2737f891..f75cd9dcd 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.concurrent.atomic.AtomicBoolean; import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ObjectResourceIdMap; import org.simantics.db.RelationInfo; import org.simantics.db.common.utils.Logger; import org.simantics.db.exception.DatabaseException; @@ -38,7 +39,8 @@ public class QueryCacheBase { public boolean collecting = false; final protected THashMap uRIToResourceMap; - final protected THashMap namespaceIndexMap; + //final protected THashMap namespaceIndexMap; + final protected UnaryQueryHashMap>> childMapMap; final protected DoubleKeyQueryHashMap objectsMap; final protected DoubleKeyQueryHashMap assertedStatementsMap; final protected DoubleKeyQueryHashMap directObjectsMap; @@ -79,7 +81,8 @@ public class QueryCacheBase { valueQueryMap = new UnaryQueryHashMap(); principalTypesMap = new UnaryQueryHashMap(); uRIToResourceMap = new THashMap(); - namespaceIndexMap = new THashMap(); + //namespaceIndexMap = new THashMap(); + childMapMap = new UnaryQueryHashMap>>(); relationInfoQueryMap = new UnaryQueryHashMap(); typeHierarchyMap = new UnaryQueryHashMap(); superTypesMap = new UnaryQueryHashMap(); @@ -373,12 +376,15 @@ public class QueryCacheBase { } - synchronized public ListenerEntry registerDependencies(ReadGraphImpl graph, CacheEntry child, CacheEntry parent, ListenerBase listener, Object procedure, boolean inferred) { + 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); + if(!child.isImmutable(graph)) { + synchronized(child) { + child.addParent(parent); + } + } } catch (DatabaseException e) { Logger.defaultLogError(e); } @@ -393,7 +399,7 @@ public class QueryCacheBase { } - public ListenerEntry registerListener(final CacheEntry entry, final ListenerBase base, final Object procedure) { + public synchronized ListenerEntry registerListener(final CacheEntry entry, final ListenerBase base, final Object procedure) { assert (entry != null); @@ -510,7 +516,8 @@ public class QueryCacheBase { realSize += directSuperRelationsMap.size(); realSize += principalTypesMap.size(); realSize += uRIToResourceMap.size(); - realSize += namespaceIndexMap.size(); + //realSize += namespaceIndexMap.size(); + realSize += childMapMap.size(); realSize += relationInfoQueryMap.size(); realSize += superTypesMap.size(); @@ -547,9 +554,11 @@ public class QueryCacheBase { for(CacheEntryBase e : uRIToResourceMap.values()) if(e.getLevel() <= level) result.add(e); - for(CacheEntryBase e : namespaceIndexMap.values()) - if(e.getLevel() <= level) - result.add(e); +// for(CacheEntryBase e : namespaceIndexMap.values()) +// if(e.getLevel() <= level) +// result.add(e); + + childMapMap.values(level, result); relationInfoQueryMap.values(level, result); superTypesMap.values(level, result); @@ -585,7 +594,8 @@ public class QueryCacheBase { entries.addAll(directSuperRelationsMap.values()); entries.addAll(principalTypesMap.values()); entries.addAll(uRIToResourceMap.values()); - entries.addAll(namespaceIndexMap.values()); + //entries.addAll(namespaceIndexMap.values()); + entries.addAll(childMapMap.values()); entries.addAll(relationInfoQueryMap.values()); entries.addAll(superTypesMap.values()); entries.addAll(superRelationsMap.values()); @@ -643,7 +653,9 @@ public class QueryCacheBase { // System.err.println("ready:"); // base.ready.printStackTrace(); // } - System.err.println("asd"); + new Exception("Timeout waiting for request to complete: " + entry.getOriginalRequest().toString()).printStackTrace(); + throw new DatabaseException("Timeout waiting for request to complete."); + //System.err.println("asd"); //base.getQuery().recompute(null, null, entry); } } catch (InterruptedException e) { @@ -796,6 +808,19 @@ public class QueryCacheBase { }; + protected static InternalProcedure> emptyChildMapProcedure = new InternalProcedure>() { + + @Override + public void execute(ReadGraphImpl graph, ObjectResourceIdMap i) { + } + + @Override + public void exception(ReadGraphImpl graph, Throwable throwable) { + } + + }; + + protected static IntProcedure emptyIntProcedure = new IntProcedure() { @@ -878,6 +903,7 @@ public class QueryCacheBase { protected static InternalProcedure emptyProcedureURIToResource = emptyIntegerProcedure; protected static InternalProcedure> emptyProcedureNamespaceIndex = emptyNamespaceProcedure; + protected static InternalProcedure> emptyProcedureChildMap = emptyChildMapProcedure; protected static InternalProcedure emptyProcedureRelationInfoQuery = emptyRelationInfoProcedure; protected static AsyncProcedure emptyProcedureReadEntry = emptyAsyncProcedure; @@ -956,11 +982,12 @@ public class QueryCacheBase { static class IntSetWrapper implements IntProcedure { private IntProcedure procedure; - private IntSet result = new IntSet(); + final private IntSet result; private Throwable throwable = null; - IntSetWrapper(IntProcedure procedure) { + IntSetWrapper(ReadGraphImpl graph, IntProcedure procedure) { this.procedure = procedure; + result = new IntSet(graph.processor.querySupport); } @Override @@ -1037,53 +1064,77 @@ public class QueryCacheBase { return wrap.get(); } - public static byte[] resultValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { - InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(procedure); + public static byte[] resultValueQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(null); QueryCache.runnerValueQuery(graph, r, parent, listener, wrap); return wrap.get(); } - public static RelationInfo resultRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { - InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(procedure); + public static RelationInfo resultRelationInfoQuery(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(null); QueryCache.runnerRelationInfoQuery(graph, r, parent, listener, wrap); return wrap.get(); } - public static IntSet resultSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { - InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(procedure); + public static IntSet resultSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(null); QueryCache.runnerSuperRelations(graph, r, parent, listener, wrap); return wrap.get(); } - public static IntSet resultSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { - InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(procedure); + public static IntSet resultSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(null); QueryCache.runnerSuperTypes(graph, r, parent, listener, wrap); return wrap.get(); } - public static IntSet resultTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { - InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(procedure); + public static IntSet resultTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(null); QueryCache.runnerTypes(graph, r, parent, listener, wrap); return wrap.get(); } - public static IntSet resultPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { - InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(procedure); + public static IntSet resultPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(null); QueryCache.runnerPredicates(graph, r, parent, listener, wrap); return wrap.get(); } - public static IntSet resultDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, InternalProcedure procedure) throws DatabaseException { - InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(procedure); + public static IntSet resultDirectPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper wrap = new InternalProcedureWrapper<>(null); QueryCache.runnerDirectPredicates(graph, r, parent, listener, wrap); return wrap.get(); } - public static IntArray resultAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, TripleIntProcedure procedure) throws DatabaseException { - TripleIntProcedureWrapper wrap = new TripleIntProcedureWrapper(procedure); + public static IntArray resultAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener) throws DatabaseException { + TripleIntProcedureWrapper wrap = new TripleIntProcedureWrapper(null); QueryCache.runnerAssertedStatements(graph, r1, r2, parent, listener, wrap); return wrap.get(); } + public static Integer resultURIToResource(ReadGraphImpl graph, String id, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper wrap = new InternalProcedureWrapper(null); + QueryCache.runnerURIToResource(graph, id, parent, listener, wrap); + return wrap.get(); + } + + public static ObjectResourceIdMap resultChildMap(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener) throws DatabaseException { + InternalProcedureWrapper> wrap = new InternalProcedureWrapper>(null); + QueryCache.runnerChildMap(graph, r, parent, listener, wrap); + return wrap.get(); + } + + static boolean shouldCache(QueryProcessor processor, int r) { + return processor.isImmutable(r); + } + + static boolean shouldCache(QueryProcessor processor, int r, int r2) { + return processor.isImmutable(r); + } + + static boolean shouldCache(QueryProcessor processor, Object o) { + return false; + } + }