Class ManagedConnection<C extends java.sql.Connection>
- java.lang.Object
- 
- org.apache.tomcat.dbcp.dbcp2.AbandonedTrace
- 
- org.apache.tomcat.dbcp.dbcp2.DelegatingConnection<C>
- 
- org.apache.tomcat.dbcp.dbcp2.managed.ManagedConnection<C>
 
 
 
- 
- Type Parameters:
- C- the Connection type
 - All Implemented Interfaces:
- java.lang.AutoCloseable,- java.sql.Connection,- java.sql.Wrapper,- TrackedUse
 
 public class ManagedConnection<C extends java.sql.Connection> extends DelegatingConnection<C> ManagedConnection is responsible for managing a database connection in a transactional environment (typically called "Container Managed"). A managed connection operates like any other connection when no global transaction (a.k.a. XA transaction or JTA Transaction) is in progress. When a global transaction is active a single physical connection to the database is used by all ManagedConnections accessed in the scope of the transaction. Connection sharing means that all data access during a transaction has a consistent view of the database. When the global transaction is committed or rolled back the enlisted connections are committed or rolled back. Typically upon transaction completion, a connection returns to the auto commit setting in effect before being enlisted in the transaction, but some vendors do not properly implement this.When enlisted in a transaction the setAutoCommit(), commit(), rollback(), and setReadOnly() methods throw a SQLException. This is necessary to assure that the transaction completes as a single unit. - Since:
- 2.0
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description protected classManagedConnection.CompletionListenerDelegates totransactionComplete()for transaction completion events.
 - 
Constructor SummaryConstructors Constructor Description ManagedConnection(ObjectPool<C> pool, TransactionRegistry transactionRegistry, boolean accessToUnderlyingConnectionAllowed)Constructs a new instance responsible for managing a database connection in a transactional environment.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckOpen()voidclose()Closes the underlying connection, and close any Statements that were not explicitly closed.voidcommit()CgetDelegate()Returns my underlyingConnection.java.sql.ConnectiongetInnermostDelegate()If my underlyingConnectionis not aDelegatingConnection, returns it, otherwise recursively invokes this method on my delegate.TransactionContextgetTransactionContext()TransactionRegistrygetTransactionRegistry()booleanisAccessToUnderlyingConnectionAllowed()If false, getDelegate() and getInnermostDelegate() will return null.voidrollback()voidsetAutoCommit(boolean autoCommit)voidsetReadOnly(boolean readOnly)protected voidtransactionComplete()Completes the transaction.- 
Methods inherited from class org.apache.tomcat.dbcp.dbcp2.DelegatingConnectionabort, activate, clearCachedState, clearWarnings, closeInternal, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDefaultQueryTimeoutDuration, getDelegateInternal, getHoldability, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleException, handleExceptionNoThrow, innermostDelegateEquals, isClosed, isClosedInternal, isReadOnly, isValid, isValid, isWrapperFor, nativeSQL, passivate, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setCacheState, setCatalog, setClientInfo, setClientInfo, setClosedInternal, setDefaultQueryTimeout, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, toString, unwrap
 - 
Methods inherited from class org.apache.tomcat.dbcp.dbcp2.AbandonedTraceaddTrace, clearTrace, close, getLastUsed, getLastUsedInstant, getTrace, removeThisTrace, removeTrace, setLastUsed, setLastUsed, setLastUsed
 
- 
 
- 
- 
- 
Constructor Detail- 
ManagedConnectionpublic ManagedConnection(ObjectPool<C> pool, TransactionRegistry transactionRegistry, boolean accessToUnderlyingConnectionAllowed) throws java.sql.SQLException Constructs a new instance responsible for managing a database connection in a transactional environment.- Parameters:
- pool- The connection pool.
- transactionRegistry- The transaction registry.
- accessToUnderlyingConnectionAllowed- Whether or not to allow access to the underlying Connection.
- Throws:
- java.sql.SQLException- Thrown when there is problem managing transactions.
 
 
- 
 - 
Method Detail- 
checkOpenprotected void checkOpen() throws java.sql.SQLException- Overrides:
- checkOpenin class- DelegatingConnection<C extends java.sql.Connection>
- Throws:
- java.sql.SQLException
 
 - 
closepublic void close() throws java.sql.SQLExceptionDescription copied from class:DelegatingConnectionCloses the underlying connection, and close any Statements that were not explicitly closed. Sub-classes that override this method must:- Call DelegatingConnection.passivate()
- Call close (or the equivalent appropriate action) on the wrapped connection
- Set closedtofalse
 - Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.sql.Connection
- Overrides:
- closein class- DelegatingConnection<C extends java.sql.Connection>
- Throws:
- java.sql.SQLException- Ignored here, for subclasses.
 
- Call 
 - 
commitpublic void commit() throws java.sql.SQLException- Specified by:
- commitin interface- java.sql.Connection
- Overrides:
- commitin class- DelegatingConnection<C extends java.sql.Connection>
- Throws:
- java.sql.SQLException
 
 - 
getDelegatepublic C getDelegate() Description copied from class:DelegatingConnectionReturns my underlyingConnection.- Overrides:
- getDelegatein class- DelegatingConnection<C extends java.sql.Connection>
- Returns:
- my underlying Connection.
 
 - 
getInnermostDelegatepublic java.sql.Connection getInnermostDelegate() Description copied from class:DelegatingConnectionIf my underlyingConnectionis not aDelegatingConnection, returns it, otherwise recursively invokes this method on my delegate.Hence this method will return the first delegate that is not a DelegatingConnection, ornullwhen no non-DelegatingConnectiondelegate can be found by traversing this chain.This method is useful when you may have nested DelegatingConnections, and you want to make sure to obtain a "genuine"Connection.- Overrides:
- getInnermostDelegatein class- DelegatingConnection<C extends java.sql.Connection>
- Returns:
- innermost delegate.
 
 - 
getTransactionContextpublic TransactionContext getTransactionContext() - Returns:
- The transaction context.
- Since:
- 2.6.0
 
 - 
getTransactionRegistrypublic TransactionRegistry getTransactionRegistry() - Returns:
- The transaction registry.
- Since:
- 2.6.0
 
 - 
isAccessToUnderlyingConnectionAllowedpublic boolean isAccessToUnderlyingConnectionAllowed() If false, getDelegate() and getInnermostDelegate() will return null.- Returns:
- if false, getDelegate() and getInnermostDelegate() will return null
 
 - 
rollbackpublic void rollback() throws java.sql.SQLException- Specified by:
- rollbackin interface- java.sql.Connection
- Overrides:
- rollbackin class- DelegatingConnection<C extends java.sql.Connection>
- Throws:
- java.sql.SQLException
 
 - 
setAutoCommitpublic void setAutoCommit(boolean autoCommit) throws java.sql.SQLException- Specified by:
- setAutoCommitin interface- java.sql.Connection
- Overrides:
- setAutoCommitin class- DelegatingConnection<C extends java.sql.Connection>
- Throws:
- java.sql.SQLException
 
 - 
setReadOnlypublic void setReadOnly(boolean readOnly) throws java.sql.SQLException- Specified by:
- setReadOnlyin interface- java.sql.Connection
- Overrides:
- setReadOnlyin class- DelegatingConnection<C extends java.sql.Connection>
- Throws:
- java.sql.SQLException
 
 - 
transactionCompleteprotected void transactionComplete() Completes the transaction.
 
- 
 
-