]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/NamespaceIndex.java
Merge remote-tracking branch 'origin/master' into private/db-threads
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / NamespaceIndex.java
index e55e99c6117bd1bf296c6f90a7b31f558ea7be51..884f3f6d4e7ad37c0a124486a50f26173cefda37 100644 (file)
@@ -33,32 +33,30 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
                provider.cache.remove(this);
        }
        
-       final private void index(ReadGraphImpl graph, final QueryProcessor provider, int root, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+       final static private void index(ReadGraphImpl graph, int root, NamespaceIndex entry, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
                
                if(root == 0) {
-            add2(graph, null);
+                       if(entry != null)
+                               entry.add2(graph, null);
             procedure.execute(graph, null);
 //            System.err.println("NamespaceIndex[" + id + "]->null");
             return;
                }
 
-               final int consistsOf = provider.getConsistsOf();
-               final int hasName = provider.getHasName();
+               QueryProcessor processor = graph.processor;
+               
+               final int consistsOf = processor.getConsistsOf();
+               final int hasName = processor.getHasName();
         
         final TObjectIntHashMap<String> result = new TObjectIntHashMap<String>();
         
-        QueryCache.runnerObjects(graph, root, consistsOf, graph.parent, null, new SyncIntProcedure() {
+        QueryCache.runnerObjects(graph, root, consistsOf, entry, null, new SyncIntProcedure() {
                
                @Override
                        public void run(ReadGraphImpl graph) throws DatabaseException {
                        
-                       if(isPending()) { 
-                    add2(graph, result);
-                    procedure.execute(graph, result);
-//                    System.err.println("NamespaceIndex[" + id + "]->" + result.size());
-                       } else {
-                               procedure.exception(graph, (Throwable)statusOrException);
-                       }
+                       if(entry != null) entry.add2(graph, result);
+                       procedure.execute(graph, result);
                                
                        }
 
@@ -74,14 +72,14 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
 
                        inc();
                        
-                       QueryCache.runnerObjects(graph, obj, hasName, graph.parent, null, new IntProcedure() {
+                       QueryCache.runnerObjects(graph, obj, hasName, entry, null, new IntProcedure() {
                        
                        @Override
                        public void execute(ReadGraphImpl graph, int i) throws DatabaseException {
 
                                inc();
 
-                               QueryCache.runnerValueQuery(graph, i, NamespaceIndex.this, null, new InternalProcedure<byte[]>() {
+                               QueryCache.runnerValueQuery(graph, i, entry, null, new InternalProcedure<byte[]>() {
                                        
                                        @Override
                                        public void execute(ReadGraphImpl graph, byte[] value) throws DatabaseException {
@@ -112,7 +110,7 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
                                        
                                        @Override
                                        public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
-                                                       except(t);
+                                                       if(entry != null) entry.except(t);
                                                dec(graph);
                             }
 
@@ -127,7 +125,7 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
                                
                                @Override
                                public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
-                                               except(t);
+                                       if(entry != null) entry.except(t);
                         dec(graph);
                     }
 
@@ -139,27 +137,33 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
         
     }
 
+       
     @Override
        public Object compute(ReadGraphImpl graph, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
+               computeForEach(graph, id, this, procedure);
+               return getResult();
+    }
+
+       public static void computeForEach(ReadGraphImpl graph, final String id, final NamespaceIndex entry, final InternalProcedure<TObjectIntHashMap<String>> procedure) throws DatabaseException {
        
        QueryProcessor processor = graph.processor;
        
 //     System.err.println("NamespaceIndex " + id);
        
         if("http://".equals(id) || "http:/".equals(id)) {
-            index(graph, processor, processor.getRootLibrary(), procedure);
+            index(graph, processor.getRootLibrary(), entry, procedure);
         } else {
             final String[] parts = URIStringUtils.splitURI(id);
             if(parts != null) {
-                QueryCache.runnerNamespaceIndex(graph, parts[0], this, null, new InternalProcedure<TObjectIntHashMap<String>>() {
+                QueryCache.runnerNamespaceIndex(graph, parts[0], entry, null, new InternalProcedure<TObjectIntHashMap<String>>() {
     
                     @Override
                     public void execute(ReadGraphImpl graph, TObjectIntHashMap<String> index) throws DatabaseException {
     
                         if(index != null) {
-                            index(graph, processor, index.get(parts[1]), procedure);
+                            index(graph, index.get(parts[1]), entry, procedure);
                         } else {
-                            add2(graph, null);
+                            if(entry != null) entry.add2(graph, null);
                             procedure.execute(graph, null);
 //                            System.err.println("NamespaceIndex[" + id + "]->null");
                         }
@@ -169,21 +173,19 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
                     @Override
                     public void exception(ReadGraphImpl graph, Throwable t) throws DatabaseException {
                         if(DebugException.DEBUG) new DebugException(t).printStackTrace();
-                        except(t);
+                        if(entry != null) entry.except(t);
                         procedure.exception(graph, t);
                     }
     
                 });
             } else {
-                add2(graph, null);
+                if(entry != null) entry.add2(graph, null);
                 procedure.execute(graph, null);
 //                System.err.println("NamespaceIndex[" + id + "]->null");
             }
 
         }
         
-        return getResult();
-        
     }
 
     @Override
@@ -191,12 +193,6 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
        return "NamespaceIndex[" + id + "]";
     }
 
-    synchronized private void add(TObjectIntHashMap<String> result) {
-       
-       throw new Error("Not possible!");
-       
-    }
-
     private void add2(ReadGraphImpl graph, TObjectIntHashMap<String> result) {
        
        if(!isPending()) {
@@ -205,22 +201,12 @@ final public class NamespaceIndex extends StringQuery<InternalProcedure<TObjectI
        
        assert(isPending());
 
-//        ArrayList<InternalProcedure<TObjectIntHashMap<String>>> p = null;
-
         synchronized(this) {
 
             setResult(result);
                setReady();
-//            p = procs;
-//            procs = null; 
         
         }
-        
-//        if(p != null) {
-//        
-//             for(InternalProcedure<TObjectIntHashMap<String>> proc : p) proc.execute(graph, result);
-//             
-//        }
        
     }