Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.transaction.memory
Class PessimisticMapWrapper

    java.lang.Object
      org.apache.commons.transaction.memory.TransactionalMapWrapper
          org.apache.commons.transaction.memory.PessimisticMapWrapper

All Implemented Interfaces:
  Map, Status

public class PessimisticMapWrapper
extends TransactionalMapWrapper

Wrapper that adds transactional control to all kinds of maps that implement the `Map` interface. By using pessimistic transaction control (blocking locks) this wrapper has better isolation than `TransactionalMapWrapper`, but also has less possible concurrency and may even deadlock. A commit, however, will never fail.
Start a transaction by calling `startTransaction()`. Then perform the normal actions on the map and finally either call `TransactionalMapWrapper.commitTransaction()` to make your changes permanent or `TransactionalMapWrapper.rollbackTransaction()` to undo them.
Caution: Do not modify values retrieved by `TransactionalMapWrapper.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 `SERIALIZABLE`.

Version:
  $Revision$
See Also:
  `TransactionalMapWrapper`, `OptimisticMapWrapper`

Nested Class Summary
`class` | `PessimisticMapWrapper.LockingTxContext`

Nested classes inherited from class org.apache.commons.transaction.memory.TransactionalMapWrapper
`TransactionalMapWrapper.HashEntry, TransactionalMapWrapper.TxContext`

Nested classes inherited from class java.util.Map
`Map.Entry`

Field Summary
`protected static Object` | `GLOBAL_LOCK`
`protected ReadWriteLockManager` | `lockManager`
`protected static int` | `READ`
`protected long` | `readTimeOut`
`protected static int` | `WRITE`

Fields inherited from class org.apache.commons.transaction.memory.TransactionalMapWrapper
`mapFactory, setFactory, 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
`PessimisticMapWrapper(Map wrapped, LoggerFacade logger)` Creates a new pessimistic transactional map wrapper.
`PessimisticMapWrapper(Map wrapped, MapFactory mapFactory, SetFactory setFactory, LoggerFacade logger)` Creates a new pessimistic transactional map wrapper.

Method Summary
`protected void` | `assureGlobalReadLock()`
`protected void` | `assureWriteLock(Object key)`
`Set` | `entrySet()`
`Set` | `keySet()`
`Object` | `put(Object key, Object value)`
`Object` | `remove(Object key)`
`void` | `startTransaction()` Starts a new transaction and associates it with the current thread.
`Collection` | `values()`

Methods inherited from class org.apache.commons.transaction.memory.TransactionalMapWrapper
`clear, commitTransaction, containsKey, containsValue, get, getActiveTx, getTransactionState, isEmpty, isReadOnly, isTransactionMarkedForRollback, markTransactionForRollback, putAll, resumeTransaction, rollbackTransaction, setActiveTx, size, suspendTransaction`

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

### READ

    protected static final int READ

See Also:
  Constant Field Values

### WRITE

    protected static final int WRITE

See Also:
  Constant Field Values

### GLOBAL_LOCK

    protected static final Object GLOBAL_LOCK

### lockManager

    protected ReadWriteLockManager lockManager

### readTimeOut

    protected long readTimeOut

Constructor Detail

### PessimisticMapWrapper

    public PessimisticMapWrapper(Map wrapped,
                                 LoggerFacade logger)

  Creates a new pessimistic transactional map wrapper. Temporary maps and sets to store transactional data will be instances of `HashMap` and `HashSet`.

Parameters:
  `wrapped` - map to be wrapped
  `logger` - generic logger used for all kinds of logging

### PessimisticMapWrapper

    public PessimisticMapWrapper(Map wrapped,
                                 MapFactory mapFactory,
                                 SetFactory setFactory,
                                 LoggerFacade logger)

  Creates a new pessimistic transactional map wrapper. Temporary maps and sets to store transactional data will be created and disposed using `MapFactory` and `SetFactory`.

Parameters:
  `wrapped` - map to be wrapped
  `mapFactory` - factory for temporary maps
  `setFactory` - factory for temporary sets
  `logger` - generic logger used for all kinds of logging

Method Detail

### startTransaction

    public void startTransaction()

  Description copied from class: `TransactionalMapWrapper`
  Starts a new transaction and associates it with the current thread. All subsequent changes in the same thread made to the map are invisible from other threads until `TransactionalMapWrapper.commitTransaction()` is called. Use `TransactionalMapWrapper.rollbackTransaction()` to discard your changes. After calling either method there will be no transaction associated to the current thread any longer.
  Caution: Be careful to finally call one of those methods, as otherwise the transaction will lurk around for ever.

  Overrides:
    `startTransaction` in class `TransactionalMapWrapper`
  See Also:
    `TransactionalMapWrapper.commitTransaction()`, `TransactionalMapWrapper.rollbackTransaction()`

### values

    public Collection values()

  Specified by:
    `values` in interface `Map`
  Overrides:
    `values` in class `TransactionalMapWrapper`
  See Also:
    `Map.values()`

### entrySet

    public Set entrySet()

  Specified by:
    `entrySet` in interface `Map`
  Overrides:
    `entrySet` in class `TransactionalMapWrapper`
  See Also:
    `Map.entrySet()`

### keySet

    public Set keySet()

  Specified by:
    `keySet` in interface `Map`
  Overrides:
    `keySet` in class `TransactionalMapWrapper`
  See Also:
    `Map.keySet()`

### remove

    public Object remove(Object key)

  Specified by:
    `remove` in interface `Map`
  Overrides:
    `remove` in class `TransactionalMapWrapper`
  See Also:
    `Map.remove(java.lang.Object)`

### put

    public Object put(Object key,
                      Object value)

  Specified by:
    `put` in interface `Map`
  Overrides:
    `put` in class `TransactionalMapWrapper`
  See Also:
    `Map.put(java.lang.Object, java.lang.Object)`

### assureWriteLock

    protected void assureWriteLock(Object key)

### assureGlobalReadLock

    protected void assureGlobalReadLock()

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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