|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.transaction.memory.TransactionalMapWrapper
public class TransactionalMapWrapper
Wrapper that adds transactional control to all kinds of maps that implement the Map
interface.
This wrapper has rather weak isolation, but is simply, neven blocks and commits will never fail for logical
reasons.
Start a transaction by calling startTransaction()
. Then perform the normal actions on the map and
finally either call commitTransaction()
to make your changes permanent or rollbackTransaction()
to
undo them.
Caution: Do not modify values retrieved by get(Object)
as this will circumvent the transactional mechanism.
Rather clone the value or copy it in a way you see fit and store it back using put(Object, Object)
.
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.
OptimisticMapWrapper
,
PessimisticMapWrapper
Nested Class Summary | |
---|---|
protected static class |
TransactionalMapWrapper.HashEntry
|
class |
TransactionalMapWrapper.TxContext
|
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary | |
---|---|
protected MapFactory |
mapFactory
Factory to be used to create temporary maps for transactions. |
protected SetFactory |
setFactory
Factory to be used to create temporary sets for transactions. |
protected java.util.Map |
wrapped
The map wrapped. |
Fields inherited from interface javax.transaction.Status |
---|
STATUS_ACTIVE, STATUS_COMMITTED, STATUS_COMMITTING, STATUS_MARKED_ROLLBACK, STATUS_NO_TRANSACTION, STATUS_PREPARED, STATUS_PREPARING, STATUS_ROLLEDBACK, STATUS_ROLLING_BACK, STATUS_UNKNOWN |
Constructor Summary | |
---|---|
TransactionalMapWrapper(java.util.Map wrapped)
Creates a new transactional map wrapper. |
|
TransactionalMapWrapper(java.util.Map wrapped,
MapFactory mapFactory,
SetFactory setFactory)
Creates a new transactional map wrapper. |
Method Summary | |
---|---|
void |
clear()
|
void |
commitTransaction()
Commits all changes made in the current transaction and deletes the association between the current thread and the transaction. |
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
java.util.Set |
entrySet()
|
java.lang.Object |
get(java.lang.Object key)
|
protected TransactionalMapWrapper.TxContext |
getActiveTx()
|
int |
getTransactionState()
Returns the state of the current transaction. |
boolean |
isEmpty()
|
boolean |
isReadOnly()
Checks if any write operations have been performed inside this transaction. |
boolean |
isTransactionMarkedForRollback()
Checks whether this transaction has been marked to allow a rollback as the only valid outcome. |
java.util.Set |
keySet()
|
void |
markTransactionForRollback()
Marks the current transaction to allow only a rollback as valid outcome. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
|
void |
putAll(java.util.Map map)
|
java.lang.Object |
remove(java.lang.Object key)
|
void |
resumeTransaction(TransactionalMapWrapper.TxContext suspendedTx)
Resumes a transaction in the current thread that has previously been suspened by suspendTransaction() . |
void |
rollbackTransaction()
Discards all changes made in the current transaction and deletes the association between the current thread and the transaction. |
protected void |
setActiveTx(TransactionalMapWrapper.TxContext txContext)
|
int |
size()
|
void |
startTransaction()
Starts a new transaction and associates it with the current thread. |
TransactionalMapWrapper.TxContext |
suspendTransaction()
Suspends the transaction associated to the current thread. |
java.util.Collection |
values()
|
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 |
Field Detail |
---|
protected java.util.Map wrapped
protected MapFactory mapFactory
protected SetFactory setFactory
Constructor Detail |
---|
public TransactionalMapWrapper(java.util.Map wrapped)
HashMap
and HashSet
.
wrapped
- map to be wrappedpublic TransactionalMapWrapper(java.util.Map wrapped, MapFactory mapFactory, SetFactory setFactory)
MapFactory
and SetFactory
.
wrapped
- map to be wrappedmapFactory
- factory for temporary mapssetFactory
- factory for temporary setsMethod Detail |
---|
public boolean isReadOnly()
true
if no write opertation has been performed inside the current transaction,
false
otherwisepublic boolean isTransactionMarkedForRollback()
markTransactionForRollback()
or might
be set internally be any fatal error. Once a transaction is marked for rollback there
is no way to undo this. A transaction that is marked for rollback can not be committed,
also rolled back.
true
if this transaction has been marked for a roll backmarkTransactionForRollback()
public void markTransactionForRollback()
isTransactionMarkedForRollback()
public TransactionalMapWrapper.TxContext suspendTransaction()
resumeTransaction(TxContext)
- possibly in another thread than the current -
to resume work on the transaction.
resumeTransaction(TxContext)
resumeTransaction(TxContext)
public void resumeTransaction(TransactionalMapWrapper.TxContext suspendedTx)
suspendTransaction()
.
suspendedTx
- the identifier for the transaction to be resumed, delivered by suspendTransaction()
suspendTransaction()
public int getTransactionState()
Status
interface.public void startTransaction()
commitTransaction()
is called.
Use rollbackTransaction()
to discard your changes. After calling either method there will be
no transaction associated to the current thread any longer.
commitTransaction()
,
rollbackTransaction()
public void rollbackTransaction()
startTransaction()
,
commitTransaction()
public void commitTransaction()
startTransaction()
,
rollbackTransaction()
public void clear()
clear
in interface java.util.Map
Map.clear()
public int size()
size
in interface java.util.Map
Map.size()
public boolean isEmpty()
isEmpty
in interface java.util.Map
Map.isEmpty()
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
Map.containsKey(java.lang.Object)
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
Map.containsValue(java.lang.Object)
public java.util.Collection values()
values
in interface java.util.Map
Map.values()
public void putAll(java.util.Map map)
putAll
in interface java.util.Map
Map.putAll(java.util.Map)
public java.util.Set entrySet()
entrySet
in interface java.util.Map
Map.entrySet()
public java.util.Set keySet()
keySet
in interface java.util.Map
Map.keySet()
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
Map.get(java.lang.Object)
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
Map.remove(java.lang.Object)
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
Map.put(java.lang.Object, java.lang.Object)
protected TransactionalMapWrapper.TxContext getActiveTx()
protected void setActiveTx(TransactionalMapWrapper.TxContext txContext)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |