]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / AsyncReadEntry.java
index 6f681056dd07bea4e755900906af540bcb88772d..010f554463373ace1edf3ac21cef13a4cc17122a 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.ArrayList;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.impl.DebugPolicy;\r
-import org.simantics.db.impl.graph.ReadGraphImpl;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.db.request.AsyncRead;\r
-\r
-final public class AsyncReadEntry<T> extends CacheEntryBase {\r
-\r
-    protected AsyncRead<T> request;\r
-\r
-    public AsyncReadEntry(AsyncRead<T> request) {\r
-       this.request = request;\r
-       if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: created " + this);\r
-    }\r
-\r
-    @Override\r
-    int makeHash() {\r
-       return request.hashCode();\r
-    }\r
-    \r
-    @Override\r
-    public Object getOriginalRequest() {\r
-        return request;\r
-    }\r
-    \r
-    @Override\r
-    public void discard() {\r
-       super.discard();\r
-       //request = null;\r
-       setResult(null);\r
-    }\r
-    \r
-    final public void addOrSet(AsyncReadGraph graph, Object item) {\r
-\r
-       assert(isPending());\r
-        \r
-//        ArrayList<AsyncProcedure<T>> p = null;\r
-\r
-        synchronized(this) {\r
-               \r
-            setResult(item);\r
-               setReady();\r
-//            p = procs;\r
-//            procs = null;\r
-            \r
-        }\r
-\r
-//        if(p != null)\r
-//            for(AsyncProcedure<T> proc : p) {\r
-//             proc.execute(graph, (T)item);\r
-////                proc.first.execute(graph, (T)item);\r
-////                proc.second.dec();\r
-//            }\r
-        \r
-    }\r
-    \r
-    \r
-    public void except(AsyncReadGraph graph, Throwable t) {\r
-       \r
-       assert(isPending());\r
-        \r
-//        ArrayList<AsyncProcedure<T>> p = null;\r
-\r
-        synchronized(this) {\r
-               \r
-            except(t);\r
-////            p = procs;\r
-//            procs = null;\r
-            \r
-        }\r
-\r
-//        if(p != null)\r
-//            for(AsyncProcedure<T> proc : p) {\r
-//             proc.exception(graph, t);\r
-//            }\r
-       \r
-    }\r
-    \r
-    \r
-    @Override\r
-    final public Query getQuery() {\r
-       \r
-        return new Query() {\r
-\r
-                       @Override\r
-                       public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) {\r
-                               \r
-                               QueryProcessor qp = (QueryProcessor)provider;\r
-\r
-                               final ReadGraphImpl parentGraph = ReadGraphImpl.forRecompute(entry, qp); \r
-\r
-                               try {\r
-\r
-                                   request.perform(parentGraph , new AsyncProcedure<T>() {\r
-\r
-                        @Override\r
-                        public void execute(AsyncReadGraph graph, T result) {\r
-                            addOrSet(graph, result);\r
-                        }\r
-                               \r
-                               @Override\r
-                               public void exception(AsyncReadGraph graph, Throwable t) {\r
-                                   except(t);\r
-                        }\r
-\r
-                    });\r
-\r
-                               } catch (Throwable t) {\r
-                                   except(t);\r
-                }\r
-                               \r
-                       }\r
-\r
-                       @Override\r
-                       public void removeEntry(QueryProcessor qp) {\r
-                       qp.asyncReadMap.remove(request);\r
-                       }\r
-\r
-                       @Override\r
-                       public int type() {\r
-                               return request.getFlags();\r
-                       }\r
-                       \r
-                       @Override\r
-                       public String toString() {\r
-                               if(request == null) return "DISCARDED";\r
-                               else if(isExcepted()) return request.toString() + " " + getResult();\r
-                               else return request.toString() + " " + statusOrException;\r
-                       }\r
-               \r
-        };\r
-        \r
-    }\r
-\r
-       public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {\r
-               \r
-        AsyncProcedure<T> proc = (AsyncProcedure<T>)procedure;\r
-\r
-           if(isExcepted()) {\r
-            \r
-            try {\r
-                proc.exception(graph, (Throwable)getResult());\r
-            } catch (Throwable t) {\r
-                t.printStackTrace();\r
-            }\r
-            \r
-        } else {\r
-            \r
-            try {\r
-                proc.execute(graph, (T)getResult());\r
-            } catch (Throwable t) {\r
-                t.printStackTrace();\r
-            }\r
-            \r
-        }\r
-               \r
-       }\r
-\r
-       @Override\r
-       public String toString() {\r
-               if(isDiscarded()) return "DISCARDED " + request.toString();\r
-               else if(isExcepted()) return request.toString() + " " + getResult();\r
-               else return request.toString() + " " + statusOrException;\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.ArrayList;
+
+import org.simantics.db.AsyncReadGraph;
+import org.simantics.db.impl.DebugPolicy;
+import org.simantics.db.impl.graph.ReadGraphImpl;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.request.AsyncRead;
+
+final public class AsyncReadEntry<T> extends CacheEntryBase {
+
+    protected AsyncRead<T> request;
+
+    public AsyncReadEntry(AsyncRead<T> request) {
+       this.request = request;
+       if(DebugPolicy.QUERY_STATE) System.out.println("[QUERY STATE]: created " + this);
+    }
+
+    @Override
+    int makeHash() {
+       return request.hashCode();
+    }
+    
+    @Override
+    public Object getOriginalRequest() {
+        return request;
+    }
+    
+    @Override
+    public void discard() {
+       super.discard();
+       //request = null;
+       setResult(null);
+    }
+    
+    final public void addOrSet(AsyncReadGraph graph, Object item) {
+
+       assert(isPending());
+        
+//        ArrayList<AsyncProcedure<T>> p = null;
+
+        synchronized(this) {
+               
+            setResult(item);
+               setReady();
+//            p = procs;
+//            procs = null;
+            
+        }
+
+//        if(p != null)
+//            for(AsyncProcedure<T> proc : p) {
+//             proc.execute(graph, (T)item);
+////                proc.first.execute(graph, (T)item);
+////                proc.second.dec();
+//            }
+        
+    }
+    
+    
+    public void except(AsyncReadGraph graph, Throwable t) {
+       
+       assert(isPending());
+        
+//        ArrayList<AsyncProcedure<T>> p = null;
+
+        synchronized(this) {
+               
+            except(t);
+////            p = procs;
+//            procs = null;
+            
+        }
+
+//        if(p != null)
+//            for(AsyncProcedure<T> proc : p) {
+//             proc.exception(graph, t);
+//            }
+       
+    }
+    
+    
+    @Override
+    final public Query getQuery() {
+       
+        return new Query() {
+
+                       @Override
+                       public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) {
+                               
+                               QueryProcessor qp = (QueryProcessor)provider;
+
+                               final ReadGraphImpl parentGraph = ReadGraphImpl.forRecompute(entry, qp); 
+
+                               try {
+
+                                   request.perform(parentGraph , new AsyncProcedure<T>() {
+
+                        @Override
+                        public void execute(AsyncReadGraph graph, T result) {
+                            addOrSet(graph, result);
+                        }
+                               
+                               @Override
+                               public void exception(AsyncReadGraph graph, Throwable t) {
+                                   except(t);
+                        }
+
+                    });
+
+                               } catch (Throwable t) {
+                                   except(t);
+                }
+                               
+                       }
+
+                       @Override
+                       public void removeEntry(QueryProcessor qp) {
+                       qp.asyncReadMap.remove(request);
+                       }
+
+                       @Override
+                       public int type() {
+                               return request.getFlags();
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               if(request == null) return "DISCARDED";
+                               else if(isExcepted()) return request.toString() + " " + getResult();
+                               else return request.toString() + " " + statusOrException;
+                       }
+               
+        };
+        
+    }
+
+       public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) {
+               
+        AsyncProcedure<T> proc = (AsyncProcedure<T>)procedure;
+
+           if(isExcepted()) {
+            
+            try {
+                proc.exception(graph, (Throwable)getResult());
+            } catch (Throwable t) {
+                t.printStackTrace();
+            }
+            
+        } else {
+            
+            try {
+                proc.execute(graph, (T)getResult());
+            } catch (Throwable t) {
+                t.printStackTrace();
+            }
+            
+        }
+               
+       }
+
+       @Override
+       public String toString() {
+               if(isDiscarded()) return "DISCARDED " + request.toString();
+               else if(isExcepted()) return request.toString() + " " + getResult();
+               else return request.toString() + " " + statusOrException;
+       }
+
+}