]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/request/DelayedWrite.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / request / DelayedWrite.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.request;\r
13 \r
14 import java.util.Map;\r
15 \r
16 import org.simantics.db.ChangeSetIdentifier;\r
17 import org.simantics.db.Session;\r
18 import org.simantics.db.VirtualGraph;\r
19 import org.simantics.db.WriteGraph;\r
20 import org.simantics.db.exception.CancelTransactionException;\r
21 import org.simantics.db.exception.DatabaseException;\r
22 \r
23 /**\r
24  * The <code>GraphRequest</code> interface is used to create transaction\r
25  * requests to Simantics database implementations. Both read and write\r
26  * transaction requests use the same interface.\r
27  * \r
28  * <p>\r
29  * The actual work carried out by the implemented request should be done in the\r
30  * <code>perform</code> method. It receives a <code>Graph</code> instance as\r
31  * the only argument which is the interface for actually reading and writing the\r
32  * graph data model.\r
33  * \r
34  * <p>\r
35  * Transaction requests can be made to the database by creating your own\r
36  * <code>GraphRequest</code> instance and putting it in the request queue of\r
37  * the database session through the {@link Session} interface. The database\r
38  * session is responsible for executing the queued requests in a thread of its\r
39  * choice, or possibly/preferably multiple threads. The database session can\r
40  * allow multiple read-only requests to occur simultaneously, but read-write\r
41  * requests require exclusive database access. In other words only one\r
42  * read-write request can be in execution simultaneously.\r
43  * \r
44  * <p>\r
45  * This interface also has two callbacks - <code>handleException</code> for\r
46  * allowing handling any exceptions thrown by <code>perform</code> and\r
47  * <code>requestCompleted</code> for performing actions after a request has\r
48  * been successfully completed.\r
49  * \r
50  * <p>\r
51  * Clients of this interface are encouraged to extend the provided abstract\r
52  * implementations or this class or extend their own helper implementations for\r
53  * ones particular needs. The provided abstract implementations are:\r
54  * <ul>\r
55  * <li>{@link ReadGraphRequestAdapter} provides default implementations for\r
56  * everything except {@link #perform(WriteGraph)}.</li>\r
57  * <li>{@link SimpleGraphRequest} replaces {@link #perform(WriteGraph)} with\r
58  * {@link SimpleGraphRequest#run(WriteGraph)} for easier request implementation in\r
59  * simple cases.</li>\r
60  * <li>{@link GraphRequestWithResult} makes it easier for the user to return\r
61  * a single result Object from the request.</li>\r
62  * </ul>\r
63  * \r
64  * @author Tuukka Lehtonen\r
65  * @see ReadGraphRequestAdapter\r
66  * @see GraphRequestRunner\r
67  * @see GraphRequestStatus\r
68  * @see GraphRequestWithResult\r
69  * @see Session\r
70  * @see SimpleGraphRequest\r
71  */\r
72 public interface DelayedWrite extends WriteTraits {\r
73 \r
74     /**\r
75      * When a <code>GraphRequest</code> is serviced by the database session\r
76      * the method <code>perform</code> is invoked.\r
77      * \r
78      * <p>\r
79      * Perform receives an object instance implementing the <code>Graph</code>\r
80      * interface which provides the only way to read/write the graph data model.\r
81      * The Graph instance must only be valid during the execution of the\r
82      * <code>perform</code> method and therefore should not be stored for use\r
83      * outside of its execution.\r
84      * \r
85      * <p>\r
86      * The general contract of the method <code>perform</code> is that it may\r
87      * take any action whatsoever which involves reading or writing the data\r
88      * model through the received Graph instance.\r
89      * \r
90      * @param g an interface for reading and writing the data model\r
91      * @return the result status of the request which affects how the\r
92      *         transaction proceeds, see GraphRequestStatus for more information\r
93      * @throws Exception when anything goes wrong inside the request thread\r
94      * @throws CancelTransactionException to indicate that the request needs to\r
95      *         be cancelled and any changes rolled back\r
96      */\r
97     void perform(WriteGraph graph) throws DatabaseException;\r
98     \r
99     ChangeSetIdentifier getIdentifier();\r
100     \r
101     VirtualGraph getProvider();\r
102     \r
103     void fillMetadata(Map<String, String> metadata);\r
104 }\r