]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/DirectObjects.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / DirectObjects.java
index f42a1ef31793788942db11bd041b940ee6f52ca6..2c106476ef263cf36c1a23835d7bc5fbd24152e0 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.impl.query;\r
-\r
-import java.util.Collection;\r
-import java.util.concurrent.Semaphore;\r
-\r
-import org.simantics.db.common.exception.DebugException;\r
-import org.simantics.db.impl.graph.ReadGraphImpl;\r
-import org.simantics.db.procedure.ListenerBase;\r
-import org.simantics.db.request.RequestFlags;\r
-\r
-final public class DirectObjects extends CollectionBinaryQuery<IntProcedure> {\r
-\r
-       private DirectObjects(final int r1, final int r2) {\r
-               super(r1, r2);\r
-       }\r
-\r
-       @Override\r
-       public int type() {\r
-               return RequestFlags.INVALIDATE;\r
-       }\r
-       \r
-    @Override\r
-    public void clearResult(QuerySupport support) {\r
-       setResult(INVALID_RESULT);\r
-    }\r
-\r
-       final static DirectObjects entry(final QueryProcessor provider, final int r1, final int r2) {\r
-\r
-               return (DirectObjects)provider.directObjectsMap.get(id(r1,r2));\r
-\r
-       }\r
-       \r
-       final static Collection<DirectObjects> entries(final QueryProcessor processor, final int r1) {\r
-               DoubleKeyQueryHashMap<IntProcedure> hash = processor.directObjectsMap;\r
-               return hash.values(r1);\r
-       }\r
-\r
-       final static void runner(ReadGraphImpl graph, final int r1, final int r2, CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {\r
-\r
-       QueryProcessor processor = graph.processor;\r
-               \r
-               DirectObjects entry = (DirectObjects)processor.directObjectsMap.get(id(r1,r2));\r
-               if(entry == null) {\r
-                       \r
-               entry = new DirectObjects(r1, r2);\r
-               entry.setPending();\r
-               entry.clearResult(processor.querySupport);\r
-               entry.putEntry(processor);\r
-               \r
-                       processor.performForEach(graph, entry, parent, listener, procedure);\r
-                       \r
-               } else {\r
-                       \r
-            if(entry.isPending()) {\r
-                synchronized(entry) {\r
-                    if(entry.isPending()) {\r
-                        processor.registerDependencies(graph, entry, parent, listener, procedure, false);\r
-                                               entry.computeForEach(graph, processor, procedure, true);\r
-                        return;\r
-                    }\r
-                }\r
-            }\r
-               \r
-                       processor.performForEach(graph, entry, parent, listener, procedure);\r
-                       \r
-               }\r
-\r
-       }\r
-\r
-       final public static void queryEach(ReadGraphImpl graph, final int r1, final int r2, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {\r
-\r
-        assert(r1 != 0);\r
-        assert(r2 != 0);\r
-        \r
-        if(parent == null && listener == null) {\r
-               DirectObjects.computeForEach(graph, r1, r2, null, procedure);\r
-        } else {\r
-               runner(graph, r1, r2, parent, listener, procedure);\r
-        }\r
-\r
-       }\r
-\r
-       @Override\r
-       public BinaryQuery<IntProcedure> getEntry(QueryProcessor provider) {\r
-               return provider.directObjectsMap.get(id);\r
-       }\r
-\r
-       @Override\r
-       public void putEntry(QueryProcessor provider) {\r
-               provider.directObjectsMap.put(id, this);\r
-       }\r
-\r
-       @Override\r
-       final public void removeEntry(QueryProcessor provider) {\r
-               provider.directObjectsMap.remove(id);\r
-       }\r
-\r
-       @Override\r
-       public void computeForEach(ReadGraphImpl graph, final QueryProcessor queryProvider, final IntProcedure procedure, final boolean store) {\r
-               computeForEach(graph, r1(), r2(), this, procedure);\r
-       }\r
-\r
-       static public void computeForEach(ReadGraphImpl graph, int r1, int r2, final DirectObjects entry, final IntProcedure procedure) {\r
-\r
-               QueryProcessor processor = graph.processor;\r
-               \r
-               processor.querySupport.ensureLoaded(graph, r1, r2);\r
-\r
-               processor.querySupport.getObjects(graph, r1, r2, new IntProcedure() {\r
-\r
-                       @Override\r
-                       public void execute(ReadGraphImpl graph, int i) {\r
-                               procedure.execute(graph, i);\r
-                       }\r
-\r
-                       @Override\r
-                       public void finished(ReadGraphImpl graph) {\r
-                       }\r
-\r
-                       @Override\r
-                       public void exception(ReadGraphImpl graph, Throwable t) {\r
-                               if(DebugException.DEBUG) new DebugException(t).printStackTrace();\r
-                       }\r
-\r
-               });\r
-\r
-               if(entry != null) entry.finish(graph, processor);\r
-               procedure.finished(graph);\r
-\r
-       }\r
-\r
-       @Override\r
-       public String toString() {\r
-               return "DirectObjects[" + r1() + " - " + r2() + "]";\r
-       }\r
-\r
-       @Override\r
-       public void setReady() {\r
-               statusOrException = READY;\r
-       }\r
-       \r
-       final private void finish(ReadGraphImpl graph, QueryProcessor provider) {\r
-               setReady();\r
-       }\r
-\r
-       @Override\r
-       public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, IntProcedure procedure) {\r
-\r
-               assert(isReady());\r
-               computeForEach(graph, provider, procedure, false);\r
-\r
-       }\r
-\r
-       @Override\r
-       public void recompute(ReadGraphImpl graph, QueryProcessor provider) {\r
-\r
-        final Semaphore s = new Semaphore(0);\r
-               \r
-               computeForEach(graph, provider, new IntProcedure() {\r
-\r
-                       @Override\r
-                       public void finished(ReadGraphImpl graph) {\r
-                               s.release();\r
-                       }\r
-\r
-                       @Override\r
-                       public void exception(ReadGraphImpl graph, Throwable t) {\r
-                               throw new Error("Error in recompute.", t);\r
-                       }\r
-\r
-                       @Override\r
-                       public void execute(ReadGraphImpl graphd, int i) {\r
-                       }\r
-\r
-               }, true);\r
-\r
-        while(!s.tryAcquire()) {\r
-               provider.resume(graph);\r
-        }\r
-\r
-       }\r
-\r
-    @Override\r
-    boolean isImmutable(ReadGraphImpl graph) {\r
-       return graph.processor.isImmutable(r1());\r
-    }\r
-       \r
-}\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.impl.query;
+
+import java.util.Collection;
+import java.util.concurrent.Semaphore;
+
+import org.simantics.db.common.exception.DebugException;
+import org.simantics.db.impl.graph.ReadGraphImpl;
+import org.simantics.db.procedure.ListenerBase;
+import org.simantics.db.request.RequestFlags;
+
+final public class DirectObjects extends CollectionBinaryQuery<IntProcedure> {
+
+       private DirectObjects(final int r1, final int r2) {
+               super(r1, r2);
+       }
+
+       @Override
+       public int type() {
+               return RequestFlags.INVALIDATE;
+       }
+       
+    @Override
+    public void clearResult(QuerySupport support) {
+       setResult(INVALID_RESULT);
+    }
+
+       final static DirectObjects entry(final QueryProcessor provider, final int r1, final int r2) {
+
+               return (DirectObjects)provider.directObjectsMap.get(id(r1,r2));
+
+       }
+       
+       final static Collection<DirectObjects> entries(final QueryProcessor processor, final int r1) {
+               DoubleKeyQueryHashMap<IntProcedure> hash = processor.directObjectsMap;
+               return hash.values(r1);
+       }
+
+       final static void runner(ReadGraphImpl graph, final int r1, final int r2, CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {
+
+       QueryProcessor processor = graph.processor;
+               
+               DirectObjects entry = (DirectObjects)processor.directObjectsMap.get(id(r1,r2));
+               if(entry == null) {
+                       
+               entry = new DirectObjects(r1, r2);
+               entry.setPending();
+               entry.clearResult(processor.querySupport);
+               entry.putEntry(processor);
+               
+                       processor.performForEach(graph, entry, parent, listener, procedure);
+                       
+               } else {
+                       
+            if(entry.isPending()) {
+                synchronized(entry) {
+                    if(entry.isPending()) {
+                        processor.registerDependencies(graph, entry, parent, listener, procedure, false);
+                                               entry.computeForEach(graph, processor, procedure, true);
+                        return;
+                    }
+                }
+            }
+               
+                       processor.performForEach(graph, entry, parent, listener, procedure);
+                       
+               }
+
+       }
+
+       final public static void queryEach(ReadGraphImpl graph, final int r1, final int r2, final QueryProcessor provider, final CacheEntry parent, final ListenerBase listener, final IntProcedure procedure) {
+
+        assert(r1 != 0);
+        assert(r2 != 0);
+        
+        if(parent == null && listener == null) {
+               DirectObjects.computeForEach(graph, r1, r2, null, procedure);
+        } else {
+               runner(graph, r1, r2, parent, listener, procedure);
+        }
+
+       }
+
+       @Override
+       public BinaryQuery<IntProcedure> getEntry(QueryProcessor provider) {
+               return provider.directObjectsMap.get(id);
+       }
+
+       @Override
+       public void putEntry(QueryProcessor provider) {
+               provider.directObjectsMap.put(id, this);
+       }
+
+       @Override
+       final public void removeEntry(QueryProcessor provider) {
+               provider.directObjectsMap.remove(id);
+       }
+
+       @Override
+       public void computeForEach(ReadGraphImpl graph, final QueryProcessor queryProvider, final IntProcedure procedure, final boolean store) {
+               computeForEach(graph, r1(), r2(), this, procedure);
+       }
+
+       static public void computeForEach(ReadGraphImpl graph, int r1, int r2, final DirectObjects entry, final IntProcedure procedure) {
+
+               QueryProcessor processor = graph.processor;
+               
+               processor.querySupport.ensureLoaded(graph, r1, r2);
+
+               processor.querySupport.getObjects(graph, r1, r2, new IntProcedure() {
+
+                       @Override
+                       public void execute(ReadGraphImpl graph, int i) {
+                               procedure.execute(graph, i);
+                       }
+
+                       @Override
+                       public void finished(ReadGraphImpl graph) {
+                       }
+
+                       @Override
+                       public void exception(ReadGraphImpl graph, Throwable t) {
+                               if(DebugException.DEBUG) new DebugException(t).printStackTrace();
+                       }
+
+               });
+
+               if(entry != null) entry.finish(graph, processor);
+               procedure.finished(graph);
+
+       }
+
+       @Override
+       public String toString() {
+               return "DirectObjects[" + r1() + " - " + r2() + "]";
+       }
+
+       @Override
+       public void setReady() {
+               statusOrException = READY;
+       }
+       
+       final private void finish(ReadGraphImpl graph, QueryProcessor provider) {
+               setReady();
+       }
+
+       @Override
+       public void performFromCache(ReadGraphImpl graph, QueryProcessor provider, IntProcedure procedure) {
+
+               assert(isReady());
+               computeForEach(graph, provider, procedure, false);
+
+       }
+
+       @Override
+       public void recompute(ReadGraphImpl graph, QueryProcessor provider) {
+
+        final Semaphore s = new Semaphore(0);
+               
+               computeForEach(graph, provider, new IntProcedure() {
+
+                       @Override
+                       public void finished(ReadGraphImpl graph) {
+                               s.release();
+                       }
+
+                       @Override
+                       public void exception(ReadGraphImpl graph, Throwable t) {
+                               throw new Error("Error in recompute.", t);
+                       }
+
+                       @Override
+                       public void execute(ReadGraphImpl graphd, int i) {
+                       }
+
+               }, true);
+
+        while(!s.tryAcquire()) {
+               provider.resume(graph);
+        }
+
+       }
+
+    @Override
+    boolean isImmutable(ReadGraphImpl graph) {
+       return graph.processor.isImmutable(r1());
+    }
+       
+}
+