Package org.hibernate.jdbc
Class ConnectionManager
java.lang.Object
org.hibernate.jdbc.ConnectionManager
- All Implemented Interfaces:
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.
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionConnectionManager(SessionFactoryImplementor factory, ConnectionManager.Callback callback, ConnectionReleaseMode releaseMode, Connection connection, Interceptor interceptor) Constructs a ConnectionManager. -
Method Summary
Modifier and TypeMethodDescriptionvoidTo be called after execution of each JDBC statement.voidTo be called after local transaction completion.close()To be called after Session completion.static ConnectionManagerdeserialize(ObjectInputStream ois, SessionFactoryImplementor factory, Interceptor interceptor, ConnectionReleaseMode connectionReleaseMode, JDBCContext jdbcContext) voidCallback to let us know that a flush is beginning.voidCallback to let us know that a flush is ending.The batcher managed by this ConnectionManager.Retrieves the connection currently managed by this ConnectionManager.The session factory.booleanbooleanWill connections be released after each statement execution?booleanIs the connection considered "auto-commit"?booleanIs this ConnectionManager instance "logically" connected.booleanbooleanWas the connection being used here supplied by the user?Manually disconnect the underlying JDBC Connection.voidManually reconnect the underlying JDBC Connection.voidmanualReconnect(Connection suppliedConnection) Manually reconnect the underlying JDBC Connection.voidvoid
-
Constructor Details
-
ConnectionManager
public ConnectionManager(SessionFactoryImplementor factory, ConnectionManager.Callback callback, ConnectionReleaseMode releaseMode, Connection connection, Interceptor interceptor) 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 Details
-
getFactory
The session factory.- Returns:
- the session factory.
-
getBatcher
The batcher managed by this ConnectionManager.- Returns:
- The batcher.
-
isSuppliedConnection
public boolean isSuppliedConnection()Was the connection being used here supplied by the user?- Returns:
- True if the user supplied the JDBC connection; false otherwise
-
getConnection
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:
- The current Connection.
- Throws:
HibernateException- Indicates a connection is currently not available (we are currently manually disconnected).
-
hasBorrowedConnection
public boolean hasBorrowedConnection() -
borrowConnection
-
releaseBorrowedConnection
public void releaseBorrowedConnection() -
isAutoCommit
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.
-
isAggressiveRelease
public boolean isAggressiveRelease()Will connections be released after each statement execution? Connections will be released after each statement if either:- the defined release-mode is
ConnectionReleaseMode.AFTER_STATEMENT; or - the defined release-mode is
ConnectionReleaseMode.AFTER_TRANSACTIONbut we are in auto-commit mode. release-mode =ConnectionReleaseMode.ON_CLOSEshould [b]never[/b] release a connection.
- Returns:
- True if the connections will be released after each statement; false otherwise.
- the defined release-mode is
-
isCurrentlyConnected
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:
- True if logically 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 aggressively if the configured release mode indicates. -
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
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
Manually reconnect the underlying JDBC Connection. Should be called at some point after manualDisconnect(). This form is used for user-supplied connections. -
flushBeginning
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 completeflushEnding() -
flushEnding
public void flushEnding()Callback to let us know that a flush is ending. We use this fact to stop circumventing aggressive releasing connections. -
isReadyForSerialization
public boolean isReadyForSerialization() -
serialize
- Throws:
IOException
-
deserialize
public static ConnectionManager deserialize(ObjectInputStream ois, SessionFactoryImplementor factory, Interceptor interceptor, ConnectionReleaseMode connectionReleaseMode, JDBCContext jdbcContext) throws IOException - Throws:
IOException
-