]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCacheBase.java
Separate query dependency management from QueryProcessor
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / QueryCacheBase.java
index 446e9c641406464de62e4cb484c66d02df4ca70f..54efda83976d8255f549ec0cd1cf41df8fc07e6c 100644 (file)
@@ -70,8 +70,6 @@ public class QueryCacheBase {
        protected final StableHashMap<AsyncMultiRead, AsyncMultiReadEntry>        asyncMultiReadEntryMap; 
        protected final StableHashMap<ExternalRead, ExternalReadEntry>            externalReadEntryMap; 
 
-       final THashMap<CacheEntry, ArrayList<ListenerEntry>>                      listeners;
-
        public final QuerySupport                                                 querySupport;
 
        public QueryCacheBase(QuerySupport querySupport, int threads) {
@@ -104,91 +102,8 @@ public class QueryCacheBase {
                asyncMultiReadEntryMap = new StableHashMap<AsyncMultiRead, AsyncMultiReadEntry>(); 
                multiReadEntryMap = new StableHashMap<MultiRead, MultiReadEntry>(); 
                externalReadEntryMap = new StableHashMap<ExternalRead, ExternalReadEntry>(); 
-               listeners = new THashMap<CacheEntry, ArrayList<ListenerEntry>>(10, 0.75f);
        }
 
-//     public <T> Object performQuery(ReadGraphImpl parentGraph, final AsyncRead<T> query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException {
-//
-//             AsyncReadEntry<T> entry = (AsyncReadEntry<T>)entry_;
-//             AsyncProcedure<T> procedure = (AsyncProcedure<T>)procedure_;
-//
-//             ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
-//
-//             try {
-//                     
-//                     query.perform(queryGraph, new AsyncProcedure<T>() {
-//
-//                             @Override
-//                             public void execute(AsyncReadGraph returnGraph, T result) {
-//                                     ReadGraphImpl impl = (ReadGraphImpl)returnGraph;
-//                                     entry.addOrSet(parentGraph, 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;
-//             
-//     }
-
-//     public <T> Object performQuery(ReadGraphImpl parentGraph, final Read<T> query, final CacheEntryBase entry_, AsyncProcedure procedure_) throws DatabaseException {
-//
-//             ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
-//
-//             ReadEntry entry = (ReadEntry)entry_;
-//
-//             try {
-//
-//                     T result = (T)query.perform(queryGraph);
-//                     entry.addOrSet(queryGraph, result);
-//
-//                     return (T)entry.get(parentGraph, procedure_);
-//
-//             }  catch (Throwable t) {
-//
-//                     entry.except(t);
-//                     return (T)entry.get(parentGraph, procedure_);
-//
-//             }
-//             
-//     }
-
-
        public <T> Object performQuery(ReadGraphImpl parentGraph, final AsyncMultiRead<T> query, final CacheEntryBase entry_, Object procedure_) throws DatabaseException {
 
                ReadGraphImpl queryGraph = parentGraph.withParent(entry_);
@@ -315,82 +230,6 @@ public class QueryCacheBase {
                
        }
        
-       public ListenerEntry registerDependencies(ReadGraphImpl graph, CacheEntry child, CacheEntry parent, ListenerBase listener, Object procedure, boolean inferred) {
-
-               if (parent != null && !inferred) {
-                       try {
-                               if(!child.isImmutable(graph)) {
-                                       synchronized(child) {
-                                               child.addParent(parent);
-                                       }
-                               }
-                       } catch (DatabaseException e) {
-                               Logger.defaultLogError(e);
-                       }
-                       if (Development.DEVELOPMENT) {
-                               if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_DEPENDENCIES, Bindings.BOOLEAN)) {
-                                       System.err.println(child + " -> " + parent);
-                               }
-                       }
-               }
-
-               if (listener != null) {
-                       return registerListener(child, listener, procedure);
-               } else {
-                       return null;
-               }
-
-       }
-       
-       public synchronized ListenerEntry registerListener(final CacheEntry entry, final ListenerBase base, final Object procedure) {
-
-               assert (entry != null);
-
-               if (base.isDisposed())
-                       return null;
-
-               return addListener(entry, base, procedure);
-
-       }
-
-       protected 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 (Development.DEVELOPMENT) {
-                       if(Development.<Boolean>getProperty(DevelopmentKeys.QUERYPROCESSOR_LISTENERS, Bindings.BOOLEAN)) {
-                               new Exception().printStackTrace();
-                               System.err.println("addListener -> " + list.size() + " " + entry + " " + base + " " + procedure);
-                       }
-               }
-
-               return result;
-
-       }
-       
-       
        public Collection<CacheEntry> getRootList() {
 
                ArrayList<CacheEntry> result = new ArrayList<CacheEntry>();