|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Interface for transaction context implementations used by the application
context to manage database transactions. Application context reads
com.boylesoftware.cb2.txContext
application property, which
names a class that implements this interface, and uses it as transaction
context with its transaction management methods.
When a new thread tries to perform a transactional database operation,
the application context checks if it already has a transaction context
object instance associated with it and if not, creates an instance of
transaction context and binds it to the thread. Right after the new
instance is created the application context calls setup
on it
and then other methods are called according to the protocol. The instance
stays bound to the thread until the thread dies.
There are also transaction management methods in the application context that operate on transaction contexts that are not bound to any thread.
Note, that implementations should be thread-safe providing their own means of access synchronization. Multiple threads can be trying to call different methods at the same time.
CB2 has several standard transaction context implementations. See
description of com.boylesoftware.cb2.txContext
application
property in the ApplicationContext
class description.
Field Summary | |
static java.lang.String |
LOG_SUBSYS
Channel name for the logger. |
Method Summary | |
void |
begin()
Begin a new transaction. |
boolean |
commit()
Commit the transaction. |
java.sql.Connection |
getConnection(java.lang.String dataSourceName)
Get a database connection managed by this transaction context. |
boolean |
isActive()
Tells if there is an active transaction at the moment of the call. |
boolean |
isRollbackOnly()
Tells if the transaction is marked for rollback only. |
boolean |
rollback()
Rollback the transaction. |
void |
setRollbackOnly()
Marks the transaction for rollback only. |
void |
setup(ApplicationContext appCtx)
Setup the instance before using it. |
boolean |
supportsUnboundTransactions()
Tells if this implementation supports transaction contexts that are not bound to a thread. |
Field Detail |
public static final java.lang.String LOG_SUBSYS
Method Detail |
public void setup(ApplicationContext appCtx) throws ApplicationException
appCtx
- the application context.
ApplicationException
- if an error happens.public void begin() throws ApplicationException
ApplicationException
- if an error happens, if there is already
an active transaction and the transaction context does not support
nested transactions.public java.sql.Connection getConnection(java.lang.String dataSourceName) throws java.sql.SQLException
begin
and
commit
or rollback
method calls, that is
when transaction is active.
dataSourceName
- logical name of the datasource, from which
to get the connection.
java.sql.SQLException
- if the connection cannnot be retrieved due
to the underlying data source error.
java.lang.IllegalStateException
- if the transaction is not
ative. In other words if the transaction has not been begun or
is already committed or rolled back.public boolean commit() throws ApplicationException
true
if there are no active transactions anymore
after successful commit. Can return false
if nested
transactions are supported and there are still active transactions
in the stack after committing the topmost one.
ApplicationException
- when the underlying subsystem
error happens.
java.lang.IllegalStateException
- if the transaction is not
ative. In other words if the transaction has not been begun or
is already committed or rolledback.public boolean rollback() throws ApplicationException
true
if there are no active transactions anymore
after successful rollback. Can return false
if nested
transactions are supported and there are still active transactions
in the stack after rolling back the topmost one.
ApplicationException
- when the underlying subsystem
error happens.
java.lang.IllegalStateException
- if the transaction is not
ative. In other words if the transaction has not been begun or
is already committed or rolledback.public void setRollbackOnly() throws ApplicationException
ApplicationException
- when the underlying subsystem
error happens.public boolean isRollbackOnly() throws ApplicationException
true
if the transaction is marked for
rollback only. Always returns false
if there are no
active transactions.
ApplicationException
- when the underlying subsystem
error happens.setRollbackOnly()
public boolean isActive()
true
if the transaction is active.public boolean supportsUnboundTransactions()
true
if unbound transaction contexts can be
created.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |