Top Description Inners Fields Constructors Methods
org.hibernate.jdbc

public Class ConnectionManager

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serializable, java.sql.Connection, .SQLException, org.slf4j.Logger, .LoggerFactory, org.hibernate.ConnectionReleaseMode, .HibernateException, .Interceptor, org.hibernate.engine.SessionFactoryImplementor, org.hibernate.exception.JDBCExceptionHelper, org.hibernate.util.JDBCExceptionReporter

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
private transient Batcher
private transient Connection
private final ConnectionManager.Callback
private transient Connection
private transient SessionFactoryImplementor
private transient Interceptor
private boolean
private transient boolean
private static final Logger
private final ConnectionReleaseMode
private final boolean

Constructor Summary

AccessConstructor and Description
public
ConnectionManager(SessionFactoryImplementor
The SessionFactory.
factory
,
ConnectionManager.Callback
An observer for internal state change.
callback
,
ConnectionReleaseMode
The mode by which to release JDBC connections.
releaseMode
,
Connection
An externally supplied connection.
connection
,
Interceptor interceptor)

Constructs a ConnectionManager.

private
ConnectionManager(SessionFactoryImplementor factory, ConnectionManager.Callback callback, ConnectionReleaseMode releaseMode, Interceptor interceptor, boolean wasConnectionSupplied, boolean isClosed)

Private constructor used exclusively from custom serialization

Method Summary

Modifier and TypeMethod and Description
public void
afterStatement()

To be called after execution of each JDBC statement.

public void
afterTransaction()

To be called after local transaction completion.

private void
aggressiveRelease()

Performs actions required to perform an aggressive release of the JDBC Connection.

public Connection
private Connection

Returns:

The released connection.
cleanup
()

Releases the Connection and cleans up any resources associated with that Connection.

public Connection

Returns:

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

To be called after Session completion.

private void
closeConnection()

Physically closes the JDBC Connection.

public static ConnectionManager
deserialize(ObjectInputStream ois, SessionFactoryImplementor factory, Interceptor interceptor, ConnectionReleaseMode connectionReleaseMode, JDBCContext jdbcContext)

public void
flushBeginning()

Callback to let us know that a flush is beginning.

public void
flushEnding()

Callback to let us know that a flush is ending.

public Batcher

Returns:

The batcher.
getBatcher
()

The batcher managed by this ConnectionManager.

public Connection

Returns:

The current Connection.
getConnection
()

Retrieves the connection currently managed by this ConnectionManager.

public SessionFactoryImplementor

Returns:

the session factory.
getFactory
()

The session factory.

public boolean
private boolean
public boolean

Returns:

True if the connections will be released after each statement; false otherwise.
isAggressiveRelease
()

Will connections be released after each statement execution?

private boolean

Returns:

True if the connections will be released after each statement; false otherwise.
isAggressiveReleaseNoTransactionCheck
()

Modified version of isAggressiveRelease which does not force a transaction check.

public boolean

Returns:

True if we either do not have a connection, or the connection really is in auto-commit mode.
isAutoCommit
()

Is the connection considered "auto-commit"?

public boolean

Returns:

True if logically connected; false otherwise.
isCurrentlyConnected
()

Is this ConnectionManager instance "logically" connected.

private boolean
public boolean
public boolean

Returns:

True if the user supplied the JDBC connection; false otherwise
isSuppliedConnection
()

Was the connection being used here supplied by the user?

public Connection

Returns:

The connection mantained here at time of disconnect. Null if there was no connection cached internally.
manualDisconnect
()

Manually disconnect the underlying JDBC Connection.

public void
manualReconnect()

Manually reconnect the underlying JDBC Connection.

public void
manualReconnect(Connection suppliedConnection)

Manually reconnect the underlying JDBC Connection.

private void
openConnection()

Pysically opens a JDBC Connection.

private void
readObject(ObjectInputStream
The stream from which we are being read.
ois
)

Used during deserialization.

public void
public void
private void
writeObject(ObjectOutputStream
The stream to which we are being written.
oos
)

Used during serialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

batcherback to summary
private transient Batcher batcher
borrowedConnectionback to summary
private transient Connection borrowedConnection
callbackback to summary
private final ConnectionManager.Callback callback
connectionback to summary
private transient Connection connection
factoryback to summary
private transient SessionFactoryImplementor factory
interceptorback to summary
private transient Interceptor interceptor
isClosedback to summary
private boolean isClosed
isFlushingback to summary
private transient boolean isFlushing
logback to summary
private static final Logger log
releaseModeback to summary
private final ConnectionReleaseMode releaseMode
wasConnectionSuppliedback to summary
private final boolean wasConnectionSupplied

Constructor Detail

ConnectionManagerback to summary
public ConnectionManager(SessionFactoryImplementor factory, ConnectionManager.Callback callback, ConnectionReleaseMode releaseMode, Connection connection, Interceptor interceptor)

Constructs a ConnectionManager.

This is the form used internally.

Parameters
factory:SessionFactoryImplementor

The SessionFactory.

callback:ConnectionManager.Callback

An observer for internal state change.

releaseMode:ConnectionReleaseMode

The mode by which to release JDBC connections.

connection:Connection

An externally supplied connection.

ConnectionManagerback to summary
private ConnectionManager(SessionFactoryImplementor factory, ConnectionManager.Callback callback, ConnectionReleaseMode releaseMode, Interceptor interceptor, boolean wasConnectionSupplied, boolean isClosed)

Private constructor used exclusively from custom serialization

Method Detail

afterStatementback to summary
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.

afterTransactionback to summary
public void afterTransaction()

To be called after local transaction completion. Used to conditionally release the JDBC connection aggressively if the configured release mode indicates.

aggressiveReleaseback to summary
private void aggressiveRelease()

Performs actions required to perform an aggressive release of the JDBC Connection.

borrowConnectionback to summary
public Connection borrowConnection()
cleanupback to summary
private Connection cleanup() throws HibernateException

Releases the Connection and cleans up any resources associated with that Connection. This is intended for use: 1) at the end of the session 2) on a manual disconnect of the session 3) from afterTransaction(), in the case of skipped aggressive releasing

Returns:Connection

The released connection.

closeback to summary
public Connection close()

To be called after Session completion. Used to release the JDBC connection.

Returns:Connection

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

closeConnectionback to summary
private void closeConnection()

Physically closes the JDBC Connection.

deserializeback to summary
public static ConnectionManager deserialize(ObjectInputStream ois, SessionFactoryImplementor factory, Interceptor interceptor, ConnectionReleaseMode connectionReleaseMode, JDBCContext jdbcContext) throws IOException
flushBeginningback to summary
public void flushBeginning()

Callback to let us know that a flush is beginning. We use this fact to temporarily circumvent aggressive connection releasing until after the flush cycle is complete flushEnding()

flushEndingback to summary
public void flushEnding()

Callback to let us know that a flush is ending. We use this fact to stop circumventing aggressive releasing connections.

getBatcherback to summary
public Batcher getBatcher()

The batcher managed by this ConnectionManager.

Returns:Batcher

The batcher.

getConnectionback to summary
public Connection getConnection() throws HibernateException

Retrieves 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:Connection

The current Connection.

Exceptions
HibernateException:
Indicates a connection is currently not available (we are currently manually disconnected).
getFactoryback to summary
public SessionFactoryImplementor getFactory()

The session factory.

Returns:SessionFactoryImplementor

the session factory.

hasBorrowedConnectionback to summary
public boolean hasBorrowedConnection()
isAfterTransactionReleaseback to summary
private boolean isAfterTransactionRelease()
isAggressiveReleaseback to summary
public boolean isAggressiveRelease()

Will connections be released after each statement execution?

Connections will be released after each statement if either:

isAggressiveReleaseNoTransactionCheckback to summary
private boolean isAggressiveReleaseNoTransactionCheck()

Modified version of isAggressiveRelease which does not force a transaction check. This is solely used from our afterTransaction callback, so no need to do the check; plus it seems to cause problems on websphere (god i love websphere ;)

It uses this information to decide if an aggressive release was skipped do to open resources, and if so forces a release.
Returns:boolean

True if the connections will be released after each statement; false otherwise.

isAutoCommitback to summary
public boolean isAutoCommit() throws SQLException

Is the connection considered "auto-commit"?

Returns:boolean

True if we either do not have a connection, or the connection really is in auto-commit mode.

Exceptions
SQLException:
Can be thrown by the Connection.isAutoCommit() check.
isCurrentlyConnectedback to summary
public boolean isCurrentlyConnected()

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:boolean

True if logically connected; false otherwise.

isOnCloseReleaseback to summary
private boolean isOnCloseRelease()
isReadyForSerializationback to summary
public boolean isReadyForSerialization()
isSuppliedConnectionback to summary
public boolean isSuppliedConnection()

Was the connection being used here supplied by the user?

Returns:boolean

True if the user supplied the JDBC connection; false otherwise

manualDisconnectback to summary
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:Connection

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

manualReconnectback to summary
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.

manualReconnectback to summary
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.

openConnectionback to summary
private void openConnection() throws HibernateException

Pysically opens a JDBC Connection.

readObjectback to summary
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException

Used during deserialization.

Parameters
ois:ObjectInputStream

The stream from which we are being read.

Exceptions
IOException:
Indicates an I/O error reading the stream
ClassNotFoundException:
Indicates resource class resolution.
releaseBorrowedConnectionback to summary
public void releaseBorrowedConnection()
serializeback to summary
public void serialize(ObjectOutputStream oos) throws IOException
writeObjectback to summary
private void writeObject(ObjectOutputStream oos) throws IOException

Used during serialization.

Parameters
oos:ObjectOutputStream

The stream to which we are being written.

Exceptions
IOException:
Indicates an I/O error writing to the stream
org.hibernate.jdbc back to summary

public Interface ConnectionManager.Callback

Known Direct Implementers
org.hibernate.jdbc.JDBCContext

Method Summary

Modifier and TypeMethod and Description
public void
public void
public boolean

Method Detail

connectionCleanedUpback to summary
public void connectionCleanedUp()
connectionOpenedback to summary
public void connectionOpened()
isTransactionInProgressback to summary
public boolean isTransactionInProgress()