IBM WebSphere Adapters User Manual page 111

Version 6 release 2
Table of Contents

Advertisement

3. Override method WBIManagedConnection.getLocalTransaction() and, if XA
support is provided, method WBIManagedConnection.getXAResource().
Wrap either or both of the LocalTransaction or XAResource instances returned by
these methods with a WBILocalTransactionWrapper or
WBIXATransacxtionWrapper instance, respectively. These wrappers provide
extended diagnostics for troubleshooting and also help adapters determine
whether or not to autocommit requests. According to the JCA 1.5 specification, a
resource adapter must autocommit transactions when being used outside the
context of a transaction. To help the managed connection determine if it is
involved in a transaction, these wrappers act as thin delegation layers, monitoring
the sequence of calls to determine whether a transaction is active. At the beginning
of a transaction, the wrappers call method setEnlistedInATransaction(true) on the
WBIManagedConnection instance; upon commit or rollback, the wrappers set this
same property to false. By then checking the status of the transaction via method
isEnlistedInTransaction on the super class, a WBIResourceAdapter subclass can
quickly determine whether it should be automatically committing transactions or
not when modifying the EIS.
Note: When overriding methods, do not invoke the super implementations of
these methods since the Adapter Foundation Classes simply throw exceptions for
these methods.
Example of an XA-enabled adapter implementation of
WBIManagedConnection
public class FooManagedConnection extends WBIManagedConnection
{
// just get the XAResource from your EIS and return the wrapper
XAResource eisXAResource = this.eisXAConnection.getXAResource();
XAResource wrapper = new WBIXATransactionWrapper(eisXAResource,this);
return wrapper;
}
// here's an example of a potentially transacted call on the EIS. Point
// is that adapter should always check whether it's enlisted in a
// container-managed transaction or whether it should handle transaction
// on its own
private void updateRecord(int id,int value) {
if(!this.isEnlistedInTransaction())
this.eisConnection.beginTransaction();
eisConnection.updateRecord(id,value);
if(!this.isEnlistedInTransaction())
this.eisConnection.commitTransaction();
}
}
Using command patterns
Command patterns simplify adapter development by providing generic logic for
dealing with hierarchical data structures.
Command patterns:
To enhance uniformity across adapters for outbound processing, support for
command patterns is provided by the CommandManager API in the Adapter
Foundation Classes.
public XAResource getXAResource() {
WebSphere Adapter development overview
105

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Websphere adapter toolkit

Table of Contents