]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/WriteOnlyResultRequest.java
Map some ListUtils functions to SCL (refs #7134).
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / WriteOnlyResultRequest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.common.request;
13
14 import org.simantics.db.AsyncRequestProcessor;
15 import org.simantics.db.RequestProcessor;
16 import org.simantics.db.VirtualGraph;
17 import org.simantics.db.exception.DatabaseException;
18 import org.simantics.db.procedure.Procedure;
19 import org.simantics.db.request.UndoTraits;
20 import org.simantics.db.request.WriteInterface;
21 import org.simantics.db.request.WriteOnlyResult;
22
23
24 /**
25  * Usage samples:
26  * 
27  * <p>
28  * Synchronous read without checked exceptions:
29  * </p>
30  * <pre>
31  * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {
32  *     {@code @Override}
33  *     public Resource run(Graph g) {
34  *         Resource r = doSomethingThatMayFail();
35  *         return r;
36  *     }
37  * }.sync();
38  * </pre>
39  * 
40  * <p>
41  * Synchronous read with a selected checked exception that may be thrown:
42  * </p>
43  * <pre>
44  * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {
45  *     {@code @Override}
46  *     public Resource run(Graph g) throws CheckedException {
47  *         Resource r = doSomethingThatMayFailWithCheckedException();
48  *         return r;
49  *     }
50  * }.sync(CheckedException.class);
51  * </pre>
52  * 
53  * <p>
54  * Asynchronous read with a completed() method for examining the result:
55  * </p>
56  * <pre>
57  * Resource r = new SimpleReadGraphRequest&lt;Resource&gt;(session) {
58  *     {@code @Override}
59  *     public Resource run(Graph g) {
60  *         Resource r = doSomethingThatMayFail();
61  *         return r;
62  *     }
63  *     public void completed(Resource result) {
64  *         // quickly dispatch the result somewhere, do nothing serious in this code.
65  *     }
66  * }.async();
67  * </pre>
68  * 
69  * @param <T> the result type
70  */
71 public abstract class WriteOnlyResultRequest<T> implements WriteOnlyResult<T>, WriteInterface<T> {
72
73     private final VirtualGraph provider;
74
75     public WriteOnlyResultRequest() {
76         this.provider = null;
77     }
78
79     public WriteOnlyResultRequest(VirtualGraph provider) {
80         this.provider = provider;
81     }
82     
83     @Override
84     final public VirtualGraph getProvider() {
85         return provider;
86     }
87     
88     @Override
89     public UndoTraits getUndoTraits() {
90         return null;
91     }
92
93     @Override
94     public void request(AsyncRequestProcessor processor, final Procedure<T> procedure) {
95         processor.asyncRequest(this, procedure);
96     }
97     
98     @Override
99     public T request(RequestProcessor processor) throws DatabaseException {
100         return processor.syncRequest(this);
101     }
102     
103 }