org.geotools.data.jdbc
Class JDBCDataStore.QueryData

java.lang.Object
  extended byorg.geotools.data.jdbc.JDBCDataStore.QueryData
Enclosing class:
JDBCDataStore

public static class JDBCDataStore.QueryData
extends java.lang.Object

Provides an encapsulation of the connection, statement and result set of a JDBC query. This class solves the problem of "Where do we close JDBC resources when they are being used by multiple AttributeReaders?".

An alternative solution would be to have the FeatureReader manage the resources, however this will pose problems when combining JDBC Attribute Readers with other AttributeReaders and FeatureReaders. The QueryData solution works by holding all the needed resources and providing a close method that closes all the resources. When the close method is called any readers that are registered as QueryDataListeners for the query data will be notified. This will allow one AttributeReader to close the resources and any other AttributeReaders using the same resources will find out about it.

Author:
Sean Geoghegan, Defence Science and Technology Organisation.

Constructor Summary
JDBCDataStore.QueryData(JDBCDataStore.FeatureTypeInfo featureTypeInfo, java.sql.Connection conn, java.sql.Statement statement, java.sql.ResultSet resultSet, Transaction transaction)
          The constructor for the QueryData object.
 
Method Summary
 void addQueryDataListener(QueryDataListener l)
          Adds a QueryDataListener to the list of listeners.
 java.io.IOException cast(java.lang.String message, java.sql.SQLException sqlException)
          A convience method that ensures we handle rollback on error correctly.
 void close(java.sql.SQLException sqlException)
          Closes all the resources.
 void deleteCurrentRow()
           
protected  void fireCloseEvent()
          Fires the close event.
 java.sql.Connection getConnection()
           
 JDBCDataStore.FeatureTypeInfo getFeatureTypeInfo()
          DOCUMENT ME!
 java.sql.ResultSet getResultSet()
          Gets the result set.
 Transaction getTransaction()
          Returns transaction, this Query data is opperating against.
 boolean isInserting()
           
 void removeQueryDataListener(QueryDataListener l)
          Removes a QueryDataListener for the list of listeners.
 void setInserting(boolean isInserting)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCDataStore.QueryData

public JDBCDataStore.QueryData(JDBCDataStore.FeatureTypeInfo featureTypeInfo,
                               java.sql.Connection conn,
                               java.sql.Statement statement,
                               java.sql.ResultSet resultSet,
                               Transaction transaction)
The constructor for the QueryData object.

Parameters:
featureTypeInfo - DOCUMENT ME!
conn - The connection to the DB.
statement - The statement used to execute the query.
resultSet - The result set.
transaction - DOCUMENT ME!
Method Detail

getResultSet

public java.sql.ResultSet getResultSet()
Gets the result set.

Returns:
The result of the query.

close

public void close(java.sql.SQLException sqlException)
Closes all the resources.

All resources are closed the QueryDataListener.queryDataClosed() is called on all QueryDataListeners.

The Connection is handled differently depending on if this is an AUTO_COMMIT Transaction or not.

Jody Here: I have forced this method to handle maintaining conneciton status as it knows about Transactions and AttributeReaders do not.

USEAGE GUIDELINES:

Parameters:
sqlException - DOCUMENT ME!

addQueryDataListener

public void addQueryDataListener(QueryDataListener l)
Adds a QueryDataListener to the list of listeners.

Parameters:
l - The Listener to the add.

removeQueryDataListener

public void removeQueryDataListener(QueryDataListener l)
Removes a QueryDataListener for the list of listeners.

Parameters:
l - The Listener to remove.

fireCloseEvent

protected void fireCloseEvent()
Fires the close event.


getTransaction

public Transaction getTransaction()
Returns transaction, this Query data is opperating against.

Please note that if transacstion is not Transaction.AUTO_COMMIT you will need to call transaction.rollback() in the event of an SQLException.

Returns:
The current Transaction

cast

public java.io.IOException cast(java.lang.String message,
                                java.sql.SQLException sqlException)
A convience method that ensures we handle rollback on error correctly.

Returns an IOException encapsulating the sqlException after correctly rolling back the current Transaction. Rollback only occurs if we are not using Transacstion.AUTO_COMMIT.

TODO: chris is this a good idea?

Parameters:
message - DOCUMENT ME!
sqlException - DOCUMENT ME!
Returns:
DOCUMENT ME!

getConnection

public java.sql.Connection getConnection()

getFeatureTypeInfo

public JDBCDataStore.FeatureTypeInfo getFeatureTypeInfo()
DOCUMENT ME!

Returns:

isInserting

public boolean isInserting()
Returns:
Returns the isInserting.

setInserting

public void setInserting(boolean isInserting)
Parameters:
isInserting - The isInserting to set.

deleteCurrentRow

public void deleteCurrentRow()
                      throws java.sql.SQLException
Throws:
java.sql.SQLException


Copyright © 1996-2003 GeoTools. All Rights Reserved.