jrun.sql
Class JRunConnection

jrun.sql.JRunConnection
All Implemented Interfaces:
PooledObject, java.io.Serializable

public class JRunConnection
implements PooledObject

This is a JDBC Connection that encompasses the following three collaborators:

  • A logical Connection returned to clients, represented by a JRunConnectionHandle and returned by this class's getConnection() method.
  • A physical Connection managed internally, represented as a raw Connection to the database and returned by this class's getPhysicalConnection() method.
  • An XAResource, to which this class cedes control when a distributed transaction is active. The XAResource is represented by a ConnectionXAResource object.
    Each JRunDataSource knows of a single JDBCPool. That JDBCPool contains pools of these JRunConnection objects. Upon receiving the request, the JDBC pool checks out a validated JRunConnection from those available in the pool, and wraps it within a JRunConnectionHandle.
    Before returning this Handle, the XADataSource implementation (JRunDataSource) determines whether a distributed transaction is active. If so, it enlists the JRunConnection's XAResource in the Transaction. It then returns the Handle to the original caller.
    When the client closes the Handle, that Handle is disposed of. But the JRunConnection is returned to its pool, available for further checkouts. If the JRunConnection's XAResource is still active in a transaction, however, it will remain in the pool but will be unavailable until the transaction either commits or rolls back. Eventually the TX will timeout, causing a rollback and freeing such "locked" connections, at which time they are immediately available to service more checkout requests.
    Close and Error events are not handled explicitly, but propagated through ConnectionEvents in accordance with the JDBC spec. Similarly, the JRunConnection, Handle, and DataSource all implement the standard pooling mechanism defined in the specification.

    Author:
    PS Neville
    See Also:
    Serialized Form

    Constructor Summary
    JRunConnection(java.sql.Connection con, ObjectPool pool)
               
     
    Method Summary
     void addConnectionEventListener(javax.sql.ConnectionEventListener listener)
               
     boolean clean()
              Close any lingering Statements, ResutSets, and started XAResources as long as we're not involved in a transaction.
     void clearWarnings()
               
     void close()
              Close the physical Connection.
     void closeAll()
               
     void closeAllResources()
              Disassociate resource references from this object
     void commit()
               
     java.sql.Statement createStatement()
               
     java.sql.Statement createStatement(int resultSetType, int resultSetConcurrency)
               
     boolean getAutoCommit()
               
     java.lang.String getCatalog()
               
     java.sql.Connection getConnection()
               
     java.sql.DatabaseMetaData getMetaData()
               
     java.lang.String getPassword()
               
     java.sql.Connection getPhysicalConnection()
               
     ObjectPool getPool()
              Retrieve the pool containing this Object.
     int getTransactionIsolation()
               
     java.util.Map getTypeMap()
               
     java.lang.String getUsername()
               
     java.sql.SQLWarning getWarnings()
               
     javax.transaction.xa.XAResource getXAResource()
               
     boolean isClosed()
               
     boolean isConnectionError()
               
     boolean isReadOnly()
               
     boolean isTmControlled()
               
     boolean isValid()
               
     java.lang.String nativeSQL(java.lang.String sql)
               
     java.sql.CallableStatement prepareCall(java.lang.String sql)
               
     java.sql.CallableStatement prepareCall(java.lang.String sql, int resultSetType, int resultSetConcurrency)
               
     java.sql.PreparedStatement prepareStatement(java.lang.String sql)
               
     java.sql.PreparedStatement prepareStatement(java.lang.String sql, int resultSetType, int resultSetConcurrency)
               
     void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)
               
     void removeOpenStatement(JRunStatement s)
               
     void rollback()
               
     void sendCloseEvent()
               
     void setAutoCommit(boolean autoCommit)
               
     void setCatalog(java.lang.String catalog)
               
     void setConnectionError(boolean connectionError)
               
     void setPassword(java.lang.String password)
               
     void setReadOnly(boolean readOnly)
               
     void setTmControlled(boolean tmControlled)
               
     void setTransactionIsolation(int level)
               
     void setTypeMap(java.util.Map map)
               
     void setUsername(java.lang.String username)
               
     java.lang.String toString()
               
     void touch()
              Update the locked table in ObjectPool to prevent the object from timing out.
     

    Constructor Detail

    JRunConnection

    public JRunConnection(java.sql.Connection con,
                          ObjectPool pool)
    Method Detail

    isValid

    public boolean isValid()

    isTmControlled

    public boolean isTmControlled()

    setTmControlled

    public void setTmControlled(boolean tmControlled)

    closeAllResources

    public void closeAllResources()
    Description copied from interface: PooledObject
    Disassociate resource references from this object
    Specified by:
    closeAllResources in interface PooledObject

    closeAll

    public void closeAll()

    removeOpenStatement

    public void removeOpenStatement(JRunStatement s)

    clean

    public boolean clean()
    Close any lingering Statements, ResutSets, and started XAResources as long as we're not involved in a transaction. While in a transaction, the JDBCManager relinquishes control over the Connection to the TM. The timeout and expiration checks in the JDBCPool similarly submit to the TM.
    Specified by:
    clean in interface PooledObject

    touch

    public void touch()
    Update the locked table in ObjectPool to prevent the object from timing out.

    getPool

    public ObjectPool getPool()
    Description copied from interface: PooledObject
    Retrieve the pool containing this Object.
    Specified by:
    getPool in interface PooledObject
    Following copied from interface: jrunx.pool.PooledObject
    Returns:
    ObjectPool The pool that contains this object

    getXAResource

    public javax.transaction.xa.XAResource getXAResource()
                                                  throws java.sql.SQLException

    getConnection

    public java.sql.Connection getConnection()
                                      throws java.sql.SQLException

    getPhysicalConnection

    public java.sql.Connection getPhysicalConnection()

    addConnectionEventListener

    public void addConnectionEventListener(javax.sql.ConnectionEventListener listener)

    removeConnectionEventListener

    public void removeConnectionEventListener(javax.sql.ConnectionEventListener listener)

    sendCloseEvent

    public void sendCloseEvent()

    createStatement

    public java.sql.Statement createStatement()
                                       throws java.sql.SQLException

    prepareStatement

    public java.sql.PreparedStatement prepareStatement(java.lang.String sql)
                                                throws java.sql.SQLException

    prepareCall

    public java.sql.CallableStatement prepareCall(java.lang.String sql)
                                           throws java.sql.SQLException

    nativeSQL

    public java.lang.String nativeSQL(java.lang.String sql)
                               throws java.sql.SQLException

    setAutoCommit

    public void setAutoCommit(boolean autoCommit)
                       throws java.sql.SQLException

    getAutoCommit

    public boolean getAutoCommit()
                          throws java.sql.SQLException

    commit

    public void commit()
                throws java.sql.SQLException

    rollback

    public void rollback()
                  throws java.sql.SQLException

    close

    public void close()
               throws java.sql.SQLException
    Close the physical Connection.

    isClosed

    public boolean isClosed()
                     throws java.sql.SQLException

    getMetaData

    public java.sql.DatabaseMetaData getMetaData()
                                          throws java.sql.SQLException

    setReadOnly

    public void setReadOnly(boolean readOnly)
                     throws java.sql.SQLException

    isReadOnly

    public boolean isReadOnly()
                       throws java.sql.SQLException

    setCatalog

    public void setCatalog(java.lang.String catalog)
                    throws java.sql.SQLException

    getCatalog

    public java.lang.String getCatalog()
                                throws java.sql.SQLException

    setTransactionIsolation

    public void setTransactionIsolation(int level)
                                 throws java.sql.SQLException

    getTransactionIsolation

    public int getTransactionIsolation()
                                throws java.sql.SQLException

    getWarnings

    public java.sql.SQLWarning getWarnings()
                                    throws java.sql.SQLException

    clearWarnings

    public void clearWarnings()
                       throws java.sql.SQLException

    createStatement

    public java.sql.Statement createStatement(int resultSetType,
                                              int resultSetConcurrency)
                                       throws java.sql.SQLException

    prepareStatement

    public java.sql.PreparedStatement prepareStatement(java.lang.String sql,
                                                       int resultSetType,
                                                       int resultSetConcurrency)
                                                throws java.sql.SQLException

    prepareCall

    public java.sql.CallableStatement prepareCall(java.lang.String sql,
                                                  int resultSetType,
                                                  int resultSetConcurrency)
                                           throws java.sql.SQLException

    getTypeMap

    public java.util.Map getTypeMap()
                             throws java.sql.SQLException

    setTypeMap

    public void setTypeMap(java.util.Map map)
                    throws java.sql.SQLException

    getUsername

    public java.lang.String getUsername()

    setUsername

    public void setUsername(java.lang.String username)

    getPassword

    public java.lang.String getPassword()

    setPassword

    public void setPassword(java.lang.String password)

    isConnectionError

    public boolean isConnectionError()

    setConnectionError

    public void setConnectionError(boolean connectionError)

    toString

    public java.lang.String toString()


    Copyright � 2002 Macromedia Corporation. All Rights Reserved.