org.geotools.data
Interface Transaction

All Known Implementing Classes:
DefaultTransaction

public interface Transaction

The controller for Transaction with FeatureStore.

Shapefiles, databases, etc. are safely modified with the assistance of this interface. Transactions are also to provide authorization when working with locked features.

All opperations 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", new Integer(7) );
 try {
     FeatureStore road = (FeatureStore) store.getFeatureSource("road");
     FeatureStore river = (FeatureStore) store.getFeatureSource("river");
 
     road.setTransaction( t );
     river.setTransaction( t );
 
     t.addAuthorization( lockID );  // provide authoriztion
     road.removeFeatures( filter ); // opperate against transaction
     river.removeFeature( filter ); // opperate against transaction
 
     t.commit(); // commit opperations
 }
 catch (IOException io){
     t.rollback(); // cancel opperations
 }
 finally {
     t.close(); // free resources
 }
 

Example code walkthrough from the (perspective of Tranasction):

  1. A new transaction is created (an instanceof DefaultTransaction with a handle)
  2. A hint is provided using Transaction.putProperty( key, value )
  3. Transaction is provided to two FeatureStores, this may result in Transaction.State instances being registered
  4. These instances of Transaction state may make use of any hint provided to Transaction.putProperty( key, value ) when they are connected with Transaction.State.setTransaction( transaction ).
  5. t.addAuthorization(lockID) is called, each Transaction.State has its addAuthroization(String) callback invoked with the value of lockID
  6. FeatureStore.removeFeatures methods are called on the two DataStores. Any of these opperations may make use of the Transaction.putProperty( key, value ).
  7. The transaction is commited, all of the Transaction.State methods have there Transaction.State.commit() methods called gicing them a chance to applyDiff maps, or commit various connections.
  8. The transaction is closed, all of the Transaction.State methods have there Transaction.State.setTransaction( null ) called, giving them a chance to clean up diffMaps, or return connections to the pool.

Version:
$Id: Transaction.java 17702 2006-01-23 00:08:55Z desruisseaux $
Author:
Jody Garnett, Chris Holmes, TOPP

Nested Class Summary
static interface Transaction.State
          DataStore implementations can use this interface to externalize the state they require to implement Transaction Support.
 
Field Summary
static Transaction AUTO_COMMIT
          Represents AUTO_COMMIT Mode
 
Method Summary
 void addAuthorization(java.lang.String authID)
          Provides an Authorization ID for this Transaction.
 void close()
          Provides an oppertunity for a Transaction to free an State it maintains.
 void commit()
          Makes all transactions made since the previous commit/rollback permanent.
 java.util.Set getAuthorizations()
          List of Authorizations IDs held by this transaction.
 java.lang.Object getProperty(java.lang.Object key)
          Retrive a Transaction property held by this transaction.
 Transaction.State getState(java.lang.Object key)
          Allows DataStores to squirel away information( and callbacks ) for later.
 void putProperty(java.lang.Object key, java.lang.Object value)
          Provides a Transaction property for this Transasction.
 void putState(java.lang.Object key, Transaction.State state)
          Allows FeatureSource to squirel away information( and callbacks ) for later.
 void removeState(java.lang.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.
 

Field Detail

AUTO_COMMIT

public static final Transaction AUTO_COMMIT
Represents AUTO_COMMIT Mode

Method Detail

getProperty

public java.lang.Object getProperty(java.lang.Object key)
Retrive a Transaction property held by this transaction.

This may be used to provide hints to DataStore implementations, it opperates as a blackboard for client, FeatureSource communication.

If this proves successful addAuthorization/getAuthorization will be replaced with this mechanism.


getAuthorizations

public java.util.Set getAuthorizations()
List of Authorizations IDs held by this transaction.

This list is reset by the next call to commit() or rollback().

Authorization IDs are used to provide FeatureLock support.

Returns:
List of Authorization IDs

putState

public void putState(java.lang.Object key,
                     Transaction.State state)
Allows FeatureSource to squirel away information( and callbacks ) for later.

The most common example is a JDBC DataStore saving the required connection for later opperations.


 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.

Parameters:
key - Key used to externalize State
state - Externalized State

removeState

public void removeState(java.lang.Object key)
Allows FeatureSources to clean up information ( and callbacks ) they earlier provided.

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.

Parameters:
key - Key that was used to externalize State

getState

public Transaction.State getState(java.lang.Object key)
Allows DataStores to squirel away information( and callbacks ) for later.

The most common example is a JDBC DataStore saving the required connection for later opperations.

Returns:
Current State externalized by key, or null if not found

commit

public void commit()
            throws java.io.IOException
Makes all transactions made since the previous commit/rollback permanent.

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.

Throws:
DataSourceException - if there are any datasource errors.
java.io.IOException
See Also:
#setAutoCommit(boolean)

rollback

public void rollback()
              throws java.io.IOException
Undoes all transactions made since the last commit or rollback.

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.

Throws:
DataSourceException - if there are problems with the datasource.
java.lang.UnsupportedOperationException - if the rollback method is not supported by this datasource.
java.io.IOException
See Also:
#setAutoCommit(boolean)

addAuthorization

public void addAuthorization(java.lang.String authID)
                      throws java.io.IOException
Provides an Authorization ID for this Transaction.

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.

Parameters:
authID -
Throws:
java.io.IOException

putProperty

public void putProperty(java.lang.Object key,
                        java.lang.Object value)
                 throws java.io.IOException
Provides a Transaction property for this Transasction.

All proceeding FeatureSource (for FeatureReader/Writer) opperations may make use of the provided property.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Provides an oppertunity for a Transaction to free an State it maintains.

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 oppertunity to revert to Transction.AUTO_COMMIT.

Throws:
java.io.IOException


Copyright © GeoTools. All Rights Reserved.