Package net.sf.ehcache.transaction.local
Class JtaLocalTransactionStore
- java.lang.Object
-
- net.sf.ehcache.store.AbstractStore
-
- net.sf.ehcache.transaction.AbstractTransactionStore
-
- net.sf.ehcache.transaction.local.JtaLocalTransactionStore
-
- All Implemented Interfaces:
Store,TerracottaStore
public class JtaLocalTransactionStore extends AbstractTransactionStore
A Store implementation with support for local transactions driven by a JTA transaction manager- Author:
- Ludovic Orban
-
-
Field Summary
-
Fields inherited from class net.sf.ehcache.transaction.AbstractTransactionStore
underlyingStore
-
Fields inherited from class net.sf.ehcache.store.AbstractStore
attributeExtractors, searchManager
-
Fields inherited from interface net.sf.ehcache.store.Store
CLUSTER_COHERENT, NODE_COHERENT
-
-
Constructor Summary
Constructors Constructor Description JtaLocalTransactionStore(LocalTransactionStore underlyingStore, TransactionManagerLookup transactionManagerLookup, TransactionController transactionController)Create a new JtaLocalTransactionStore instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(java.lang.Object key)A check to see if a key is in the Store.Elementget(java.lang.Object key)Gets an item from the cache.java.util.ListgetKeys()Gets an Array of the keys for all elements in the disk store.ElementgetOldElement(java.lang.Object key)Method to get to theElementmatching the key, oblivious of any in-flight transaction.ElementgetQuiet(java.lang.Object key)Gets anElementfrom the Store, without updating statisticsintgetSize()Returns the current local store sizeintgetTerracottaClusteredSize()Returns the current Terracotta clustered store sizebooleanput(Element element)Puts an item into the store.voidputAll(java.util.Collection<Element> elements)Puts a collection of elements into the store.ElementputIfAbsent(Element element)Put an element in the store if no element is currently mapped to the elements key.booleanputWithWriter(Element element, CacheWriterManager writerManager)Puts an item into the store and the cache writer manager in an atomic operationElementremove(java.lang.Object key)Removes an item from the cache.voidremoveAll()Remove all of the elements from the store.voidremoveAll(java.util.Collection<?> keys)Removes a collection of elements from the cache.ElementremoveElement(Element element, ElementValueComparator comparator)Remove the Element mapped to the key for the supplied element if the value of the supplied Element is equal to the value of the cached Element.ElementremoveWithWriter(java.lang.Object key, CacheWriterManager writerManager)Removes an item from the store and the cache writer manager in an atomic operation.Elementreplace(Element element)Replace the cached element only if an Element is currently cached for this keybooleanreplace(Element old, Element element, ElementValueComparator comparator)Replace the cached element only if the value of the current Element is equal to the value of the supplied old Element.-
Methods inherited from class net.sf.ehcache.transaction.AbstractTransactionStore
bufferFull, containsKeyInMemory, containsKeyOffHeap, containsKeyOnDisk, createWriteBehind, dispose, executeQuery, expireElements, flush, getInMemoryEvictionPolicy, getInMemorySize, getInMemorySizeInBytes, getInternalContext, getLocalKeys, getMBean, getOffHeapSize, getOffHeapSizeInBytes, getOnDiskSize, getOnDiskSizeInBytes, getSearchAttribute, getSearchAttributes, getStatus, getTransactionalMode, hasAbortedSizeOf, isCacheCoherent, isClusterCoherent, isNodeCoherent, notifyCacheEventListenersChanged, quickClear, quickSize, setAttributeExtractors, setInMemoryEvictionPolicy, setNodeCoherent, unsafeGet, waitUntilClusterCoherent
-
Methods inherited from class net.sf.ehcache.store.AbstractStore
addStoreListener, getAll, getAllQuiet, getEventListenerList, recalculateSize, removeStoreListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.sf.ehcache.store.Store
addStoreListener, getAll, getAllQuiet, recalculateSize, removeStoreListener
-
-
-
-
Constructor Detail
-
JtaLocalTransactionStore
public JtaLocalTransactionStore(LocalTransactionStore underlyingStore, TransactionManagerLookup transactionManagerLookup, TransactionController transactionController)
Create a new JtaLocalTransactionStore instance- Parameters:
underlyingStore- the underlying LocalTransactionStoretransactionManagerLookup- the TransactionManagerLookuptransactionController- the TransactionController
-
-
Method Detail
-
getOldElement
public Element getOldElement(java.lang.Object key)
Description copied from class:AbstractTransactionStoreMethod to get to theElementmatching the key, oblivious of any in-flight transaction.- Overrides:
getOldElementin classAbstractTransactionStore- Parameters:
key- the key to look for- Returns:
- the mapped element, outside of any transaction
-
put
public boolean put(Element element) throws CacheException
Puts an item into the store.- Returns:
- true if this is a new put for the key or element is null. Returns false if it was an update.
- Throws:
CacheException
-
putAll
public void putAll(java.util.Collection<Element> elements) throws CacheException
Puts a collection of elements into the store.- Specified by:
putAllin interfaceStore- Overrides:
putAllin classAbstractStore- Parameters:
elements- Collection of elements to be put in the store- Throws:
CacheException
-
putWithWriter
public boolean putWithWriter(Element element, CacheWriterManager writerManager) throws CacheException
Puts an item into the store and the cache writer manager in an atomic operation- Returns:
- true if this is a new put for the key or element is null. Returns false if it was an update.
- Throws:
CacheException
-
get
public Element get(java.lang.Object key)
Gets an item from the cache.
-
getQuiet
public Element getQuiet(java.lang.Object key)
Gets anElementfrom the Store, without updating statistics- Returns:
- The element
-
getKeys
public java.util.List getKeys()
Gets an Array of the keys for all elements in the disk store.- Returns:
- An List of
Serializablekeys
-
remove
public Element remove(java.lang.Object key)
Removes an item from the cache.
-
removeAll
public void removeAll(java.util.Collection<?> keys)
Removes a collection of elements from the cache.- Specified by:
removeAllin interfaceStore- Overrides:
removeAllin classAbstractStore
-
removeWithWriter
public Element removeWithWriter(java.lang.Object key, CacheWriterManager writerManager) throws CacheException
Removes an item from the store and the cache writer manager in an atomic operation.- Throws:
CacheException
-
removeAll
public void removeAll() throws CacheExceptionRemove all of the elements from the store.If there are registered
CacheEventListeners they are notified of the expiry or removal of theElementas each is removed.- Throws:
CacheException
-
putIfAbsent
public Element putIfAbsent(Element element) throws java.lang.NullPointerException
Put an element in the store if no element is currently mapped to the elements key.- Parameters:
element- element to be added- Returns:
- the element previously cached for this key, or null if none.
- Throws:
java.lang.NullPointerException- if the element is null, or has a null key
-
removeElement
public Element removeElement(Element element, ElementValueComparator comparator) throws java.lang.NullPointerException
Remove the Element mapped to the key for the supplied element if the value of the supplied Element is equal to the value of the cached Element. This is a CAS operation. It is consistent even against a distributed cache that is not coherent. If the old value is stale when this operation is attempted the remove does not take place.- Parameters:
element- Element to be removedcomparator- ElementValueComparator to use to compare elements- Returns:
- the Element removed or null if no Element was removed
- Throws:
java.lang.NullPointerException- if the element is null, or has a null key
-
replace
public boolean replace(Element old, Element element, ElementValueComparator comparator) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
Replace the cached element only if the value of the current Element is equal to the value of the supplied old Element.- Parameters:
old- Element to be test againstelement- Element to be cachedcomparator- ElementValueComparator to use to compare elements- Returns:
- true is the Element was replaced
- Throws:
java.lang.NullPointerException- if the either Element is null or has a null keyjava.lang.IllegalArgumentException- if the two Element keys are non-null but not equal
-
replace
public Element replace(Element element) throws java.lang.NullPointerException
Replace the cached element only if an Element is currently cached for this key- Parameters:
element- Element to be cached- Returns:
- the Element previously cached for this key, or null if no Element was cached
- Throws:
java.lang.NullPointerException- if the Element is null or has a null key
-
getSize
public int getSize()
Returns the current local store size- Returns:
- the count of the Elements in the Store on the local machine
-
getTerracottaClusteredSize
public int getTerracottaClusteredSize()
Returns the current Terracotta clustered store size- Returns:
- the count of the Elements in the Store across the cluster
-
containsKey
public boolean containsKey(java.lang.Object key)
A check to see if a key is in the Store.- Parameters:
key- The Element key- Returns:
- true if found. No check is made to see if the Element is expired. 1.2
-
-