]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ReadEntry.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ReadEntry.java
index a9fc5120730e39de1971a9dd43de956b13decc65..e4ff1ea874bb2c3b9f8e288d413eaedc49f51c51 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 org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.impl.graph.ReadGraphImpl;\r
-import org.simantics.db.impl.graph.WriteGraphImpl;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.db.request.ReadExt;\r
-import org.simantics.db.request.RequestFlags;\r
-\r
-final public class ReadEntry<T> extends CacheEntryBase {\r
-\r
-       protected Read<T> request;\r
-\r
-       public ReadEntry(Read<T> request) {\r
-       this.request = request;\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
-       setResult(null);\r
-    }\r
-       \r
-    final public void addOrSet(AsyncReadGraph graph, Object item) {\r
-\r
-       assert(assertPending());\r
-       \r
-//        ArrayList<Pair<AsyncProcedure<T>, AsyncBarrier>> 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(Pair<AsyncProcedure<T>, AsyncBarrier> proc : p) {\r
-//                     proc.first.execute(graph, (T)item);\r
-//                     proc.second.dec();\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
-                       WriteGraphImpl write = qp.getCore().getSession().getService(WriteGraphImpl.class);\r
-                               \r
-                       ReadGraphImpl graph = write.newSync(entry);\r
-\r
-                               try {\r
-\r
-                                       entry.setPending();\r
-                                   T result = request.perform(graph);\r
-                                   addOrSet(graph, result);\r
-\r
-                               } catch (Throwable t) {\r
-\r
-                                       except(t);\r
-                    \r
-                }\r
-                               \r
-                       }\r
-\r
-                       @Override\r
-                       public void removeEntry(QueryProcessor processor) {\r
-                               processor.readMap.remove(request);\r
-                       }\r
-\r
-                       @Override\r
-                       public int type() {\r
-                               if(request instanceof ReadExt) {\r
-                                       return ((ReadExt)request).getType();\r
-                               } else {\r
-                                       return RequestFlags.INVALIDATE;\r
-                               }\r
-                       }\r
-                       \r
-                       @Override\r
-                       public String toString() {\r
-                               if(request == null) return "DISCARDED";\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(request == null) return "DISCARDED";\r
-               else return request.toString() + " - " + statusOrException;\r
-       }\r
-       \r
-       public Object get(ReadGraphImpl graph, QueryProcessor processor, Object procedure) throws DatabaseException {\r
-               if(procedure != null) performFromCache(graph, processor, procedure);\r
-               checkAndThrow();\r
-               return getResult();\r
-       }\r
-       \r
-       @Override\r
-       boolean isImmutable(ReadGraphImpl graph) throws DatabaseException {\r
-               if(request instanceof ReadExt) {\r
-                       return ((ReadExt)request).isImmutable(graph);\r
-               }\r
-               return false;\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 org.simantics.db.AsyncReadGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.graph.ReadGraphImpl;
+import org.simantics.db.impl.graph.WriteGraphImpl;
+import org.simantics.db.procedure.AsyncProcedure;
+import org.simantics.db.request.Read;
+import org.simantics.db.request.ReadExt;
+import org.simantics.db.request.RequestFlags;
+
+final public class ReadEntry<T> extends CacheEntryBase {
+
+       protected Read<T> request;
+
+       public ReadEntry(Read<T> request) {
+       this.request = request;
+    }
+    
+    @Override
+    int makeHash() {
+       return request.hashCode();
+    }
+       
+    @Override
+    public Object getOriginalRequest() {
+        return request;
+    }
+    
+    @Override
+    public void discard() {
+       super.discard();
+       setResult(null);
+    }
+       
+    final public void addOrSet(AsyncReadGraph graph, Object item) {
+
+       assert(assertPending());
+       
+//        ArrayList<Pair<AsyncProcedure<T>, AsyncBarrier>> p = null;
+
+       synchronized(this) {
+           
+            setResult(item);
+               setReady();
+//             p = procs;
+//             procs = null;
+               
+       }
+
+//        if(p != null)
+//             for(Pair<AsyncProcedure<T>, AsyncBarrier> proc : p) {
+//                     proc.first.execute(graph, (T)item);
+//                     proc.second.dec();
+//             }
+        
+    }
+
+    @Override
+    final public Query getQuery() {
+        
+        return new Query() {
+
+                       @Override
+                       public void recompute(ReadGraphImpl graph_, Object provider, CacheEntry entry) {
+                               
+                               QueryProcessor qp = (QueryProcessor)provider;
+                               
+                       WriteGraphImpl write = qp.getCore().getSession().getService(WriteGraphImpl.class);
+                               
+                       ReadGraphImpl graph = write.newSync(entry);
+
+                               try {
+
+                                       entry.setPending();
+                                   T result = request.perform(graph);
+                                   addOrSet(graph, result);
+
+                               } catch (Throwable t) {
+
+                                       except(t);
+                    
+                }
+                               
+                       }
+
+                       @Override
+                       public void removeEntry(QueryProcessor processor) {
+                               processor.readMap.remove(request);
+                       }
+
+                       @Override
+                       public int type() {
+                               if(request instanceof ReadExt) {
+                                       return ((ReadExt)request).getType();
+                               } else {
+                                       return RequestFlags.INVALIDATE;
+                               }
+                       }
+                       
+                       @Override
+                       public String toString() {
+                               if(request == null) return "DISCARDED";
+                               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(request == null) return "DISCARDED";
+               else return request.toString() + " - " + statusOrException;
+       }
+       
+       public Object get(ReadGraphImpl graph, QueryProcessor processor, Object procedure) throws DatabaseException {
+               if(procedure != null) performFromCache(graph, processor, procedure);
+               checkAndThrow();
+               return getResult();
+       }
+       
+       @Override
+       boolean isImmutable(ReadGraphImpl graph) throws DatabaseException {
+               if(request instanceof ReadExt) {
+                       return ((ReadExt)request).isImmutable(graph);
+               }
+               return false;
+       }
+
+}