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, TransactionManager txnManager, EhcacheXAStore ehcacheXAStore)
          Constructor
 
Method Summary
 void commit(javax.transaction.xa.Xid xid, boolean onePhase)
          
 void end(javax.transaction.xa.Xid xid, int flags)
          
 boolean equals(java.lang.Object obj)
          
 void forget(javax.transaction.xa.Xid xid)
          
 Element get(java.lang.Object key)
          Fall through methods to the underlying cache that will hit potential "guards" or "guarding read-only store"
 java.lang.String getCacheName()
          Getter to the name of the cache wrapped by this XAResource
 TransactionContext getOrCreateTransactionContext()
          Obtain the already associated TransactionContext with the current Transaction, or create a new one should none be there yet.
 Element getQuiet(java.lang.Object key)
          Fall through methods to the underlying cache that will hit potential "guards" or "guarding read-only store"
 Store getStore()
          Getter to the store wrapped by this XAResource
 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 i)
          
 void start(javax.transaction.xa.Xid xid, int flags)
          
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EhcacheXAResourceImpl

public EhcacheXAResourceImpl(Ehcache cache,
                             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

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 i)
                              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

getStore

public Store getStore()
Getter to the store wrapped by this XAResource

Specified by:
getStore in interface EhcacheXAResource
Returns:
the real underlying store (not the Transactional wrapper)

getOrCreateTransactionContext

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

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

get

public Element get(java.lang.Object key)
Fall through methods to the underlying cache that will hit potential "guards" or "guarding read-only store"

Specified by:
get in interface EhcacheXAResource
Parameters:
key - the key to the Element to obtain form the underlying store
Returns:
the Element associated with the key, or null

getQuiet

public Element getQuiet(java.lang.Object key)
Fall through methods to the underlying cache that will hit potential "guards" or "guarding read-only store"

Specified by:
getQuiet in interface EhcacheXAResource
Parameters:
key - the key to the Element to obtain form the underlying store
Returns:
the Element associated with the key, or null

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

ehcache

true