Holger's Java API

## com.antelmann.db
Class AbstractDBTransaction

    java.lang.Object
      com.antelmann.db.AbstractDBTransaction

All Implemented Interfaces:
  DBTransaction

Direct Known Subclasses:
  SQLTransaction

    public abstract class AbstractDBTransaction

extends Object
implements DBTransaction

a simple base implementation for a DBTransaction. By implementing the abstract methods (instead of those that implement the interface and are marked final), the listeners are handled transparently.

Since:
  17. November 2006, 19:24
Author:
  Holger Antelmann

Field Summary
`protected Database<?>` `database`

Constructor Summary
`AbstractDBTransaction(Database<?> database)`

Method Summary
`void` `abort()` aborts this transaction; requires ownership of this instance.
`boolean` `addTransactionListener(TransactionListener listener)`
`void` `begin()` sets the transaction to active and allows access to the Resources provided that the calling thread holds the lock on this instance.
`void` `commit()` commits all data within the transaction scope to the underlying database; requires ownership of this instance.
`protected abstract void` `doAbort()`
`protected abstract void` `doBegin()`
`protected abstract void` `doCommit()`
`Database<?>` `getDatabase()` gives access to the associated Database
`TransactionListener[]` `getTransactionListeners()`
`boolean` `isActive()` if true, a transaction is currently in progress and has not been committed or aborted, yet.
`boolean` `isReadOnly()` informs whether the currently running transaction is configured to be read-only.
`boolean` `removeTransactionListener(TransactionListener listener)`
`void` `setNextToReadOnly(boolean flag)` allows to configure the next transaction to be read-only.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### database

    protected Database<?> database

Constructor Detail

### AbstractDBTransaction

    public AbstractDBTransaction(Database<?> database)

Method Detail

### addTransactionListener

    public boolean addTransactionListener(TransactionListener listener)

  Specified by:
    `addTransactionListener` in interface `DBTransaction`

### removeTransactionListener

    public boolean removeTransactionListener(TransactionListener listener)

  Specified by:
    `removeTransactionListener` in interface `DBTransaction`

### getTransactionListeners

    public TransactionListener[] getTransactionListeners()

  Specified by:
    `getTransactionListeners` in interface `DBTransaction`

### getDatabase

    public Database<?> getDatabase()

  Description copied from interface: `DBTransaction`
  gives access to the associated Database

  Specified by:
    `getDatabase` in interface `DBTransaction`

### doBegin

    protected abstract void doBegin()
                             throws TransactionException

  Throws:
    `TransactionException`

### doCommit

    protected abstract void doCommit()
                              throws DatabaseException

  Throws:
    `DatabaseException`

### doAbort

    protected abstract void doAbort()
                             throws DatabaseException

  Throws:
    `DatabaseException`

### begin

    public final void begin()
                     throws TransactionException

  Description copied from interface: `DBTransaction`
  sets the transaction to active and allows access to the Resources provided that the calling thread holds the lock on this instance.

  Specified by:
    `begin` in interface `DBTransaction`
  Throws:
    `TransactionException` - if the transaction is already active or if the transaction is in transition
  See Also:
    `TransactionListener.transactionAborted(DBTransaction)`, `TransactionListener.transactionCommitted(DBTransaction)`

### commit

    public final void commit()
                      throws TransactionException,
                             DatabaseException

  Description copied from interface: `DBTransaction`
  commits all data within the transaction scope to the underlying database; requires ownership of this instance.

  Specified by:
    `commit` in interface `DBTransaction`
  Throws:
    `TransactionException` - if the transaction is already active
    `DatabaseException` - if the transaction could not be committed to the underlying service

### abort

    public final void abort()
                     throws TransactionException,
                            DatabaseException

  Description copied from interface: `DBTransaction`
  aborts this transaction; requires ownership of this instance.

  Specified by:
    `abort` in interface `DBTransaction`
  Throws:
    `TransactionException` - if the transaction is already active
    `DatabaseException` - if the transaction could not be aborted from the underlying service

### isActive

    public boolean isActive()

  Description copied from interface: `DBTransaction`
  if true, a transaction is currently in progress and has not been committed or aborted, yet. Access to resources is only save if this method returns true and the calling thread holds the lock on this instance. In order to rely on the return value after the method returns, an ownership of the calling thread on this DBTransaction is required.

  Specified by:
    `isActive` in interface `DBTransaction`

### isReadOnly

    public boolean isReadOnly()

  Description copied from interface: `DBTransaction`
  informs whether the currently running transaction is configured to be read-only. If there is no active transaction, the return value will determine whether the next transaction to be started is going to be read-only. This setting only applies for the current/next transaction, not for subsequent ones. Some given database implementation may, however, configure every transaction to be read-only (or read-write) while altering this setting may not be supported. `DBTransaction.setNextToReadOnly(boolean)`

  Specified by:
    `isReadOnly` in interface `DBTransaction`

### setNextToReadOnly

    public void setNextToReadOnly(boolean flag)
                           throws TransactionException,
                                  UnsupportedOperationException

  Description copied from interface: `DBTransaction`
  allows to configure the next transaction to be read-only. This call must be repeated before every transaction that is to be read-only, as after each commit/abort this setting is reset to false.

  Specified by:
    `setNextToReadOnly` in interface `DBTransaction`
  Parameters:
    `flag` - if true, the next transaction will run read-only; if false, the next transaction will be read-write
  Throws:
    `TransactionException` - if a transaction is currently active
    `UnsupportedOperationException`
  See Also:
    `DBTransaction.isReadOnly()`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads