com.amazon.carbonado.txn
Class TransactionManager<Txn>

java.lang.Object
  extended by com.amazon.carbonado.txn.TransactionManager<Txn>
Type Parameters:
Txn - Transaction implementation

public abstract class TransactionManager<Txn>
extends Object

Generic transaction manager for repositories.

Author:
Brian S O'Neill

Constructor Summary
TransactionManager()
           
 
Method Summary
protected abstract  void abortTxn(Txn txn)
          Aborts and closes the given internal transaction.
 void close(boolean suspend)
          Closes all transaction scopes.
protected abstract  boolean commitTxn(Txn txn)
          Commits and closes the given internal transaction.
protected abstract  Txn createTxn(Txn parent, IsolationLevel level)
          Creates an internal transaction representation, with the optional parent transaction.
protected  Txn createTxn(Txn parent, IsolationLevel level, int timeout, TimeUnit unit)
          Creates an internal transaction representation, with the optional parent transaction.
 TransactionScope<Txn> detachLocalScope()
          Detaches the thread-local TransactionScope from the current thread.
 TransactionScope<Txn> localScope()
          Returns the thread-local TransactionScope, creating it if needed.
protected  void reuseTxn(Txn txn)
          Called when a transaction is about to be reused.
protected abstract  IsolationLevel selectIsolationLevel(Transaction parent, IsolationLevel level)
          Returns supported isolation level, which may be higher.
protected  void setForUpdate(Txn txn, boolean forUpdate)
          Called when the Transaction.setForUpdate method is called.
protected abstract  boolean supportsForUpdate()
          Return true if transactions support "for update" mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionManager

public TransactionManager()
Method Detail

localScope

public TransactionScope<Txn> localScope()
Returns the thread-local TransactionScope, creating it if needed.


detachLocalScope

public TransactionScope<Txn> detachLocalScope()
Detaches the thread-local TransactionScope from the current thread. It can be attached later, and to any thread which does not currently have a TransactionScope.

Returns:
detached thread-local TransactionScope or null if none
Since:
1.2

close

public void close(boolean suspend)
           throws RepositoryException
Closes all transaction scopes. Should be called only when repository is closed.

Parameters:
suspend - when true, indefinitely suspend all threads interacting with transactions
Throws:
RepositoryException

selectIsolationLevel

protected abstract IsolationLevel selectIsolationLevel(Transaction parent,
                                                       IsolationLevel level)
Returns supported isolation level, which may be higher. If isolation level cannot go higher (or lower than parent) then return null.

Parameters:
parent - optional parent transaction
level - desired isolation level (may be null)

supportsForUpdate

protected abstract boolean supportsForUpdate()
Return true if transactions support "for update" mode.

Since:
1.2

createTxn

protected abstract Txn createTxn(Txn parent,
                                 IsolationLevel level)
                          throws Exception
Creates an internal transaction representation, with the optional parent transaction. If parent is not null and real nested transactions are not supported, simply return parent transaction for supporting fake nested transactions.

Parameters:
parent - optional parent transaction
level - required isolation level
Returns:
new transaction, parent transaction, or possibly null if required isolation level is none
Throws:
Exception

createTxn

protected Txn createTxn(Txn parent,
                        IsolationLevel level,
                        int timeout,
                        TimeUnit unit)
                 throws Exception
Creates an internal transaction representation, with the optional parent transaction. If parent is not null and real nested transactions are not supported, simply return parent transaction for supporting fake nested transactions.

The default implementation of this method just calls the regular createTxn method, ignoring the timeout parameter.

Parameters:
parent - optional parent transaction
level - required isolation level
timeout - desired timeout for lock acquisition, never negative
unit - timeout unit, never null
Returns:
new transaction, parent transaction, or possibly null if required isolation level is none
Throws:
Exception

reuseTxn

protected void reuseTxn(Txn txn)
                 throws Exception
Called when a transaction is about to be reused. The default implementation of this method does nothing. Override if any preparation is required to ready a transaction for reuse.

Parameters:
txn - transaction to reuse, never null
Throws:
Exception
Since:
1.1.3

setForUpdate

protected void setForUpdate(Txn txn,
                            boolean forUpdate)
Called when the Transaction.setForUpdate method is called. The default implementation of this method does nothing. Override if internal transaction needs to switch modes.

Since:
1.2.1

commitTxn

protected abstract boolean commitTxn(Txn txn)
                              throws PersistException
Commits and closes the given internal transaction.

Returns:
true if transaction object is still valid
Throws:
PersistException

abortTxn

protected abstract void abortTxn(Txn txn)
                          throws PersistException
Aborts and closes the given internal transaction.

Throws:
PersistException


Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.