public interface TransactionCallback
Session will send corresponding events
to the TransactionCallback. An ObjectGrid can have zero or one
TransactionCallback. BackingMaps defined on an ObjectGrid with
a TransactionCallback should have corresponding Loaders.
A TransactionCallback works with Loaders and place transaction
specific objects in slots on the TxID object that
Loaders can obtain. Examples are database connections, prepared
statement caches, etc. The TransactionCallback should reserve slots in the
TxID by calling ObjectGrid.reserveSlot(String)
using the name TxID.SLOT_NAME. The TransactionCallback can then
put an object at that index in the TxID. A Loader
can retrieve the index used by the TransactionCallback by
calling an internal method on the TransactionCallback's
implementation. A reference to the configured TransactionCallback
can be found using the
TxID.getSession().getObjectGrid().getTransactionCallback()
code sequence.
A TransactionCallback implementation that also implements the ObjectGridLifecycleListener
interface will be automatically added as an EventListener on the ObjectGrid when the
callback is set on the object grid.
A TransactionCallback may implement the ObjectGridPlugin interface in order
to receive enhanced ObjectGrid plug-in lifecycle method calls. The plug-in is
also required to correctly implement each of the bean methods related to
introspection of its state (for example isInitialized(),
isDestroyed(), etc).
| Modifier and Type | Interface and Description |
|---|---|
static interface |
TransactionCallback.BeforeCommit
The BeforeCommit optional mix-in interface for the TransactionCallback plug-in interface allows plug-ins to be
notified at the beginning of a
Session.commit(). |
| Modifier and Type | Method and Description |
|---|---|
void |
begin(TxID id)
Invoked when starting a Session transaction.
|
void |
commit(TxID id)
Invoked when committing a Session transaction.
|
void |
initialize(ObjectGrid objectGrid)
Invoked when an
ObjectGrid is initialized. |
boolean |
isExternalTransactionActive(Session session)
Called when an application attempts to use a Session with no transaction
active.
|
void |
rollback(TxID id)
Invoked when rolling back a Session transaction.
|
void initialize(ObjectGrid objectGrid) throws TransactionCallbackException
ObjectGrid is initialized.
This method is called so this object can do any implementation specific intialization.
objectGrid - A reference to the ObjectGrid.TransactionCallbackException - if an error occurs during processingObjectGrid.reserveSlot(String)void begin(TxID id) throws TransactionCallbackException
A TransactionCallback can communicate the begin processing (along with the TxID) to the appropriate BackingMap and/or Loader. The Loader may use this signal to start a corresponding transaction on the underlying connection to a database.
id - transaction identifer (TxID)TransactionCallbackException - if an error occurs during processingSession.begin(),
Session.beginNoWriteThrough(),
TxIDvoid commit(TxID id) throws TransactionCallbackException
This method should be used to commit any underlying transaction and return any underlying connection back to the pool. The TxID is provided to determine which transaction is being committed
id - transaction identifier (TxID)TransactionCallbackException - if an error occurs during processingbegin(TxID),
Session.commit(),
TxIDvoid rollback(TxID id) throws TransactionCallbackException
This method should be used to roll back any underlying transaction and return any underlying connection back to the pool. The TxID is provided to determine which transaction is being committed
id - transaction identifier (TxID)TransactionCallbackException - if an error occurs during processingbegin(TxID),
Session.rollback(),
TxIDboolean isExternalTransactionActive(Session session)
The callback could return true in which case an auto
Session.begin() is executed. If false is
returned, an application exception is thrown indicating no transaction
is active. This event is usually used when integrating with a J2EE
environment such as WebSphere Application Server.
session - the session which the application is usingtrue if an auto begin should be done,
false if this is not the caseSession