org.apache.commons.transaction.memory
Class BasicTxMap<K,V>

java.lang.Object
  extended by org.apache.commons.transaction.AbstractTransactionalResourceManager<BasicTxMap.MapTxContext>
      extended by org.apache.commons.transaction.memory.BasicTxMap<K,V>
All Implemented Interfaces:
Map<K,V>, ManageableResourceManager, TxMap<K,V>, TransactionalResourceManager
Direct Known Subclasses:
OptimisticTxMap, PessimisticTxMap

public class BasicTxMap<K,V>
extends AbstractTransactionalResourceManager<BasicTxMap.MapTxContext>
implements TxMap<K,V>

Map featuring transactional control.

This implementation has rather weak isolation, but is simple, never blocks and commits will never fail for logical reasons.

Note: This wrapper guarantees isolation level READ COMMITTED only. I.e. as soon a value is committed in one transaction it will be immediately visible in all other concurrent transactions.

This implementation wraps a map of type ConcurrentHashMap. All internal synchronization is delegated to this class.

This implementation is thread-safe.

See Also:
OptimisticTxMap, PessimisticTxMap, ConcurrentHashMap

Nested Class Summary
protected static class BasicTxMap.HashEntry
           
 class BasicTxMap.MapTxContext
           
 
Nested classes/interfaces inherited from class org.apache.commons.transaction.AbstractTransactionalResourceManager
AbstractTransactionalResourceManager.AbstractTxContext
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Field Summary
protected  Map<K,V> wrapped
           
 
Fields inherited from class org.apache.commons.transaction.AbstractTransactionalResourceManager
activeTx
 
Constructor Summary
BasicTxMap(String name)
           
BasicTxMap(String name, LockManager<Object,Object> lm)
           
 
Method Summary
 void clear()
           
 boolean commitCanFail()
          Checks whether a tried commit could possibly fail because of logical reasons.
 boolean containsKey(Object key)
           
 boolean containsValue(Object value)
           
protected  BasicTxMap.MapTxContext createContext()
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object key)
           
protected  BasicTxMap.MapTxContext getActiveTx()
           
 Map<K,V> getWrappedMap()
          Gets the underlying map that is wrapped by this transactional implementation.
 boolean isEmpty()
           
 Set<K> keySet()
           
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> map)
           
 V remove(Object key)
           
 int size()
           
 Collection<V> values()
           
 
Methods inherited from class org.apache.commons.transaction.AbstractTransactionalResourceManager
commitTransaction, forgetTransaction, getCheckedActiveTx, getLm, getName, isPartofComplexTransaction, isReadOnly, isRollbackOnly, joinTransaction, prepareTransaction, rollbackTransaction, setActiveTx, setLm, setName, startTransaction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 
Methods inherited from interface org.apache.commons.transaction.ManageableResourceManager
forgetTransaction, isReadOnly, isRollbackOnly, joinTransaction, prepareTransaction
 
Methods inherited from interface org.apache.commons.transaction.TransactionalResourceManager
commitTransaction, rollbackTransaction, startTransaction
 

Field Detail

wrapped

protected final Map<K,V> wrapped
Constructor Detail

BasicTxMap

public BasicTxMap(String name,
                  LockManager<Object,Object> lm)

BasicTxMap

public BasicTxMap(String name)
Method Detail

getWrappedMap

public Map<K,V> getWrappedMap()
Description copied from interface: TxMap
Gets the underlying map that is wrapped by this transactional implementation.

Specified by:
getWrappedMap in interface TxMap<K,V>
Returns:
the wrapped map

clear

public void clear()
Specified by:
clear in interface Map<K,V>
See Also:
Map.clear()

size

public int size()
Specified by:
size in interface Map<K,V>
See Also:
Map.size()

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>
See Also:
Map.isEmpty()

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
See Also:
Map.containsKey(java.lang.Object)

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K,V>
See Also:
Map.containsValue(java.lang.Object)

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>
See Also:
Map.values()

putAll

public void putAll(Map<? extends K,? extends V> map)
Specified by:
putAll in interface Map<K,V>
See Also:
Map.putAll(java.util.Map)

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
See Also:
Map.entrySet()

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>
See Also:
Map.keySet()

get

public V get(Object key)
Specified by:
get in interface Map<K,V>
See Also:
Map.get(java.lang.Object)

remove

public V remove(Object key)
Specified by:
remove in interface Map<K,V>
See Also:
Map.remove(java.lang.Object)

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
See Also:
Map.put(java.lang.Object, java.lang.Object)

createContext

protected BasicTxMap.MapTxContext createContext()
Specified by:
createContext in class AbstractTransactionalResourceManager<BasicTxMap.MapTxContext>

getActiveTx

protected BasicTxMap.MapTxContext getActiveTx()
Overrides:
getActiveTx in class AbstractTransactionalResourceManager<BasicTxMap.MapTxContext>

commitCanFail

public boolean commitCanFail()
Description copied from interface: ManageableResourceManager
Checks whether a tried commit could possibly fail because of logical reasons.

Specified by:
commitCanFail in interface ManageableResourceManager
Specified by:
commitCanFail in class AbstractTransactionalResourceManager<BasicTxMap.MapTxContext>
Returns:
true if a commit could fail


Copyright © 2004-2007 The Apache Software Foundation. All Rights Reserved.