public interface Transaction extends Closeable
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. Transaction.AUTO_COMMIT is used to represent an immidiate mode where requests are immidately commited.
For more information please see DataStore and FeatureStore.
Example Use:
Transaction t = new DefaultTransaction("handle");
t.putProperty( "hint", Integer.valueOf(7) );
try {
SimpleFeatureStore road = (SimpleFeatureStore) store.getFeatureSource("road");
FeatureStore river = (SimpleFeatureStore) store.getFeatureSource("river");
road.setTransaction( t );
river.setTransaction( t );
t.addAuthorization( lockID ); // provide authoriztion
road.removeFeatures( filter ); // operate against transaction
river.removeFeature( filter ); // operate against transaction
t.commit(); // commit operations
}
catch (IOException io){
t.rollback(); // cancel operations
}
finally {
t.close(); // free resources
}
Example code walkthrough (from the perspective of Transaction):
Modifier and Type | Interface and Description |
---|---|
static interface |
Transaction.State
DataStore implementations can use this interface to externalize the state they require to
implement Transaction Support.
|
Modifier and Type | Field and Description |
---|---|
static Transaction |
AUTO_COMMIT
Represents AUTO_COMMIT mode as opposed to operations with commit/rollback control under a
user-supplied transaction.
|
Modifier and Type | Method and Description |
---|---|
void |
addAuthorization(String authID)
Provides an Authorization ID for this Transaction.
|
void |
close()
Provides an opportunity for a Transaction to free an State it maintains.
|
void |
commit()
Makes all transactions made since the previous commit/rollback permanent.
|
Set<String> |
getAuthorizations()
List of Authorizations IDs held by this transaction.
|
Object |
getProperty(Object key)
Retrive a Transaction property held by this transaction.
|
Transaction.State |
getState(Object key)
Allows DataStores to squirel away information( and callbacks ) for later.
|
void |
putProperty(Object key,
Object value)
Provides a Transaction property for this Transasction.
|
void |
putState(Object key,
Transaction.State state)
Allows SimpleFeatureSource to squirel away information( and callbacks ) for later.
|
void |
removeState(Object key)
Allows FeatureSources to clean up information ( and callbacks ) they earlier provided.
|
void |
rollback()
Undoes all transactions made since the last commit or rollback.
|
static final Transaction AUTO_COMMIT
Object getProperty(Object key)
This may be used to provide hints to DataStore implementations, it operates as a blackboard for client, SimpleFeatureSource communication.
Set<String> getAuthorizations()
This list is reset by the next call to commit() or rollback().
Authorization IDs are used to provide FeatureLock support.
void putState(Object key, Transaction.State state)
The most common example is a JDBC DataStore saving the required connection for later operations.
ConnectionState implements State {
public Connection conn;
public addAuthorization() {}
public commit(){ conn.commit(); }
public rollback(){ conn.rollback(); }
}
putState will call State.setTransaction( transaction ) to allow State a chance to configure itself.
key
- Key used to externalize Statestate
- Externalized Statevoid removeState(Object key)
Care should be taken when using shared State to not remove State required by another FeatureSources.
removeState will call State.setTransaction( null ) to allow State a chance cleanup after itself.
key
- Key that was used to externalize StateTransaction.State getState(Object key)
The most common example is a JDBC DataStore saving the required connection for later operations.
null
if not foundvoid commit() throws IOException
FeatureSources will need to issue any changes notifications using a FeatureEvent.FEATURES_CHANGED to all FeatureSources with the same typeName and a different Transaction. FeatureSources with the same Transaction will of been notified of changes as the FeaureWriter made them.
DataSourceException
- if there are any datasource errors.IOException
#setAutoCommit(boolean)
void rollback() throws IOException
FeatureSources will need to issue any changes notifications using a FeatureEvent.FEATURES_CHANGED. This will need to be issued to all FeatureSources with the same typeName and Transaction.
DataSourceException
- if there are problems with the datasource.UnsupportedOperationException
- if the rollback method is not supported by this
datasource.IOException
#setAutoCommit(boolean)
void addAuthorization(String authID) throws IOException
All proceeding modifyFeatures,removeFeature, unLockFeatures, refreshLock and ReleaseLock operations will make use of the provided authorization.
Authorization is only maintained until the this Transaction is commited or rolledback.
That is operations will only succeed if affected features either:
Authorization ID is provided as a String, rather than a FeatureLock, to account for across process lock use.
authID
- IOException
void putProperty(Object key, Object value) throws IOException
All proceeding SimpleFeatureSource (for FeatureReader/Writer) operations may make use of the provided property.
IOException
void close() throws IOException
This method should call State.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 Transction.AUTO_COMMIT.
close
in interface AutoCloseable
close
in interface Closeable
IOException
Copyright © 1996–2019 Geotools. All rights reserved.