Interface Transaction
-
@XmlElement(value="Transaction") public interface Transaction
The controller for transaction withFeatureStore. Shapefiles, databases, etc. are safely modified with the assistance of this interface. Transactions are also to provide authorization when working with locked features.All operations are considered to be working against a transaction. The
AUTO_COMMITconstant is used to represent an immediate mode where requests are immediately commited. Example use:Transaction t = ... t.putProperty("someHint", someValue); try { FeatureCollection road = store.getFeatures("road"); FeatureCollection river = store.getFeatures("river"); road .setTransaction(t); river.setTransaction(t); // Provides authorization and operates against transaction t.useAuthorization(authorizationID); road .removeAll(road .subCollection(filter)); river.removeAll(river.subCollection(filter)); t.commit(); // Commit operations } catch (IOException exception){ t.rollback(); // Cancel operations throw exception; // Propagate the exception } finally { t.close(); // free resources }
Example code walkthrough from the perspective of transaction:
- A new transaction is created
- A hint is provided using
putProperty(key, value) - Transaction is provided to two
FeatureStores. This may result in severalTransaction.Stateinstances being registered. These instances of transaction state may make use of any hint provided as properties (in previous step) when they are connected withState.setTransaction(t). t.useAuthorization(authorizationID)is called. EachTransaction.Statehas itsaddAuthorizationcallback invoked with the value ofauthorizationID.removeAllmethods are called on the twoFeatureCollections. Any of these opperations may make use of the hints provided as properties.- The transaction is commited. All of the transaction state instances have there commit commit methods called.
- The transaction is closed. All of the transaction state instances have there close close methods called.
- Since:
- GeoAPI 2.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface and Description static interfaceTransaction.StateFeatureStoreimplementations can use this interface to externalize the state they require to implementTransactionsupport.
-
Field Summary
Fields Modifier and Type Field and Description static TransactionAUTO_COMMITMarker constant used to indicate immidiate response.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description voidclose()Provides an opportunity for a transaction to free anyStateit maintains.LockResponsecommit()Makes all transactions made since the previous commit/rollback permanent.java.util.Set<java.lang.String>getAuthorizations()Returns the set of authorizations IDs held by this transaction.java.lang.ObjectgetProperty(java.lang.Object key)Retrieves a transaction property held by this transaction.Transaction.StategetState(java.lang.Object key)Retrieve a state used to squirel away information (and callbacks) for later.voidputProperty(java.lang.Object key, java.lang.Object value)Provides a property for this transasction.voidputState(java.lang.Object key, Transaction.State state)AllowsFeatureStoreto squirel away information (and callbacks) for later.voidremoveState(java.lang.Object key)AllowsFeatureStores to clean up information (and callbacks) they earlier provided.voidrollback()Undoes all transactions made since the last commit or rollback.voiduseAuthorization(java.lang.String authorizationID)Uses an Authorization token with this transaction.
-
-
-
Field Detail
-
AUTO_COMMIT
static final Transaction AUTO_COMMIT
Marker constant used to indicate immidiate response. The constant is a pure Marker (similar in spirit to a Null Object pattern). All methods do nothing, this constant can be detected by interested parties as a request to perform actions immidiately.
-
-
Method Detail
-
putProperty
void putProperty(java.lang.Object key, java.lang.Object value) throws java.io.IOExceptionProvides a property for this transasction. All proceedingFeatureStoreoperations may make use of the provided property.- Throws:
java.io.IOException- if there are problems with the feature store.- See Also:
getProperty(java.lang.Object)
-
getProperty
java.lang.Object getProperty(java.lang.Object key)
Retrieves a transaction property held by this transaction. This may be used to provide hints toFeatureStoreimplementations. It operates as a blackboard for client,FeatureStorecommunication.
-
useAuthorization
void useAuthorization(java.lang.String authorizationID) throws java.io.IOExceptionUses an Authorization token with this transaction. Any locks held against this token will be released on commit.All
FeatureCollections operations can make use of the provided authorization for the duration of this transaction. Authorization is only maintained until this transaction is commited or rolled back. That is operations that modify or delete a feature will only succeed if affected features either:- not locked
- locked with a provided
authorizationID
You may call this method several times to provide authorization token to multiple feature collections.
- Parameters:
authorizationID- Authorization ID. Should of been obtained from aLockResponse.- Throws:
java.io.IOException- if there are problems with the feature store.- See Also:
getAuthorizations()
-
getAuthorizations
java.util.Set<java.lang.String> getAuthorizations()
Returns the set of authorizations IDs held by this transaction. This collection is reset by the next call tocommit()orrollback().- See Also:
useAuthorization(java.lang.String)
-
putState
void putState(java.lang.Object key, Transaction.State state)AllowsFeatureStoreto squirel away information (and callbacks) for later. The most common example is a JDBCFeatureStoresaving the required connection for later opperations.This method will call
State.setTransaction(this)to allowStatea chance to configure itself.- Parameters:
key- Key used to externalize Statestate- Externalized State- See Also:
removeState(java.lang.Object),getState(java.lang.Object)
-
removeState
void removeState(java.lang.Object key)
AllowsFeatureStores to clean up information (and callbacks) they earlier provided. Care should be taken when using shared State to not remove State required by another feature sources.State.setTransaction(null)to allowStatea chance cleanup after itself.- Parameters:
key- Key that was used to externalize State
-
getState
Transaction.State getState(java.lang.Object key)
Retrieve a state used to squirel away information (and callbacks) for later. The most common example is a JDBC FeatureStore saving the required connection for later opperations.- Parameters:
key- Key that was used to externalize State- Returns:
- Current State externalized by key, or
nullif not found
-
commit
LockResponse commit() throws java.io.IOException
Makes all transactions made since the previous commit/rollback permanent.FeatureStores will need to issue any changes notifications using aFeatureEventto allFeatureStores with the same type name and a different transaction.FeatureStores with the same transaction will been notified of changes as the feature writer made them.Workflows:
LockRequest+Transactionreturns aLockResponseas the result of any and all lock requests made during the transaction.TransactionreturnsLockResponse.NONEwhen no lock requests are made.
For a discussion of these workflows please read the package javadocs.
- Returns:
- The lock response, or
LockResponse.NONEif no lock requests were made. - Throws:
java.io.IOException- if there are problems with the feature store.
-
rollback
void rollback() throws java.lang.UnsupportedOperationException, java.io.IOExceptionUndoes all transactions made since the last commit or rollback.FeatureStores will need to issue any changes notifications using aFeatureEvent. This will need to be issued to allFeatureStores with the same type name and transaction.- Throws:
java.lang.UnsupportedOperationException- if the rollback method is not supported by this datasource.java.io.IOException- if there are problems with the feature store.
-
close
void close() throws java.io.IOExceptionProvides an opportunity for a transaction to free anyStateit maintains. This method should callState.setTransaction(null)on all state it maintains.It is hoped that FeatureStore implementations that have externalized their state with the transaction take the opportunity to revert to
AUTO_COMMIT.- Throws:
java.io.IOException- if there are problems with the feature store.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG