C
- the Connection typepublic class ManagedConnection<C extends java.sql.Connection> extends DelegatingConnection<C>
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.
Modifier and Type | Class and Description |
---|---|
protected class |
ManagedConnection.CompletionListener
Delegates to
transactionComplete() for transaction completion events. |
Constructor and Description |
---|
ManagedConnection(ObjectPool<C> pool,
TransactionRegistry transactionRegistry,
boolean accessToUnderlyingConnectionAllowed)
Constructs a new instance responsible for managing a database connection in a transactional environment.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkOpen() |
void |
close()
Closes the underlying connection, and close any Statements that were not explicitly closed.
|
void |
commit() |
C |
getDelegate()
Returns my underlying
Connection . |
java.sql.Connection |
getInnermostDelegate()
If my underlying
Connection is not a DelegatingConnection , returns it, otherwise recursively
invokes this method on my delegate. |
boolean |
isAccessToUnderlyingConnectionAllowed()
If false, getDelegate() and getInnermostDelegate() will return null.
|
void |
rollback() |
void |
setAutoCommit(boolean autoCommit) |
void |
setReadOnly(boolean readOnly) |
protected void |
transactionComplete() |
abort, activate, clearCachedState, clearWarnings, closeInternal, createArrayOf, createBlob, createClob, createNClob, createSQLXML, createStatement, createStatement, createStatement, createStruct, getAutoCommit, getCacheState, getCatalog, getClientInfo, getClientInfo, getDefaultQueryTimeout, getDelegateInternal, getHoldability, getInnermostDelegateInternal, getMetaData, getNetworkTimeout, getSchema, getTransactionIsolation, getTypeMap, getWarnings, handleException, innermostDelegateEquals, isClosed, isClosedInternal, isReadOnly, isValid, isWrapperFor, nativeSQL, passivate, prepareCall, prepareCall, prepareCall, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, prepareStatement, releaseSavepoint, rollback, setCacheState, setCatalog, setClientInfo, setClientInfo, setClosedInternal, setDefaultQueryTimeout, setDelegate, setHoldability, setNetworkTimeout, setSavepoint, setSavepoint, setSchema, setTransactionIsolation, setTypeMap, toString, unwrap
addTrace, clearTrace, getLastUsed, getTrace, removeTrace, setLastUsed, setLastUsed
public ManagedConnection(ObjectPool<C> pool, TransactionRegistry transactionRegistry, boolean accessToUnderlyingConnectionAllowed) throws java.sql.SQLException
pool
- The connection pool.transactionRegistry
- The transaction registry.accessToUnderlyingConnectionAllowed
- Whether or not to allow access to the underlying Connection.java.sql.SQLException
- Thrown when there is problem managing transactions.protected void checkOpen() throws java.sql.SQLException
checkOpen
in class DelegatingConnection<C extends java.sql.Connection>
java.sql.SQLException
public void close() throws java.sql.SQLException
DelegatingConnection
false
close
in interface java.lang.AutoCloseable
close
in interface java.sql.Connection
close
in class DelegatingConnection<C extends java.sql.Connection>
java.sql.SQLException
protected void transactionComplete()
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException
setAutoCommit
in interface java.sql.Connection
setAutoCommit
in class DelegatingConnection<C extends java.sql.Connection>
java.sql.SQLException
public void commit() throws java.sql.SQLException
commit
in interface java.sql.Connection
commit
in class DelegatingConnection<C extends java.sql.Connection>
java.sql.SQLException
public void rollback() throws java.sql.SQLException
rollback
in interface java.sql.Connection
rollback
in class DelegatingConnection<C extends java.sql.Connection>
java.sql.SQLException
public void setReadOnly(boolean readOnly) throws java.sql.SQLException
setReadOnly
in interface java.sql.Connection
setReadOnly
in class DelegatingConnection<C extends java.sql.Connection>
java.sql.SQLException
public boolean isAccessToUnderlyingConnectionAllowed()
public C getDelegate()
DelegatingConnection
Connection
.getDelegate
in class DelegatingConnection<C extends java.sql.Connection>
Connection
.public java.sql.Connection getInnermostDelegate()
DelegatingConnection
Connection
is not a DelegatingConnection
, returns it, otherwise recursively
invokes this method on my delegate.
Hence this method will return the first delegate that is not a DelegatingConnection
, or null
when
no non-DelegatingConnection
delegate can be found by traversing this chain.
This method is useful when you may have nested DelegatingConnection
s, and you want to make sure to obtain
a "genuine" Connection
.
getInnermostDelegate
in class DelegatingConnection<C extends java.sql.Connection>
Copyright © 2000-1970 Apache Software Foundation. All Rights Reserved.