org.hibernate.jdbc
Class ConnectionManager

java.lang.Object
  extended byorg.hibernate.jdbc.ConnectionManager
All Implemented Interfaces:
Serializable

public class ConnectionManager
extends Object
implements Serializable

Encapsulates JDBC Connection management logic needed by Hibernate.

The lifecycle is intended to span a logical series of interactions with the database. Internally, this means the the lifecycle of the Session.

Author:
Steve Ebersole
See Also:
Serialized Form

Nested Class Summary
static interface ConnectionManager.Callback
           
 
Constructor Summary
ConnectionManager(SessionFactoryImplementor factory, ConnectionManager.Callback callback, ConnectionReleaseMode releaseMode, Connection connection)
          Constructs a ConnectionManager.
 
Method Summary
 void afterStatement()
          To be called after execution of each JDBC statement.
 void afterTransaction()
          To be called after local transaction completion.
 Connection close()
          To be called after Session completion.
protected  void finalize()
          Just in case user forgot to commit()/cancel() or close()
 Batcher getBatcher()
          The batcher managed by this ConnectionManager.
 Connection getConnection()
          Retreives the connection currently managed by this ConnectionManager.
 SessionFactoryImplementor getFactory()
          The session factory.
 boolean isAutoCommit()
          Is the connection considered "auto-commit"?
 boolean isLogicallyConnected()
          Is this ConnectionManager instance "logically" connected.
 boolean isPhysicallyConnected()
          Is theis ConnectionManager instance "physically" connection.
 Connection manualDisconnect()
          Manually disconnect the underlying JDBC Connection.
 void manualReconnect()
          Manually reconnect the underlying JDBC Connection.
 void manualReconnect(Connection suppliedConnection)
          Manually reconnect the underlying JDBC Connection.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConnectionManager

public ConnectionManager(SessionFactoryImplementor factory,
                         ConnectionManager.Callback callback,
                         ConnectionReleaseMode releaseMode,
                         Connection connection)
Constructs a ConnectionManager.

This is the form used internally.

Parameters:
factory - The SessionFactory.
callback - An observer for internal state change.
releaseMode - The mode by which to release JDBC connections.
connection - An externally supplied connection.
Method Detail

getFactory

public SessionFactoryImplementor getFactory()
The session factory.

Returns:
the session factory.

getBatcher

public Batcher getBatcher()
The batcher managed by this ConnectionManager.

Returns:
The batcher.

getConnection

public Connection getConnection()
                         throws HibernateException
Retreives the connection currently managed by this ConnectionManager.

Note, that we may need to obtain a connection to return here if a connection has either not yet been obtained (non-UserSuppliedConnectionProvider) or has previously been aggressively released (if supported in this environment).

Returns:
The current Connection.
Throws:
HibernateException - Indicates a connection is currently not available (we are currently manually disconnected).

isAutoCommit

public boolean isAutoCommit()
                     throws SQLException
Is the connection considered "auto-commit"?

Returns:
True if we either do not have a connection, or the connection really is in auto-commit mode.
Throws:
SQLException - Can be thrown by the Connection.isAutoCommit() check.

isLogicallyConnected

public boolean isLogicallyConnected()
Is this ConnectionManager instance "logically" connected. Meaning do we either have a cached connection available or do we have the ability to obtain a connection on demand.

Returns:
True if logically connected; false otherwise.

isPhysicallyConnected

public boolean isPhysicallyConnected()
Is theis ConnectionManager instance "physically" connection. Meaning do have currently actually have a cached connection.

Returns:
True if physically connected; false otherwise.

afterStatement

public void afterStatement()
To be called after execution of each JDBC statement. Used to conditionally release the JDBC connection aggressively if the configured release mode indicates.


afterTransaction

public void afterTransaction()
To be called after local transaction completion. Used to conditionally release the JDBC connection aggressivley if the configured release mode indicates.


close

public Connection close()
To be called after Session completion. Used to release the JDBC connection.

Returns:
The connection mantained here at time of close. Null if there was no connection cached internally.

manualDisconnect

public Connection manualDisconnect()
Manually disconnect the underlying JDBC Connection. The assumption here is that the manager will be reconnected at a later point in time.

Returns:
The connection mantained here at time of disconnect. Null if there was no connection cached internally.

manualReconnect

public void manualReconnect()
Manually reconnect the underlying JDBC Connection. Should be called at some point after manualDisconnect().

This form is used for ConnectionProvider-supplied connections.


manualReconnect

public void manualReconnect(Connection suppliedConnection)
Manually reconnect the underlying JDBC Connection. Should be called at some point after manualDisconnect().

This form is used for user-supplied connections.


finalize

protected void finalize()
                 throws Throwable
Just in case user forgot to commit()/cancel() or close()

Throws:
Throwable