public class TransactionalMapWrapper extends Object implements Map, Status
Map
interface.
This wrapper has rather weak isolation, but is simply, neven blocks and commits will never fail for logical
reasons.
startTransaction()
. Then perform the normal actions on the map and
finally either call commitTransaction()
to make your changes permanent or rollbackTransaction()
to
undo them.
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)
.
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
Modifier and Type | Class and Description |
---|---|
protected static class |
TransactionalMapWrapper.HashEntry |
class |
TransactionalMapWrapper.TxContext |
Modifier and Type | Field and Description |
---|---|
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 Map |
wrapped
The map wrapped.
|
STATUS_ACTIVE, STATUS_COMMITTED, STATUS_COMMITTING, STATUS_MARKED_ROLLBACK, STATUS_NO_TRANSACTION, STATUS_PREPARED, STATUS_PREPARING, STATUS_ROLLEDBACK, STATUS_ROLLING_BACK, STATUS_UNKNOWN
Constructor and Description |
---|
TransactionalMapWrapper(Map wrapped)
Creates a new transactional map wrapper.
|
TransactionalMapWrapper(Map wrapped,
MapFactory mapFactory,
SetFactory setFactory)
Creates a new transactional map wrapper.
|
Modifier and Type | Method and Description |
---|---|
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(Object key) |
boolean |
containsValue(Object value) |
Set |
entrySet() |
Object |
get(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.
|
Set |
keySet() |
void |
markTransactionForRollback()
Marks the current transaction to allow only a rollback as valid outcome.
|
Object |
put(Object key,
Object value) |
void |
putAll(Map map) |
Object |
remove(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.
|
Collection |
values() |
protected MapFactory mapFactory
protected SetFactory setFactory
public TransactionalMapWrapper(Map wrapped)
HashMap
and HashSet
.wrapped
- map to be wrappedpublic TransactionalMapWrapper(Map wrapped, MapFactory mapFactory, SetFactory setFactory)
MapFactory
and SetFactory
.wrapped
- map to be wrappedmapFactory
- factory for temporary mapssetFactory
- factory for temporary setspublic 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 Map
Map.clear()
public int size()
size
in interface Map
Map.size()
public boolean isEmpty()
isEmpty
in interface Map
Map.isEmpty()
public boolean containsKey(Object key)
containsKey
in interface Map
Map.containsKey(java.lang.Object)
public boolean containsValue(Object value)
containsValue
in interface Map
Map.containsValue(java.lang.Object)
public Collection values()
values
in interface Map
Map.values()
public void putAll(Map map)
putAll
in interface Map
Map.putAll(java.util.Map)
public Set entrySet()
entrySet
in interface Map
Map.entrySet()
public Set keySet()
keySet
in interface Map
Map.keySet()
public Object get(Object key)
get
in interface Map
Map.get(java.lang.Object)
public Object remove(Object key)
remove
in interface Map
Map.remove(java.lang.Object)
public Object put(Object key, Object value)
put
in interface Map
Map.put(java.lang.Object, java.lang.Object)
protected TransactionalMapWrapper.TxContext getActiveTx()
protected void setActiveTx(TransactionalMapWrapper.TxContext txContext)
Copyright © 2004-2013 The Apache Software Foundation. All Rights Reserved.