org.geotools.data.jdbc
Class JDBCDataSource

java.lang.Object
  extended byorg.geotools.data.AbstractDataSource
      extended byorg.geotools.data.jdbc.JDBCDataSource
All Implemented Interfaces:
DataSource

public abstract class JDBCDataSource
extends AbstractDataSource

This class provides a skeletal implementation of the DataSource interface to minimize the effort of required to implement this interface.

Version:
$Id: JDBCDataSource.java,v 1.4 2003/11/04 00:34:02 cholmesny Exp $
Author:
Chris Holmes, TOPP, Sean Geoghegan

Nested Class Summary
 
Nested classes inherited from class org.geotools.data.AbstractDataSource
AbstractDataSource.MetaDataSupport
 
Field Summary
protected  java.sql.Connection transConn
          A postgis connection.
 
Fields inherited from class org.geotools.data.AbstractDataSource
supportMsg
 
Constructor Summary
JDBCDataSource(ConnectionPool pool)
           
 
Method Summary
protected  void closeTransactionConnection()
          This method should be called when a connection retrieved using getTransactionConnection is to be closed.
 void commit()
          Makes all transactions made since the previous commit/rollback permanent.
protected  DataSourceMetaData createMetaData()
          Creates the a metaData object.
protected  void finalizeTransactionMethod(boolean previousAutoCommit, boolean fail)
          This is called my any transaction method in its finally block.
 boolean getAutoCommit()
          Retrieves the current autoCommit mode for the current DataSource.
protected  java.sql.Connection getConnection()
          Gets a connection.
protected  java.sql.Connection getTransactionConnection()
          This method should be called when a connection is required for transactions.
 void rollback()
          Undoes all transactions made since the last commit or rollback.
 void setFeatures(FeatureCollection features)
          Performs the setFeautres operation by removing all and then adding the full collection.
 
Methods inherited from class org.geotools.data.AbstractDataSource
abortLoading, addFeatures, getBounds, getFeatures, getFeatures, getFeatures, getFeatures, getFeatures, getMetaData, getSchema, makeDefaultQuery, modifyFeatures, modifyFeatures, removeFeatures, setAutoCommit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

transConn

protected java.sql.Connection transConn
A postgis connection.

Constructor Detail

JDBCDataSource

public JDBCDataSource(ConnectionPool pool)
Method Detail

commit

public void commit()
            throws DataSourceException
Makes all transactions made since the previous commit/rollback permanent. This method should be used only when auto-commit mode has been disabled. If autoCommit is true then this method does nothing.

Throws:
DataSourceException - if there are any datasource errors.
See Also:
AbstractDataSource.setAutoCommit(boolean)

createMetaData

protected DataSourceMetaData createMetaData()
Creates the a metaData object. This method should be overridden in any subclass implementing any functions beyond getFeatures, so that clients recieve the proper information about the datasource's capabilities.

Returns:
the metadata for this datasource.
See Also:
#MetaDataSupport

setFeatures

public void setFeatures(FeatureCollection features)
                 throws DataSourceException
Performs the setFeautres operation by removing all and then adding the full collection. This is not efficient, the add, modify and remove operations should be used instead, this is just to follow the interface. Extensions of this class should set supportsSetFeatures to true if remove and add are supported, and this class will do the work for them.

Parameters:
features - the features to set for this table.
Throws:
DataSourceException - if there are problems removing or adding.
java.lang.UnsupportedOperationException - If setFeatures is not supported

rollback

public void rollback()
              throws DataSourceException
Undoes all transactions made since the last commit or rollback. This method should be used only when auto-commit mode has been disabled. This method should only be implemented if setAutoCommit(boolean) is also implemented.

Throws:
DataSourceException - if there are problems with the datasource.
See Also:
AbstractDataSource.setAutoCommit(boolean)

getAutoCommit

public boolean getAutoCommit()
                      throws DataSourceException
Retrieves the current autoCommit mode for the current DataSource. If the datasource does not implement setAutoCommit, then this method should always return true.

Returns:
the current state of this datasource's autoCommit mode.
Throws:
DataSourceException - if a datasource access error occurs.
See Also:
AbstractDataSource.setAutoCommit(boolean)

getConnection

protected java.sql.Connection getConnection()
                                     throws DataSourceException
Gets a connection.

The connection returned by this method is suitable for a single use. Once a method has finish with the connection it should call the connections close method.

Methods wishing to use a connection for transactions or methods who use of the connection involves commits or rollbacks should use getTransactionConnection instead of this method.

Returns:
A single use connection.
Throws:
DataSourceException - If the connection is not an OracleConnection.

finalizeTransactionMethod

protected void finalizeTransactionMethod(boolean previousAutoCommit,
                                         boolean fail)
                                  throws DataSourceException
This is called my any transaction method in its finally block. If the transaction failed it is rolled back, if it succeeded and we are previously set to autocommit, it is committed and if it succeed and we are set to manual commit, no action is taken.

In all cases the autocommit status of the data source is set to previousAutoCommit and the closeTransactionConnection is called.

Parameters:
previousAutoCommit - The status of autoCommit prior to the beginning of a transaction method. This tells us whether we should commit or wiat for the user to perform the commit.
fail - The fail status of the transaction. If true, the transaction is rolled back.
Throws:
DataSourceException - If errors occur performing any of the actions.

getTransactionConnection

protected java.sql.Connection getTransactionConnection()
                                                throws DataSourceException,
                                                       java.sql.SQLException
This method should be called when a connection is required for transactions. After completion of the use of the connection the caller should call closeTransactionConnection which will either close the conn if we are in auto commit, or maintain the connection if we are in manual commit. Successive calls to this method after setting autoCommit to false will return the same connection object.

Returns:
A connection object suitable for multiple transactional calls.
Throws:
DataSourceException - IF an error occurs getting the connection.
java.sql.SQLException - If there is something wrong with the connection.

closeTransactionConnection

protected void closeTransactionConnection()
This method should be called when a connection retrieved using getTransactionConnection is to be closed.

This method only closes the connection if it is set to auto commit. Otherwise the connection is kept open and held in the transactionConnection instance variable.



Copyright © 1996-2003 GeoTools. All Rights Reserved.