]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ValueQuery.java
Generate parts of db client query code
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ValueQuery.java
index 770a25cb93abc0e3fa75b2004efabc396da0fed2..1521d31936d8e3946addd015b62ac9ce68b77cbe 100644 (file)
  *******************************************************************************/
 package org.simantics.db.impl.query;
 
-import java.util.concurrent.Semaphore;
-
+import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.impl.graph.ReadGraphImpl;
 import org.simantics.db.impl.procedure.InternalProcedure;
-import org.simantics.db.procedure.ListenerBase;
 
 final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
     
-    private ValueQuery(final int resource) {
+    ValueQuery(final int resource) {
         super(resource);
     }
-    
-    final static ValueQuery entry(final QueryProcessor provider, final int 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.cache.valueMap.get(r); 
-        if(entry == null) {
-               
-               entry = new ValueQuery(r);
-               entry.setPending();
-               entry.clearResult(processor.querySupport);
-               entry.putEntry(processor);
-               
-               return (byte[])processor.performForEach(graph, entry, parent, listener, procedure);
-            
-        } else {
-               
-               return (byte[])processor.performForEach(graph, entry, parent, listener, procedure);
-            
-        }
-
-    }
-    
-    final public static byte[] queryEach(ReadGraphImpl graph, final int r, final CacheEntry parent, final ListenerBase listener, final InternalProcedure<byte[]> procedure) {
-        
-       assert(r != 0);
-       
-       if(graph.parent == null && listener == null) {
-               return ValueQuery.computeForEach(graph, r, null, procedure);
-        } else {
-               return runner(graph, r, parent, listener, procedure);
-        }
-         
-    }
-
-    final public static byte[] queryEach(ReadGraphImpl graph, final int r, final CacheEntry parent) {
-        
-        assert(r != 0);
-        
-        if(graph.parent == null) {
-            return ValueQuery.computeForEach(graph, r);
-        } else {
-            return runner(graph, r, parent, null, null);
-        }
-         
-    }
-    
-       @Override
-       public UnaryQuery<InternalProcedure<byte[]>> getEntry(QueryProcessor provider) {
-        return provider.cache.valueMap.get(id);
-       }
-       
-       @Override
-       public void putEntry(QueryProcessor provider) {
-        provider.cache.valueMap.put(id, this);
-       }
 
        @Override
        final public void removeEntry(QueryProcessor provider) {
-               provider.cache.valueMap.remove(id);
+               provider.cache.remove(this);
        }
-       
                
-       public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure) {
+       public static byte[] computeForEach(ReadGraphImpl graph, final int r, final ValueQuery entry, final InternalProcedure<byte[]> procedure) throws DatabaseException {
 
                graph.ensureLoaded(r);
                
@@ -115,7 +52,7 @@ final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
     }
        
        @Override
-       public Object computeForEach(ReadGraphImpl graph, final QueryProcessor queryProvider, final InternalProcedure<byte[]> procedure, final boolean store) {
+       public Object compute(ReadGraphImpl graph, final InternalProcedure<byte[]> procedure) throws DatabaseException {
                return computeForEach(graph, id, this, procedure);
     }
     
@@ -125,20 +62,17 @@ final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
     }
 
     @Override
-    public Object performFromCache(ReadGraphImpl graph, QueryProcessor queryProvider, InternalProcedure<byte[]> procedure) {
-       return computeForEach(graph, queryProvider, procedure, false);
+    public Object performFromCache(ReadGraphImpl graph, InternalProcedure<byte[]> procedure) throws DatabaseException {
+       return compute(graph, procedure);
     }
     
     @Override
-    public void recompute(ReadGraphImpl graph, QueryProcessor provider) {
-
-       final Semaphore s = new Semaphore(0);
+    public void recompute(ReadGraphImpl graph) throws DatabaseException {
        
-        computeForEach(graph, provider, new InternalProcedure<byte[]>() {
+        compute(graph,  new InternalProcedure<byte[]>() {
 
             @Override
             public void execute(ReadGraphImpl graph, byte[] result) {
-               s.release();
             }
                        
                        @Override
@@ -146,17 +80,13 @@ final public class ValueQuery extends UnaryQuery<InternalProcedure<byte[]>> {
                                throw new Error("Error in recompute.", t);
             }
 
-        }, true);
-        
-        while(!s.tryAcquire()) {
-               provider.resume(graph);
-        }
+        });
         
     }
     
     @Override
     boolean isImmutable(ReadGraphImpl graph) {
        return graph.processor.isImmutable(id);
-    }    
+    }
     
 }