]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/request/WriteOnlyResult.java
Make Write-interfaces as @FunctionalInterface for lambdas
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / request / WriteOnlyResult.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.request;
13
14 import org.simantics.db.Session;
15 import org.simantics.db.WriteOnlyGraph;
16 import org.simantics.db.exception.CancelTransactionException;
17 import org.simantics.db.exception.DatabaseException;
18
19 /**
20  * The <code>GraphRequest</code> interface is used to create transaction
21  * requests to Simantics database implementations. Both read and write
22  * transaction requests use the same interface.
23  * 
24  * <p>
25  * The actual work carried out by the implemented request should be done in the
26  * <code>perform</code> method. It receives a <code>WriteOnlyGraph</code> instance as
27  * the only argument which is the interface for actually reading and writing the
28  * graph data model.
29  * 
30  * <p>
31  * Transaction requests can be made to the database by creating your own
32  * <code>GraphRequest</code> instance and putting it in the request queue of
33  * the database session through the {@link Session} interface. The database
34  * session is responsible for executing the queued requests in a thread of its
35  * choice, or possibly/preferably multiple threads. The database session can
36  * allow multiple read-only requests to occur simultaneously, but read-write
37  * requests require exclusive database access. In other words only one
38  * read-write request can be in execution simultaneously.
39  * 
40  * <p>
41  * This interface also has two callbacks - <code>handleException</code> for
42  * allowing handling any exceptions thrown by <code>perform</code> and
43  * <code>requestCompleted</code> for performing actions after a request has
44  * been successfully completed.
45  * 
46  * <p>
47  * Clients of this interface are encouraged to extend the provided abstract
48  * implementations or this class or extend their own helper implementations for
49  * ones particular needs. The provided abstract implementations are:
50  * <ul>
51  * <li>{@link ReadGraphRequestAdapter} provides default implementations for
52  * everything except {@link #perform(WriteOnlyGraph)}.</li>
53  * <li>{@link SimpleGraphRequest} replaces {@link #perform(WriteOnlyGraph)} with
54  * {@link SimpleGraphRequest#run(WriteOnlyGraph)} for easier request implementation in
55  * simple cases.</li>
56  * <li>{@link GraphRequestWithResult} makes it easier for the user to return
57  * a single result Object from the request.</li>
58  * </ul>
59  * 
60  * @author Tuukka Lehtonen
61  * @see ReadGraphRequestAdapter
62  * @see GraphRequestRunner
63  * @see GraphRequestStatus
64  * @see GraphRequestWithResult
65  * @see Session
66  * @see SimpleGraphRequest
67  */
68 @FunctionalInterface
69 public interface WriteOnlyResult<T> extends WriteTraits {
70
71     /**
72      * When a <code>GraphRequest</code> is serviced by the database session
73      * the method <code>perform</code> is invoked.
74      * 
75      * <p>
76      * Perform receives an object instance implementing the <code>WriteOnlyGraph</code>
77      * interface which provides the only way to read/write the graph data model.
78      * The Graph instance must only be valid during the execution of the
79      * <code>perform</code> method and therefore should not be stored for use
80      * outside of its execution.
81      * 
82      * <p>
83      * The general contract of the method <code>perform</code> is that it may
84      * take any action whatsoever which involves reading or writing the data
85      * model through the received Graph instance.
86      * 
87      * @param g an interface for reading and writing the data model
88      * @return the result status of the request which affects how the
89      *         transaction proceeds, see GraphRequestStatus for more information
90      * @throws Exception when anything goes wrong inside the request thread
91      * @throws CancelTransactionException to indicate that the request needs to
92      *         be cancelled and any changes rolled back
93      */
94     T perform(WriteOnlyGraph graph) throws DatabaseException;
95
96 }