java.lang.Object
org.apache.derby.impl.jdbc.TransactionResourceImpl
- public final class TransactionResourceImpl
- extends java.lang.Object
An instance of a TransactionResourceImpl is a bundle of things that
connects a connection to the database - it is the transaction "context" in
a generic sense. It is also the object of synchronization used by the
connection object to make sure only one thread is accessing the underlying
transaction and context.
TransactionResourceImpl not only serves as a transaction "context", it
also takes care of:
- context management: the pushing and popping of the context manager in
and out of the global context service
- transaction demarcation: all calls to commit/abort/prepare/close a
transaction must route thru the transaction resource.
- error handling
The only connection that have access to the TransactionResource is the
root connection, all other nested connections (called proxyConnection)
accesses the TransactionResource via the root connection. The root
connection may be a plain EmbedConnection, or a DetachableConnection (in
case of a XATransaction). A nested connection must be a ProxyConnection.
A proxyConnection is not detachable and can itself be a XA connection -
although an XATransaction may start nested local (proxy) connections.
this is an example of how all the objects in this package relate to each
other. In this example, the connection is nested 3 deep.
DetachableConnection.
lcc cm database jdbcDriver
^ ^ ^ ^
| | | |
|======================|
| TransactionResource |
|======================|
^ |
| |
| | |---------------rootConnection----------|
| | | |
| | |- rootConnection-| |
| | | | |
| V V | |
|========================| |=================| |=================|
| EmbedConnection | | EmbedConnection | | EmbedConnection |
| |<-----| |<-----| |
| (DetachableConnection) | | ProxyConnection | | ProxyConnection |
|========================| |=================| |=================|
^ | ^ ^ ^
| | | | |
---rootConnection-- | | |
| | |
| | |
|======================| |======================| |======================|
| ConnectionChild | | ConnectionChild | | ConnectionChild |
| | | | | |
| (EmbedStatement) | | (EmbedResultSet) | | (...) |
|======================| |======================| |======================|
A plain local connection must be attached (doubly linked with) to a
TransactionResource at all times. A detachable connection can be without a
TransactionResource, and a TransactionResource for an XATransaction
(called XATransactionResource) can be without a connection.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
cm
protected org.apache.derby.iapi.services.context.ContextManager cm
csf
protected org.apache.derby.iapi.services.context.ContextService csf
username
protected java.lang.String username
dbname
private java.lang.String dbname
driver
private org.apache.derby.jdbc.InternalDriver driver
url
private java.lang.String url
drdaID
private java.lang.String drdaID
database
protected org.apache.derby.iapi.db.Database database
lcc
protected org.apache.derby.iapi.sql.conn.LanguageConnectionContext lcc
TransactionResourceImpl
TransactionResourceImpl(org.apache.derby.jdbc.InternalDriver driver,
java.lang.String url,
java.util.Properties info)
throws java.sql.SQLException
setDatabase
void setDatabase(org.apache.derby.iapi.db.Database db)
startTransaction
void startTransaction()
throws org.apache.derby.iapi.error.StandardException,
java.sql.SQLException
getDriver
org.apache.derby.jdbc.InternalDriver getDriver()
getCsf
org.apache.derby.iapi.services.context.ContextService getCsf()
getContextManager
org.apache.derby.iapi.services.context.ContextManager getContextManager()
getLcc
org.apache.derby.iapi.sql.conn.LanguageConnectionContext getLcc()
getDBName
java.lang.String getDBName()
getUrl
java.lang.String getUrl()
getDatabase
org.apache.derby.iapi.db.Database getDatabase()
shutdownDatabaseException
org.apache.derby.iapi.error.StandardException shutdownDatabaseException()
commit
protected void commit()
throws org.apache.derby.iapi.error.StandardException
rollback
protected void rollback()
throws org.apache.derby.iapi.error.StandardException
clearContextInError
void clearContextInError()
- An error happens in the constructor, pop the context.
clearLcc
protected void clearLcc()
- Resolve: probably superfluous
setupContextStack
protected final void setupContextStack()
restoreContextStack
protected final void restoreContextStack()
handleException
protected final java.sql.SQLException handleException(java.lang.Throwable thrownException,
boolean autoCommit,
boolean rollbackOnAutoCommit)
throws java.sql.SQLException
wrapInSQLException
public static final java.sql.SQLException wrapInSQLException(java.sql.SQLException sqlException,
java.lang.Throwable thrownException)
getUserName
java.lang.String getUserName()
cleanupOnError
public boolean cleanupOnError(java.lang.Throwable e)
isIdle
public boolean isIdle()
isActive
boolean isActive()