ehcache

net.sf.ehcache.transaction.xa
Class EhcacheXAResourceImpl

java.lang.Object
  extended by net.sf.ehcache.transaction.xa.EhcacheXAResourceImpl
All Implemented Interfaces:
javax.transaction.xa.XAResource, EhcacheXAResource

public class EhcacheXAResourceImpl
extends java.lang.Object
implements EhcacheXAResource

Default implementation for EhcacheXAResource. It encapsulates the store to be accessed in a transactional way, the TransactionManager and an EhcacheXAStore, where it'll save transaction data during the two-phase commit process, and between suspend/resume transaction cycles.

It'll also associate Transaction instances with their Xid

Author:
Nabib El-Rahman, Alex Snaps

Field Summary
 
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
 
Constructor Summary
EhcacheXAResourceImpl(Ehcache cache, javax.transaction.TransactionManager txnManager, EhcacheXAStore ehcacheXAStore)
          Constructor
 
Method Summary
 void addTwoPcExecutionListener(TwoPcExecutionListener listener)
          Add a listener which will be called back according to the 2PC lifecycle
 void commit(javax.transaction.xa.Xid xid, boolean onePhase)
          
 TransactionContext createTransactionContext()
          Obtain the already associated TransactionContext with the current Transaction, or create a new one should none be there yet.
 void end(javax.transaction.xa.Xid xid, int flags)
          
 boolean equals(java.lang.Object obj)
          
 void forget(javax.transaction.xa.Xid xid)
          
 java.lang.String getCacheName()
          Getter to the name of the cache wrapped by this XAResource
 TransactionContext getCurrentTransactionContext()
          Gets the current TransactionContext associated with this resource
 int getTransactionTimeout()
          
 int hashCode()
          
 boolean isSameRM(javax.transaction.xa.XAResource xaResource)
          
 int prepare(javax.transaction.xa.Xid xid)
          
 javax.transaction.xa.Xid[] recover(int flags)
          
 void rollback(javax.transaction.xa.Xid xid)
          
 boolean setTransactionTimeout(int timeout)
          
 void start(javax.transaction.xa.Xid xid, int flags)
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EhcacheXAResourceImpl

public EhcacheXAResourceImpl(Ehcache cache,
                             javax.transaction.TransactionManager txnManager,
                             EhcacheXAStore ehcacheXAStore)
Constructor

Parameters:
cache - The cache name of the Cache wrapped
txnManager - the TransactionManager associated with this XAResource
ehcacheXAStore - The EhcacheXAStore for this cache
Method Detail

addTwoPcExecutionListener

public void addTwoPcExecutionListener(TwoPcExecutionListener listener)
Add a listener which will be called back according to the 2PC lifecycle

Specified by:
addTwoPcExecutionListener in interface EhcacheXAResource
Parameters:
listener - the TwoPcExecutionListener

getCacheName

public java.lang.String getCacheName()
Getter to the name of the cache wrapped by this XAResource

Specified by:
getCacheName in interface EhcacheXAResource
Returns:
Ehcache.getName() value

start

public void start(javax.transaction.xa.Xid xid,
                  int flags)
           throws javax.transaction.xa.XAException

Specified by:
start in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

end

public void end(javax.transaction.xa.Xid xid,
                int flags)
         throws javax.transaction.xa.XAException

Specified by:
end in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

prepare

public int prepare(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException

Specified by:
prepare in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

forget

public void forget(javax.transaction.xa.Xid xid)
            throws javax.transaction.xa.XAException

Specified by:
forget in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

recover

public javax.transaction.xa.Xid[] recover(int flags)
                                   throws javax.transaction.xa.XAException

Specified by:
recover in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

commit

public void commit(javax.transaction.xa.Xid xid,
                   boolean onePhase)
            throws javax.transaction.xa.XAException

Specified by:
commit in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

rollback

public void rollback(javax.transaction.xa.Xid xid)
              throws javax.transaction.xa.XAException

Specified by:
rollback in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

isSameRM

public boolean isSameRM(javax.transaction.xa.XAResource xaResource)
                 throws javax.transaction.xa.XAException

Specified by:
isSameRM in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

setTransactionTimeout

public boolean setTransactionTimeout(int timeout)
                              throws javax.transaction.xa.XAException

Specified by:
setTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

getTransactionTimeout

public int getTransactionTimeout()
                          throws javax.transaction.xa.XAException

Specified by:
getTransactionTimeout in interface javax.transaction.xa.XAResource
Throws:
javax.transaction.xa.XAException

createTransactionContext

public TransactionContext createTransactionContext()
                                            throws javax.transaction.SystemException,
                                                   javax.transaction.RollbackException
Obtain the already associated TransactionContext with the current Transaction, or create a new one should none be there yet.

Specified by:
createTransactionContext in interface EhcacheXAResource
Returns:
The associated Transaction associated TransactionContext
Throws:
javax.transaction.SystemException - Thrown if the associated transaction manager encounters an unexpected error condition.
javax.transaction.RollbackException - Thrown if the resource has to be enlisted with the transaction, while it is marked for rollback only.

getCurrentTransactionContext

public TransactionContext getCurrentTransactionContext()
Gets the current TransactionContext associated with this resource

Specified by:
getCurrentTransactionContext in interface EhcacheXAResource
Returns:
the current TransactionContext, or null if none

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object

ehcache

true