org.neo4j.kernel.impl.transaction.xaframework
Class XaConnectionHelpImpl

java.lang.Object
  extended by org.neo4j.kernel.impl.transaction.xaframework.XaConnectionHelpImpl
All Implemented Interfaces:
XaConnection
Direct Known Subclasses:
IndexXaConnection, NeoStoreXaConnection

public abstract class XaConnectionHelpImpl
extends Object
implements XaConnection

XaConnectionHelpImpl helps with basic implementation that is needed to fit a non XA compatible resource in the xaframework.

Put your methods that perform any transactional work towards the resource in your extention of this class. Create a instance of the XaResourceHelpImpl as your XAResource. Add a try-finally block in your work methods around the command creations and enlist/delist the XAResource with the transaction. Use the protected getTransaction method to get a XaTransaction and add your commands to the transaction. Here is an example implementation:

 
 public class MyConnection extends XaConnectionHelpImpl
 {
     private static class MyResource extends XaResourceHelpImpl
     {
         public boolean isSameRM( XAResource rm )
         {
             if ( rm instanceof MyResource )
             {
                 return true;
             }
             return false;
         }
     }
 
     private XaResource xaResource = new MyResource();
 
     public XaResource getXaResource()
     {
         return xaResource;
     }
 
     public void doWork1() throws SomeException
     {
         enlistResourceWithTx();
         try
         {
             getTransaction().addCommand( new Work1Command( params ) );
         }
         finally
         {
             delistResourceFromTx();
         }
     }
 }
 
 


Constructor Summary
XaConnectionHelpImpl(XaResourceManager xaRm)
           
 
Method Summary
 void clearAllTransactions()
          Will clear the resource manager of all transactions.
 void destroy()
          Destroys this connection and depending on XAResource implementation the work done on the resource will be rolled back, saved or committed (may also depend on transactional state).
protected  XaTransaction getTransaction()
          Returns the XaTransaction associated with this connection.
abstract  XAResource getXaResource()
          Returns the XAResource associated with this connection.
 void validate()
          Makes sure the resource is enlisted as active in the transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XaConnectionHelpImpl

public XaConnectionHelpImpl(XaResourceManager xaRm)
Method Detail

getXaResource

public abstract XAResource getXaResource()
Returns the XAResource associated with this connection.

Specified by:
getXaResource in interface XaConnection
Returns:
The XAResource for this connection

destroy

public void destroy()
Description copied from interface: XaConnection
Destroys this connection and depending on XAResource implementation the work done on the resource will be rolled back, saved or committed (may also depend on transactional state).

This method is only valid to call once and there after it is illegal to invoke getXaResource or any other method that creates transactions or performs work using the XAResource.

Specified by:
destroy in interface XaConnection

validate

public void validate()
              throws XAException
Makes sure the resource is enlisted as active in the transaction.

Throws:
XAException - If resource not enlisted or suspended

getTransaction

protected XaTransaction getTransaction()
                                throws XAException
Returns the XaTransaction associated with this connection. If transaction is already completed it will still be returned.

Returns:
The XaTransaction associated with this connection
Throws:
XAException - If the transaction hasn't completed and the resource isn't enlisted

clearAllTransactions

public void clearAllTransactions()
Will clear the resource manager of all transactions. Used for testing purpose only. Do not use this method unless you know what you're doing since it will corrupt the state between the resource and the global transaction manager.



Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.