1 | /*
|
---|
2 | * GeoTools - The Open Source Java GIS Toolkit
|
---|
3 | * http://geotools.org
|
---|
4 | *
|
---|
5 | * (C) 2002-2008, Open Source Geospatial Foundation (OSGeo)
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Lesser General Public
|
---|
9 | * License as published by the Free Software Foundation;
|
---|
10 | * version 2.1 of the License.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Lesser General Public License for more details.
|
---|
16 | */
|
---|
17 | package org.geotools.data;
|
---|
18 |
|
---|
19 | import java.util.Set;
|
---|
20 |
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * The controller for Transaction with FeatureStore.
|
---|
24 | *
|
---|
25 | * <p>
|
---|
26 | * Shapefiles, databases, etc. are safely modified with the assistance of this
|
---|
27 | * interface. Transactions are also to provide authorization when working with
|
---|
28 | * locked features.
|
---|
29 | * </p>
|
---|
30 | *
|
---|
31 | * <p>
|
---|
32 | * All operations are considered to be working against a Transaction.
|
---|
33 | * Transaction.AUTO_COMMIT is used to represent an immidiate mode where
|
---|
34 | * requests are immidately commited.
|
---|
35 | * </p>
|
---|
36 | *
|
---|
37 | * <p>
|
---|
38 | * For more information please see DataStore and FeatureStore.
|
---|
39 | * </p>
|
---|
40 | *
|
---|
41 | * <p>
|
---|
42 | * Example Use:
|
---|
43 | * </p>
|
---|
44 | * <pre><code>
|
---|
45 | * Transaction t = new DefaultTransaction("handle");
|
---|
46 | * t.putProperty( "hint", new Integer(7) );
|
---|
47 | * try {
|
---|
48 | * SimpleFeatureStore road = (SimpleFeatureStore) store.getFeatureSource("road");
|
---|
49 | * FeatureStore river = (SimpleFeatureStore) store.getFeatureSource("river");
|
---|
50 | *
|
---|
51 | * road.setTransaction( t );
|
---|
52 | * river.setTransaction( t );
|
---|
53 | *
|
---|
54 | * t.addAuthorization( lockID ); // provide authoriztion
|
---|
55 | * road.removeFeatures( filter ); // operate against transaction
|
---|
56 | * river.removeFeature( filter ); // operate against transaction
|
---|
57 | *
|
---|
58 | * t.commit(); // commit operations
|
---|
59 | * }
|
---|
60 | * catch (IOException io){
|
---|
61 | * t.rollback(); // cancel operations
|
---|
62 | * }
|
---|
63 | * finally {
|
---|
64 | * t.close(); // free resources
|
---|
65 | * }
|
---|
66 | * </code></pre>
|
---|
67 | * <p>
|
---|
68 | * Example code walkthrough (from the perspective of Transaction):
|
---|
69 | * </p>
|
---|
70 | * <ol>
|
---|
71 | * <li>A new transaction is created (an instanceof DefaultTransaction with a handle)</li>
|
---|
72 | * <li>A hint is provided using Transaction.putProperty( key, value )</li>
|
---|
73 | * <li>Transaction is provided to two FeatureStores, this may result
|
---|
74 | * in Transaction.State instances being registered</li>
|
---|
75 | * <ul>
|
---|
76 | * <li>TransactionStateDiff (stored by DataStore):
|
---|
77 | * Used for in memory locking is used by many DataStore's
|
---|
78 | * (like ShapefileDataStore).
|
---|
79 | * Lazy creation by AbstractDataStore.state(transaction).
|
---|
80 | * </li>
|
---|
81 | * <li>JDBCTransactionState (stored by ConnectionPool):
|
---|
82 | * Used to manage connection rollback/commit.
|
---|
83 | * Lazy creation as part of JDBCDataStore.getConnection(transaction).
|
---|
84 | * </li>
|
---|
85 | * <li>InProcessLockingManager.FeatureLock (stored by LockingManger):
|
---|
86 | * Used for per transaction FeatureLocks, used to free locked features
|
---|
87 | * on Transaction commit/rollback.
|
---|
88 | * </li>
|
---|
89 | * </ul>
|
---|
90 | * These instances of Transaction state may make use of any hint provided
|
---|
91 | * to Transaction.putProperty( key, value ) when they are connected with
|
---|
92 | * Transaction.State.setTransaction( transaction ).
|
---|
93 | * <li>t.addAuthorization(lockID) is called, each Transaction.State has its
|
---|
94 | * addAuthroization(String) callback invoked with the value of lockID</li>
|
---|
95 | * <li>FeatureStore.removeFeatures methods are called on the two DataStores.
|
---|
96 | * <ul>
|
---|
97 | * <li>PostgisFeatureStore.removeFeatures(fitler) handles operation
|
---|
98 | * without delegation.
|
---|
99 | * </li>
|
---|
100 | * <li>Most removeFeature(filter) implementations use the implementation
|
---|
101 | * provided by AbstractFeatureStore which delegates to FeatureWriter.
|
---|
102 | * </li>
|
---|
103 | * </ul>
|
---|
104 | * Any of these operations may make use of the
|
---|
105 | * Transaction.putProperty( key, value ).
|
---|
106 | * <li>The transaction is commited, all of the Transaction.State methods have
|
---|
107 | * there Transaction.State.commit() methods called gicing them a chance
|
---|
108 | * to applyDiff maps, or commit various connections.
|
---|
109 | * </li>
|
---|
110 | * <li>The transaction is closed, all of the Transaction.State methods have
|
---|
111 | * there Transaction.State.setTransaction( null ) called, giving them a
|
---|
112 | * chance to clean up diffMaps, or return connections to the pool.
|
---|
113 | * </li>
|
---|
114 | * </ol>
|
---|
115 | * @author Jody Garnett
|
---|
116 | * @author Chris Holmes, TOPP
|
---|
117 | *
|
---|
118 | * @source $URL: http://svn.osgeo.org/geotools/branches/2.7.x/modules/library/api/src/main/java/org/geotools/data/Transaction.java $
|
---|
119 | * @version $Id: Transaction.java 37280 2011-05-24 07:53:02Z mbedward $
|
---|
120 | */
|
---|
121 | public interface Transaction {
|
---|
122 | /**
|
---|
123 | * Represents AUTO_COMMIT mode as opposed to operations with commit/rollback
|
---|
124 | * control under a user-supplied transaction.
|
---|
125 | */
|
---|
126 | static final Transaction AUTO_COMMIT = new AutoCommitTransaction();
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * List of Authorizations IDs held by this transaction.
|
---|
130 | *
|
---|
131 | * <p>
|
---|
132 | * This list is reset by the next call to commit() or rollback().
|
---|
133 | * </p>
|
---|
134 | *
|
---|
135 | * <p>
|
---|
136 | * Authorization IDs are used to provide FeatureLock support.
|
---|
137 | * </p>
|
---|
138 | *
|
---|
139 | * @return List of Authorization IDs
|
---|
140 | */
|
---|
141 | Set<String> getAuthorizations();
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Allows SimpleFeatureSource to squirel away information( and callbacks ) for
|
---|
145 | * later.
|
---|
146 | *
|
---|
147 | * <p>
|
---|
148 | * The most common example is a JDBC DataStore saving the required
|
---|
149 | * connection for later operations.
|
---|
150 | * </p>
|
---|
151 | * <pre><code>
|
---|
152 | * ConnectionState implements State {
|
---|
153 | * public Connection conn;
|
---|
154 | * public addAuthorization() {}
|
---|
155 | * public commit(){ conn.commit(); }
|
---|
156 | * public rollback(){ conn.rollback(); }
|
---|
157 | * }
|
---|
158 | * </code></pre>
|
---|
159 | *
|
---|
160 | * <p>
|
---|
161 | * putState will call State.setTransaction( transaction ) to allow State a
|
---|
162 | * chance to configure itself.
|
---|
163 | * </p>
|
---|
164 | *
|
---|
165 | * @param key Key used to externalize State
|
---|
166 | * @param state Externalized State
|
---|
167 | */
|
---|
168 | void putState(Object key, State state);
|
---|
169 |
|
---|
170 | /**
|
---|
171 | * Allows DataStores to squirel away information( and callbacks ) for
|
---|
172 | * later.
|
---|
173 | *
|
---|
174 | * <p>
|
---|
175 | * The most common example is a JDBC DataStore saving the required
|
---|
176 | * connection for later operations.
|
---|
177 | * </p>
|
---|
178 | *
|
---|
179 | * @return Current State externalized by key, or <code>null</code> if not
|
---|
180 | * found
|
---|
181 | */
|
---|
182 | State getState(Object key);
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * DataStore implementations can use this interface to externalize the
|
---|
186 | * state they require to implement Transaction Support.
|
---|
187 | *
|
---|
188 | * <p>
|
---|
189 | * The commit and rollback methods will be called as required. The
|
---|
190 | * intension is that several DataStores can share common transaction state
|
---|
191 | * (example: Postgis DataStores sharing a connection to the same
|
---|
192 | * database).
|
---|
193 | * </p>
|
---|
194 | *
|
---|
195 | * @author jgarnett, Refractions Reasearch Inc.
|
---|
196 | * @version CVS Version
|
---|
197 | *
|
---|
198 | * @see org.geotools.data
|
---|
199 | */
|
---|
200 | static public interface State {
|
---|
201 | }
|
---|
202 | }
|
---|