Top Description Fields Constructors Methods
org.apache.derby.impl.jdbc

public final Class TransactionResourceImpl

extends Object
Class Inheritance
Imports
org.apache.derby.iapi.jdbc.InternalDriver, org.apache.derby.iapi.services.context.Context, .ContextService, .ContextManager, org.apache.derby.iapi.services.monitor.Monitor, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.db.Database, org.apache.derby.shared.common.error.StandardException, .ExceptionSeverity, org.apache.derby.iapi.sql.conn.LanguageConnectionContext, org.apache.derby.shared.common.reference.Attribute, .SQLState, .Property, org.apache.derby.iapi.util.StringUtil, .IdUtil, .InterruptStatus, java.util.Properties, java.sql.SQLException

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:

  1. context management: the pushing and popping of the context manager in and out of the global context service
  2. transaction demarcation: all calls to commit/abort/prepare/close a transaction must route thru the transaction resource.
  3. 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.

Field Summary

Modifier and TypeField and Description
protected ContextManager
protected ContextService
protected Database
private String
private String
private InternalDriver
protected LanguageConnectionContext
private String
protected String

Constructor Summary

AccessConstructor and Description
pack-priv
TransactionResourceImpl(InternalDriver driver, String url, Properties info)

create a brand new connection for a brand new transaction

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean

Returns:

true if the context manager is shutdown, false otherwise.
cleanupOnError
(Throwable
the error we want to clean up
e
,
boolean
true if extended diagnostics should be considered, false not interested of extended diagnostic information
diagActive
)

clean up error and print it to derby.log if diagActive is true

pack-priv void
clearContextInError()

An error happens in the constructor, pop the context.

pack-priv void
clearLcc()

Resolve

probably superfluous

pack-priv void
commit()

local transaction demarcation - note that global or xa transaction cannot commit thru the connection, they can only commit thru the XAResource, which uses the xa_commit or xa_rollback interface as a safeguard.

pack-priv ContextManager
getContextManager()

need to be public because it is in the XATransactionResource interface

pack-priv ContextService
pack-priv Database
pack-priv String
pack-priv InternalDriver
getDriver()

Return instance variables to EmbedConnection.

pack-priv LanguageConnectionContext
pack-priv String
pack-priv String
pack-priv final SQLException
handleException(Throwable thrownException, boolean autoCommit, boolean rollbackOnAutoCommit)

clean up the error and wrap the real exception in some SQLException.

pack-priv boolean
pack-priv boolean
private boolean

Returns:

true if this is a login failure exception
isLoginException
(Throwable thrownException)

Determine if the exception thrown is a login exception.

pack-priv final void
pack-priv void
pack-priv void
setDatabase(Database db)

Called only in EmbedConnection construtor.

pack-priv final void
pack-priv StandardException
pack-priv void
public static SQLException

Returns:

thrownException, if it is an SQLException; otherwise, an SQLException which wraps thrownException
wrapInSQLException
(Throwable
a Throwable
thrownException
)

Wrap a Throwable in an SQLException.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cmback to summary
protected ContextManager cm
csfback to summary
protected ContextService csf
databaseback to summary
protected Database database
dbnameback to summary
private String dbname
drdaIDback to summary
private String drdaID
driverback to summary
private InternalDriver driver
lccback to summary
protected LanguageConnectionContext lcc
urlback to summary
private String url
usernameback to summary
protected String username

Constructor Detail

TransactionResourceImplback to summary
pack-priv TransactionResourceImpl(InternalDriver driver, String url, Properties info) throws SQLException

create a brand new connection for a brand new transaction

Method Detail

cleanupOnErrorback to summary
pack-priv boolean cleanupOnError(Throwable e, boolean diagActive)

clean up error and print it to derby.log if diagActive is true

Parameters
e:Throwable

the error we want to clean up

diagActive:boolean

true if extended diagnostics should be considered, false not interested of extended diagnostic information

Returns:boolean

true if the context manager is shutdown, false otherwise.

clearContextInErrorback to summary
pack-priv void clearContextInError()

An error happens in the constructor, pop the context.

clearLccback to summary
pack-priv void clearLcc()

Resolve

probably superfluous

commitback to summary
pack-priv void commit() throws StandardException

local transaction demarcation - note that global or xa transaction cannot commit thru the connection, they can only commit thru the XAResource, which uses the xa_commit or xa_rollback interface as a safeguard.

getContextManagerback to summary
pack-priv ContextManager getContextManager()

need to be public because it is in the XATransactionResource interface

getCsfback to summary
pack-priv ContextService getCsf()
getDatabaseback to summary
pack-priv Database getDatabase()
getDBNameback to summary
pack-priv String getDBName()
getDriverback to summary
pack-priv InternalDriver getDriver()

Return instance variables to EmbedConnection.

Resolve

given time, we should perhaps stop giving out reference to these things but instead use the transaction resource itself.

getLccback to summary
pack-priv LanguageConnectionContext getLcc()
getUrlback to summary
pack-priv String getUrl()
getUserNameback to summary
pack-priv String getUserName()
handleExceptionback to summary
pack-priv final SQLException handleException(Throwable thrownException, boolean autoCommit, boolean rollbackOnAutoCommit) throws SQLException

clean up the error and wrap the real exception in some SQLException.

isActiveback to summary
pack-priv boolean isActive()
isIdleback to summary
pack-priv boolean isIdle()
isLoginExceptionback to summary
private boolean isLoginException(Throwable thrownException)

Determine if the exception thrown is a login exception. Needed for DERBY-5427 fix to prevent inappropriate thread dumps and javacores. This exception is special because it is SESSION_SEVERITY and database.isActive() is true, but the session hasn't started yet,so it is not an actual crash and should not report extended diagnostics.

Returns:boolean

true if this is a login failure exception

restoreContextStackback to summary
pack-priv final void restoreContextStack()
rollbackback to summary
pack-priv void rollback() throws StandardException
setDatabaseback to summary
pack-priv void setDatabase(Database db)

Called only in EmbedConnection construtor. The Local Connection sets up the database in its constructor and sets it here.

setupContextStackback to summary
pack-priv final void setupContextStack()
shutdownDatabaseExceptionback to summary
pack-priv StandardException shutdownDatabaseException()
startTransactionback to summary
pack-priv void startTransaction() throws StandardException, SQLException
wrapInSQLExceptionback to summary
public static SQLException wrapInSQLException(Throwable thrownException)

Wrap a Throwable in an SQLException.

Parameters
thrownException:Throwable

a Throwable

Returns:SQLException

thrownException, if it is an SQLException; otherwise, an SQLException which wraps thrownException