X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryCache.java;h=7b591abb7fd80e062308ce3df88c86e872cfe27e;hb=8b6de499c9c1bad0e72631719fd165ce39d6ad56;hp=38ed21026f9ff2bbcbc70d7936f0aca30e7fc497;hpb=a6c431919eb2ef9a06623cf0b9daa1fd5a04669c;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java index 38ed21026..7b591abb7 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCache.java @@ -10,14 +10,13 @@ import org.simantics.db.impl.query.QueryProcessor.SessionTask; import org.simantics.db.procedure.AsyncMultiProcedure; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.db.procedure.ListenerBase; +import org.simantics.db.procedure.SyncMultiProcedure; 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.TObjectIntHashMap; - public class QueryCache extends QueryCacheBase { public QueryCache(QuerySupport querySupport, int threads) { @@ -674,15 +673,15 @@ public class QueryCache extends QueryCacheBase { } } - AssertedStatements getOrCreateAssertedStatements(QueryProcessor processor, int r1, int r2) throws DatabaseException { - AssertedStatements existing = null; - synchronized(assertedStatementsMap) { - existing = (AssertedStatements)assertedStatementsMap.get(r1,r2); + TypeHierarchy getOrCreateTypeHierarchy(QueryProcessor processor, int r) throws DatabaseException { + TypeHierarchy existing = null; + synchronized(typeHierarchyMap) { + existing = (TypeHierarchy)typeHierarchyMap.get(r); if(existing == null) { - existing = new AssertedStatements(r1,r2); + existing = new TypeHierarchy(r); existing.clearResult(querySupport); existing.setPending(); - assertedStatementsMap.put(keyR2(r1,r2), existing); + typeHierarchyMap.put(keyR(r), existing); size++; return existing; } @@ -695,34 +694,38 @@ public class QueryCache extends QueryCacheBase { return existing; } - void remove(AssertedStatements entry) { - synchronized(assertedStatementsMap) { - assertedStatementsMap.remove(entry.id); + void remove(TypeHierarchy entry) { + synchronized(typeHierarchyMap) { + typeHierarchyMap.remove(entry.id); } } - public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException { + public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph.processor, r1,r2); - TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements; + if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + TypeHierarchy.computeForEach(graph, r, null, procedure); + return; + } + TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph.processor, r); + InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - entry.compute(graph, procedure_); + TypeHierarchy.computeForEach(graph, r, entry, procedure_); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - AssertedPredicates getOrCreateAssertedPredicates(QueryProcessor processor, int r) throws DatabaseException { - AssertedPredicates existing = null; - synchronized(assertedPredicatesMap) { - existing = (AssertedPredicates)assertedPredicatesMap.get(r); + SuperTypes getOrCreateSuperTypes(QueryProcessor processor, int r) throws DatabaseException { + SuperTypes existing = null; + synchronized(superTypesMap) { + existing = (SuperTypes)superTypesMap.get(r); if(existing == null) { - existing = new AssertedPredicates(r); + existing = new SuperTypes(r); existing.clearResult(querySupport); existing.setPending(); - assertedPredicatesMap.put(keyR(r), existing); + superTypesMap.put(keyR(r), existing); size++; return existing; } @@ -735,34 +738,38 @@ public class QueryCache extends QueryCacheBase { return existing; } - void remove(AssertedPredicates entry) { - synchronized(assertedPredicatesMap) { - assertedPredicatesMap.remove(entry.id); + void remove(SuperTypes entry) { + synchronized(superTypesMap) { + superTypesMap.remove(entry.id); } } - public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { + public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph.processor, r); - IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates; + if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + SuperTypes.computeForEach(graph, r, null, procedure); + return; + } + SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph.processor, r); + InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - entry.compute(graph, procedure_); + SuperTypes.computeForEach(graph, r, entry, procedure_); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - DirectSuperRelations getOrCreateDirectSuperRelations(QueryProcessor processor, int r) throws DatabaseException { - DirectSuperRelations existing = null; - synchronized(directSuperRelationsMap) { - existing = (DirectSuperRelations)directSuperRelationsMap.get(r); + SuperRelations getOrCreateSuperRelations(QueryProcessor processor, int r) throws DatabaseException { + SuperRelations existing = null; + synchronized(superRelationsMap) { + existing = (SuperRelations)superRelationsMap.get(r); if(existing == null) { - existing = new DirectSuperRelations(r); + existing = new SuperRelations(r); existing.clearResult(querySupport); existing.setPending(); - directSuperRelationsMap.put(keyR(r), existing); + superRelationsMap.put(keyR(r), existing); size++; return existing; } @@ -775,34 +782,38 @@ public class QueryCache extends QueryCacheBase { return existing; } - void remove(DirectSuperRelations entry) { - synchronized(directSuperRelationsMap) { - directSuperRelationsMap.remove(entry.id); + void remove(SuperRelations entry) { + synchronized(superRelationsMap) { + superRelationsMap.remove(entry.id); } } - public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { + public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph.processor, r); - IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations; + if(parent == null && listener == null && !cache.shouldCache(graph.processor, r)) { + SuperRelations.computeForEach(graph, r, null, procedure); + return; + } + SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph.processor, r); + InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { assert(entry.isPending()); - entry.compute(graph, procedure_); + SuperRelations.computeForEach(graph, r, entry, procedure_); if(listenerEntry != null) cache.primeListenerEntry(listenerEntry, entry.getResult()); } } - SuperTypes getOrCreateSuperTypes(QueryProcessor processor, int r) throws DatabaseException { - SuperTypes existing = null; - synchronized(superTypesMap) { - existing = (SuperTypes)superTypesMap.get(r); + AssertedPredicates getOrCreateAssertedPredicates(QueryProcessor processor, int r) throws DatabaseException { + AssertedPredicates existing = null; + synchronized(assertedPredicatesMap) { + existing = (AssertedPredicates)assertedPredicatesMap.get(r); if(existing == null) { - existing = new SuperTypes(r); + existing = new AssertedPredicates(r); existing.clearResult(querySupport); existing.setPending(); - superTypesMap.put(keyR(r), existing); + assertedPredicatesMap.put(keyR(r), existing); size++; return existing; } @@ -815,16 +826,16 @@ public class QueryCache extends QueryCacheBase { return existing; } - void remove(SuperTypes entry) { - synchronized(superTypesMap) { - superTypesMap.remove(entry.id); + void remove(AssertedPredicates entry) { + synchronized(assertedPredicatesMap) { + assertedPredicatesMap.remove(entry.id); } } - public static void runnerSuperTypes(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { + public static void runnerAssertedPredicates(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - SuperTypes entry = (SuperTypes)cache.getOrCreateSuperTypes(graph.processor, r); - InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureSuperTypes; + AssertedPredicates entry = (AssertedPredicates)cache.getOrCreateAssertedPredicates(graph.processor, r); + IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedPredicates; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { @@ -834,15 +845,15 @@ public class QueryCache extends QueryCacheBase { } } - TypeHierarchy getOrCreateTypeHierarchy(QueryProcessor processor, int r) throws DatabaseException { - TypeHierarchy existing = null; - synchronized(typeHierarchyMap) { - existing = (TypeHierarchy)typeHierarchyMap.get(r); + AssertedStatements getOrCreateAssertedStatements(QueryProcessor processor, int r1, int r2) throws DatabaseException { + AssertedStatements existing = null; + synchronized(assertedStatementsMap) { + existing = (AssertedStatements)assertedStatementsMap.get(r1,r2); if(existing == null) { - existing = new TypeHierarchy(r); + existing = new AssertedStatements(r1,r2); existing.clearResult(querySupport); existing.setPending(); - typeHierarchyMap.put(keyR(r), existing); + assertedStatementsMap.put(keyR2(r1,r2), existing); size++; return existing; } @@ -855,16 +866,16 @@ public class QueryCache extends QueryCacheBase { return existing; } - void remove(TypeHierarchy entry) { - synchronized(typeHierarchyMap) { - typeHierarchyMap.remove(entry.id); + void remove(AssertedStatements entry) { + synchronized(assertedStatementsMap) { + assertedStatementsMap.remove(entry.id); } } - public static void runnerTypeHierarchy(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { + public static void runnerAssertedStatements(ReadGraphImpl graph, int r1, int r2, CacheEntry parent, ListenerBase listener, final TripleIntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - TypeHierarchy entry = (TypeHierarchy)cache.getOrCreateTypeHierarchy(graph.processor, r); - InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureTypeHierarchy; + AssertedStatements entry = (AssertedStatements)cache.getOrCreateAssertedStatements(graph.processor, r1,r2); + TripleIntProcedure procedure_ = procedure != null ? procedure : emptyProcedureAssertedStatements; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { @@ -874,15 +885,15 @@ public class QueryCache extends QueryCacheBase { } } - SuperRelations getOrCreateSuperRelations(QueryProcessor processor, int r) throws DatabaseException { - SuperRelations existing = null; - synchronized(superRelationsMap) { - existing = (SuperRelations)superRelationsMap.get(r); + DirectSuperRelations getOrCreateDirectSuperRelations(QueryProcessor processor, int r) throws DatabaseException { + DirectSuperRelations existing = null; + synchronized(directSuperRelationsMap) { + existing = (DirectSuperRelations)directSuperRelationsMap.get(r); if(existing == null) { - existing = new SuperRelations(r); + existing = new DirectSuperRelations(r); existing.clearResult(querySupport); existing.setPending(); - superRelationsMap.put(keyR(r), existing); + directSuperRelationsMap.put(keyR(r), existing); size++; return existing; } @@ -895,16 +906,16 @@ public class QueryCache extends QueryCacheBase { return existing; } - void remove(SuperRelations entry) { - synchronized(superRelationsMap) { - superRelationsMap.remove(entry.id); + void remove(DirectSuperRelations entry) { + synchronized(directSuperRelationsMap) { + directSuperRelationsMap.remove(entry.id); } } - public static void runnerSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final InternalProcedure procedure) throws DatabaseException { + public static void runnerDirectSuperRelations(ReadGraphImpl graph, int r, CacheEntry parent, ListenerBase listener, final IntProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; - SuperRelations entry = (SuperRelations)cache.getOrCreateSuperRelations(graph.processor, r); - InternalProcedure procedure_ = procedure != null ? procedure : emptyProcedureSuperRelations; + DirectSuperRelations entry = (DirectSuperRelations)cache.getOrCreateDirectSuperRelations(graph.processor, r); + IntProcedure procedure_ = procedure != null ? procedure : emptyProcedureDirectSuperRelations; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else { @@ -941,10 +952,10 @@ public class QueryCache extends QueryCacheBase { } } - public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead r, CacheEntry parent, ListenerBase listener, final AsyncMultiProcedure procedure) throws DatabaseException { + public static void runnerMultiReadEntry(ReadGraphImpl graph, MultiRead r, CacheEntry parent, ListenerBase listener, final SyncMultiProcedure procedure) throws DatabaseException { QueryCache cache = graph.processor.cache; MultiReadEntry entry = (MultiReadEntry)cache.getOrCreateMultiReadEntry(graph.processor, r); - AsyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry; + SyncMultiProcedure procedure_ = procedure != null ? procedure : emptyProcedureMultiReadEntry; ListenerEntry listenerEntry = cache.registerDependencies(graph, entry, parent, listener, procedure_, false); if(entry.isReady()) entry.performFromCache(graph, procedure_); else {