ehcache

net.sf.ehcache.transaction.xa
Class EhcacheXAStoreImpl

java.lang.Object
  extended by net.sf.ehcache.transaction.xa.EhcacheXAStoreImpl
All Implemented Interfaces:
EhcacheXAStore

public class EhcacheXAStoreImpl
extends java.lang.Object
implements EhcacheXAStore

Default implementation of EhcacheXAStore.

It uses ConcurrentHashMap for the local data (non safe in case of failure) and requires a "safe" Store for the oldVersionStore, and a reference to the underlying Store.

Author:
Alex Snaps

Nested Class Summary
static class EhcacheXAStoreImpl.Version
          Represents an Element's version for a Store
static class EhcacheXAStoreImpl.VersionTable
          A table containing element version information
 
Field Summary
protected  Store oldVersionStore
          protected for testing
protected  java.util.concurrent.ConcurrentMap<javax.transaction.xa.Xid,PreparedContext> prepareXids
          protected for testing
protected  java.util.concurrent.ConcurrentMap<javax.transaction.xa.Xid,XATransactionContext> transactionContextXids
          protected for testing
protected  Store underlyingStore
          protected for testing
protected  EhcacheXAStoreImpl.VersionTable versionTable
          protected for testing
 
Constructor Summary
EhcacheXAStoreImpl(Store underlyingStore, Store oldVersionStore)
          Constructor
 
Method Summary
 void checkin(java.lang.Object key, javax.transaction.xa.Xid xid, boolean readOnly)
          Checks in changes to a key
 long checkout(java.lang.Object key, javax.transaction.xa.Xid xid)
          Checks a version for en Element out of the store
 PreparedContext createPreparedContext()
          Return a newly created prepare context if none exist.
 TransactionContext createTransactionContext(javax.transaction.xa.Xid xid)
          Creates a new TransactionContext for a given Transaction
 Store getOldVersionStore()
          Getter to the guarding read-only oldVersionStore
 PreparedContext getPreparedContext(javax.transaction.xa.Xid xid)
          Gets a PreparedContext from a persistent store for a previously prepared Transaction
 javax.transaction.xa.Xid[] getPreparedXids()
          Lists prepared, yet not commited Xids
 TransactionContext getTransactionContext(javax.transaction.xa.Xid xid)
          Gets a stored TransactionContext for a given Transaction
 Store getUnderlyingStore()
          Getter to the underlying store
 boolean isPrepared(javax.transaction.xa.Xid xid)
          Checks whether a Transaction is prepared
 boolean isValid(VersionAwareCommand command, javax.transaction.xa.Xid xid)
          Checks whether a command can safely be executed against the store, depending on the version lock
 void prepare(javax.transaction.xa.Xid xid, PreparedContext context)
          Save the Transaction's data as being prepared
 void removeData(javax.transaction.xa.Xid xid)
          Removes stored data of a given Xid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

transactionContextXids

protected final java.util.concurrent.ConcurrentMap<javax.transaction.xa.Xid,XATransactionContext> transactionContextXids
protected for testing


prepareXids

protected final java.util.concurrent.ConcurrentMap<javax.transaction.xa.Xid,PreparedContext> prepareXids
protected for testing


versionTable

protected final EhcacheXAStoreImpl.VersionTable versionTable
protected for testing


underlyingStore

protected Store underlyingStore
protected for testing


oldVersionStore

protected Store oldVersionStore
protected for testing

Constructor Detail

EhcacheXAStoreImpl

public EhcacheXAStoreImpl(Store underlyingStore,
                          Store oldVersionStore)
Constructor

Parameters:
underlyingStore - the real underlying store
oldVersionStore - the old version, read-only, used to access keys during 2pc
Method Detail

getOldVersionStore

public Store getOldVersionStore()
Getter to the guarding read-only oldVersionStore

Specified by:
getOldVersionStore in interface EhcacheXAStore
Returns:
the oldVersionStore

isPrepared

public boolean isPrepared(javax.transaction.xa.Xid xid)
Checks whether a Transaction is prepared

Specified by:
isPrepared in interface EhcacheXAStore
Parameters:
xid - the Xid of the Transaction
Returns:
true if prepared

removeData

public void removeData(javax.transaction.xa.Xid xid)
Removes stored data of a given Xid

Specified by:
removeData in interface EhcacheXAStore
Parameters:
xid - the Xid of the Transaction

checkin

public void checkin(java.lang.Object key,
                    javax.transaction.xa.Xid xid,
                    boolean readOnly)
Checks in changes to a key

Specified by:
checkin in interface EhcacheXAStore
Parameters:
key - the key of the affected Element in the Store
xid - the Xid of the Transaction executing the change
readOnly - whether the command modified the underlying Store

checkout

public long checkout(java.lang.Object key,
                     javax.transaction.xa.Xid xid)
Checks a version for en Element out of the store

Specified by:
checkout in interface EhcacheXAStore
Parameters:
key - the key to the Element in the store
xid - the Xid of the Transaction reading
Returns:
the version of the element

createTransactionContext

public TransactionContext createTransactionContext(javax.transaction.xa.Xid xid)
Creates a new TransactionContext for a given Transaction

Specified by:
createTransactionContext in interface EhcacheXAStore
Parameters:
xid - of current transaction
Returns:
a TransactionContext for that Transaction

getPreparedXids

public javax.transaction.xa.Xid[] getPreparedXids()
Lists prepared, yet not commited Xids

Specified by:
getPreparedXids in interface EhcacheXAStore
Returns:
array of uncommited, yet prepared xids

getTransactionContext

public TransactionContext getTransactionContext(javax.transaction.xa.Xid xid)
Gets a stored TransactionContext for a given Transaction

Specified by:
getTransactionContext in interface EhcacheXAStore
Parameters:
xid - The Xid of the Transaction
Returns:
the matching TransactionContext

isValid

public boolean isValid(VersionAwareCommand command,
                       javax.transaction.xa.Xid xid)
Checks whether a command can safely be executed against the store, depending on the version lock

Specified by:
isValid in interface EhcacheXAStore
Parameters:
command - the Command
Returns:
true if safe, false if cannot be applied anymore

prepare

public void prepare(javax.transaction.xa.Xid xid,
                    PreparedContext context)
Save the Transaction's data as being prepared

Specified by:
prepare in interface EhcacheXAStore
Parameters:
xid - the Xid of the Transaction
context - the context with the transaction data

getPreparedContext

public PreparedContext getPreparedContext(javax.transaction.xa.Xid xid)
Gets a PreparedContext from a persistent store for a previously prepared Transaction

Specified by:
getPreparedContext in interface EhcacheXAStore
Parameters:
xid - The Xid of the Transaction
Returns:
the Prepared context for the Transaction, or null

createPreparedContext

public PreparedContext createPreparedContext()
Return a newly created prepare context if none exist.

Specified by:
createPreparedContext in interface EhcacheXAStore
Returns:
a new PreparedContext

getUnderlyingStore

public Store getUnderlyingStore()
Getter to the underlying store

Specified by:
getUnderlyingStore in interface EhcacheXAStore
Returns:
the store

ehcache

true