]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.common/src/org/simantics/db/common/request/WriteRequest.java
Make Write-interfaces as @FunctionalInterface for lambdas
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / WriteRequest.java
index 76ab2016d80cc3fc230484941ac2b075e844a5fb..cb9460d13a2b49286b8b554683be9a81157122e7 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.common.request;\r
-\r
-import org.simantics.db.AsyncRequestProcessor;\r
-import org.simantics.db.Operation;\r
-import org.simantics.db.RequestProcessor;\r
-import org.simantics.db.VirtualGraph;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.procedure.Procedure;\r
-import org.simantics.db.request.UndoTraits;\r
-import org.simantics.db.request.Write;\r
-import org.simantics.db.request.WriteInterface;\r
-import org.simantics.utils.datastructures.Callback;\r
-\r
-\r
-/**\r
- * TODO: fix this javadoc to document the correct class!!\r
- * \r
- * Usage samples:\r
- * \r
- * <p>\r
- * Synchronous read without checked exceptions:\r
- * </p>\r
- * <pre>\r
- * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {\r
- *     {@code @Override}\r
- *     public Resource run(Graph g) {\r
- *         Resource r = doSomethingThatMayFail();\r
- *         return r;\r
- *     }\r
- * }.sync();\r
- * </pre>\r
- * \r
- * <p>\r
- * Synchronous read with a selected checked exception that may be thrown:\r
- * </p>\r
- * <pre>\r
- * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {\r
- *     {@code @Override}\r
- *     public Resource run(Graph g) throws CheckedException {\r
- *         Resource r = doSomethingThatMayFailWithCheckedException();\r
- *         return r;\r
- *     }\r
- * }.sync(CheckedException.class);\r
- * </pre>\r
- * \r
- * <p>\r
- * Asynchronous read with a completed() method for examining the result:\r
- * </p>\r
- * <pre>\r
- * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {\r
- *     {@code @Override}\r
- *     public Resource run(Graph g) {\r
- *         Resource r = doSomethingThatMayFail();\r
- *         return r;\r
- *     }\r
- *     public void completed(Resource result) {\r
- *         // quickly dispatch the result somewhere, do nothing serious in this code.\r
- *     }\r
- * }.async();\r
- * </pre>\r
- * \r
- * @param <T> the result type\r
- */\r
-public abstract class WriteRequest implements Write, UndoTraits, WriteInterface<Object> {\r
-\r
-    private final VirtualGraph provider;\r
-    \r
-    public WriteRequest() {\r
-        this.provider = null;\r
-    }\r
-\r
-    public WriteRequest(VirtualGraph provider) {\r
-        this.provider = provider;\r
-    }\r
-\r
-    @Override\r
-    public void commitOk(Operation op) {\r
-    }\r
-\r
-    @Override\r
-    final public VirtualGraph getProvider() {\r
-        return provider;\r
-    }\r
-\r
-    @Override\r
-    public UndoTraits getUndoTraits() {\r
-        return this;\r
-    }\r
-\r
-    \r
-    @Override\r
-    public void request(AsyncRequestProcessor processor, final Procedure<Object> procedure) {\r
-       processor.asyncRequest(this, new Callback<DatabaseException>() {\r
-                       \r
-                       @Override\r
-                       public void run(DatabaseException parameter) {\r
-                               if(parameter != null) procedure.exception(parameter);\r
-                               else procedure.execute(null);\r
-                       }\r
-                       \r
-               });\r
-    }\r
-    \r
-    @Override\r
-    public Object request(RequestProcessor processor) throws DatabaseException {\r
-       processor.syncRequest(this);\r
-       return null;\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.common.request;
+
+import org.simantics.db.AsyncRequestProcessor;
+import org.simantics.db.Operation;
+import org.simantics.db.RequestProcessor;
+import org.simantics.db.VirtualGraph;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Procedure;
+import org.simantics.db.request.UndoTraits;
+import org.simantics.db.request.Write;
+import org.simantics.db.request.WriteInterface;
+import org.simantics.utils.datastructures.Callback;
+
+
+/**
+ * TODO: fix this javadoc to document the correct class!!
+ * 
+ * Usage samples:
+ * 
+ * <p>
+ * Synchronous read without checked exceptions:
+ * </p>
+ * <pre>
+ * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {
+ *     {@code @Override}
+ *     public Resource run(Graph g) {
+ *         Resource r = doSomethingThatMayFail();
+ *         return r;
+ *     }
+ * }.sync();
+ * </pre>
+ * 
+ * <p>
+ * Synchronous read with a selected checked exception that may be thrown:
+ * </p>
+ * <pre>
+ * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {
+ *     {@code @Override}
+ *     public Resource run(Graph g) throws CheckedException {
+ *         Resource r = doSomethingThatMayFailWithCheckedException();
+ *         return r;
+ *     }
+ * }.sync(CheckedException.class);
+ * </pre>
+ * 
+ * <p>
+ * Asynchronous read with a completed() method for examining the result:
+ * </p>
+ * <pre>
+ * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {
+ *     {@code @Override}
+ *     public Resource run(Graph g) {
+ *         Resource r = doSomethingThatMayFail();
+ *         return r;
+ *     }
+ *     public void completed(Resource result) {
+ *         // quickly dispatch the result somewhere, do nothing serious in this code.
+ *     }
+ * }.async();
+ * </pre>
+ * 
+ * @param <T> the result type
+ */
+public abstract class WriteRequest implements Write, UndoTraits, WriteInterface<Object> {
+
+    private final VirtualGraph provider;
+    
+    public WriteRequest() {
+        this.provider = null;
+    }
+
+    public WriteRequest(VirtualGraph provider) {
+        this.provider = provider;
+    }
+
+    @Override
+    public void commitOk(Operation op) {
+    }
+
+    @Override
+    final public VirtualGraph getProvider() {
+        return provider;
+    }
+
+    @Override
+    public void request(AsyncRequestProcessor processor, final Procedure<Object> procedure) {
+       processor.asyncRequest(this, new Callback<DatabaseException>() {
+                       
+                       @Override
+                       public void run(DatabaseException parameter) {
+                               if(parameter != null) procedure.exception(parameter);
+                               else procedure.execute(null);
+                       }
+                       
+               });
+    }
+    
+    @Override
+    public Object request(RequestProcessor processor) throws DatabaseException {
+       processor.syncRequest(this);
+       return null;
+    }
+
+}