Holger's Java API

## com.antelmann.db
Class TransactionCounter

    java.lang.Object
      com.antelmann.db.TransactionListener.Adapter
          com.antelmann.db.TransactionCounter

All Implemented Interfaces:
  TransactionListener

    public class TransactionCounter

extends TransactionListener.Adapter

A TransactionCounter increments its counter upon transaction begin to allow determining whether it's still the same transaction. This counter allows to determine whether an ongoing transaction of a given database is still the same as during a previous call by checking the counter.

Since:
  21. Oktober 2007, 22:33
Author:
  Holger Antelmann
See Also:
  `getTransactionCounter(DBTransaction)`

Nested Class Summary

Nested classes/interfaces inherited from interface com.antelmann.db.TransactionListener
`TransactionListener.Adapter`

Constructor Summary
`TransactionCounter(DBTransaction ta)` After calling the constructor, this instance must still be added as a listener to the given transaction before the counter works.

Method Summary
`void` `checkCount(int count)`
`int` `getCounter()`
`DBTransaction` `getTransaction()`
`static TransactionCounter` `getTransactionCounter(DBTransaction ta)` returns a TransactionCounter associated and listening to the given DBTransaction.
`void` `transactionBegin(DBTransaction transaction)` increments the counter by one if the given transaction is the same as the embedded one

Methods inherited from class com.antelmann.db.TransactionListener.Adapter
`finishTransaction, prepareToCommit, transactionAborted, transactionCommitted`

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

Constructor Detail

### TransactionCounter

    public TransactionCounter(DBTransaction ta)

  After calling the constructor, this instance must still be added as a listener to the given transaction before the counter works. Also, it must then be removed as a listener to be garbage-collected. Preferably, use `getTransactionCounter(DBTransaction)` to only have one counter per database.

Method Detail

### getTransaction

    public DBTransaction getTransaction()

### getCounter

    public int getCounter()

### checkCount

    public void checkCount(int count)
                    throws TransactionException

  Throws:
    `TransactionException`

### transactionBegin

    public void transactionBegin(DBTransaction transaction)

  increments the counter by one if the given transaction is the same as the embedded one

  Specified by:
    `transactionBegin` in interface `TransactionListener`
  Overrides:
    `transactionBegin` in class `TransactionListener.Adapter`

### getTransactionCounter

    public static TransactionCounter getTransactionCounter(DBTransaction ta)

  returns a TransactionCounter associated and listening to the given DBTransaction. First, this method seeks to find an existing TransactionCounter already used as a listener; if found, that one is simply returned. If that fails, a new TransactionCounter instance is created, added as a listener to the database, and returned.

  See Also:
    `AbstractDBTransaction.getTransactionListeners()`

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