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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.request;
\r
14 import org.simantics.db.Session;
\r
15 import org.simantics.db.WriteGraph;
\r
16 import org.simantics.db.exception.CancelTransactionException;
\r
17 import org.simantics.db.exception.DatabaseException;
\r
20 * TODO: fix this AGE OLD documentation !! This is totally out of date.
\r
22 * The <code>GraphRequest</code> interface is used to create transaction
\r
23 * requests to Simantics database implementations. Both read and write
\r
24 * transaction requests use the same interface.
\r
27 * The actual work carried out by the implemented request should be done in the
\r
28 * <code>perform</code> method. It receives a <code>Graph</code> instance as
\r
29 * the only argument which is the interface for actually reading and writing the
\r
33 * Transaction requests can be made to the database by creating your own
\r
34 * <code>GraphRequest</code> instance and putting it in the request queue of
\r
35 * the database session through the {@link Session} interface. The database
\r
36 * session is responsible for executing the queued requests in a thread of its
\r
37 * choice, or possibly/preferably multiple threads. The database session can
\r
38 * allow multiple read-only requests to occur simultaneously, but read-write
\r
39 * requests require exclusive database access. In other words only one
\r
40 * read-write request can be in execution simultaneously.
\r
43 * This interface also has two callbacks - <code>handleException</code> for
\r
44 * allowing handling any exceptions thrown by <code>perform</code> and
\r
45 * <code>requestCompleted</code> for performing actions after a request has
\r
46 * been successfully completed.
\r
49 * Clients of this interface are encouraged to extend the provided abstract
\r
50 * implementations or this class or extend their own helper implementations for
\r
51 * ones particular needs. The provided abstract implementations are:
\r
53 * <li>{@link WriteRequest} provides default implementations for
\r
54 * everything except {@link #perform(WriteGraph)}.</li>
\r
55 * <li>{@link WriteResult} makes it easier for the user to return
\r
56 * a single result Object from the request.</li>
\r
59 * @author Tuukka Lehtonen
\r
61 * @see WriteOnlyRequest
\r
65 public interface Write extends WriteTraits {
\r
68 * When a <code>Write</code> request is serviced by the database session the
\r
69 * method <code>perform</code> is invoked.
\r
72 * Perform receives an object instance implementing the
\r
73 * <code>WriteGraph</code> interface which provides the only way to
\r
74 * read/write the graph data model. The <code>WriteGraph</code> instance
\r
75 * must only be valid during the execution of the <code>perform</code>
\r
76 * method and therefore should not be stored for use outside of its
\r
80 * The general contract of the method <code>perform</code> is that it may
\r
81 * take any action whatsoever which involves reading or writing the data
\r
82 * model through the received WriteGraph instance.
\r
84 * @param g an interface for reading and writing the data model
\r
85 * @return the result status of the request which affects how the
\r
86 * transaction proceeds, see GraphRequestStatus for more information
\r
87 * @throws DatabaseException if anything goes wrong inside the request thread
\r
88 * @throws CancelTransactionException to indicate that the request needs to
\r
89 * be cancelled and any changes rolled back
\r
91 void perform(WriteGraph graph) throws DatabaseException;
\r