When you use the WebSphereTransactionCallback plug-in, enterprise applications that are running in a WebSphere® Application Server environment can manage ObjectGrid transactions.
When you are using an ObjectGrid session within a method that is configured to use container-managed transactions, the enterprise container automatically begins, commits or rolls back the ObjectGrid transaction. When you are using Java™ Transaction API (JTA) UserTransaction objects, the ObjectGrid transaction is managed by the UserTransaction object automatically.
For a detailed discussion of the implementation of this plug-in, see External transaction managers
You can enable the WebSphereTransactionCallback into the ObjectGrid configuration with programmatic configuration or XML configuration.
The following XML configuration creates the WebSphereTransactionCallback object and adds it to an ObjectGrid. The following text must be in the myGrid.xml file:
<?xml version="1.0" encoding="UTF-8"?> <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd" xmlns="http://ibm.com/ws/objectgrid/config"> <objectGrids> <objectGrid name="myGrid"> <bean id="TransactionCallback" className= "com.ibm.websphere.objectgrid.plugins.builtins.WebSphereTransactionCallback" /> </objectGrid> </objectGrids> </objectGridConfig>
The following code snippet creates the WebSphereTransactionCallback object and adds it to an ObjectGrid:
ObjectGridManager objectGridManager = ObjectGridManagerFactory.getObjectGridManager(); ObjectGrid myGrid = objectGridManager.createObjectGrid("myGrid", false); WebSphereTransactionCallback wsTxCallback= new WebSphereTransactionCallback (); myGrid.setTransactionCallback(wsTxCallback);