Module org.firebirdsql.jaybird
Package org.firebirdsql.gds.ng

# Class AbstractFbTransaction

java.lang.Object
org.firebirdsql.gds.ng.AbstractFbTransaction

All Implemented Interfaces:
  `FbTransaction`, `ExceptionListenable`

Direct Known Subclasses:
  `V10Transaction`

public abstract class AbstractFbTransaction extends Object implements FbTransaction

Since:
  3.0
Author:
  Mark Rotteveel

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final ExceptionListenerDispatcher`
`exceptionListenerDispatcher`
`protected final TransactionListenerDispatcher`
`transactionListenerDispatcher`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`AbstractFbTransaction(TransactionState initialState, FbDatabase database)`
Initializes AbstractFbTransaction.

## Method Summary

Modifier and Type
Method
Description
`final void`
`addExceptionListener(ExceptionListener listener)`
Adds an exception listener to this object.
`final void`
`addTransactionListener(TransactionListener listener)`
Adds a `TransactionListener` to the list of strongly referenced listeners.
`final void`
`addWeakTransactionListener(TransactionListener listener)`
Adds a `TransactionListener` to the list of weakly referenced listeners.
`protected FbDatabase`
`getDatabase()`
`final TransactionState`
`getState()`
`long`
`getTransactionId()`
Retrieves the transaction id.
`<T> T`
`getTransactionInfo(byte[] requestItems, int bufferLength, InfoProcessor<T> infoProcessor)`
Request transaction info.
`protected final void`
`logUnexpectedState(TransactionState expectedState, System.Logger log)`
`final void`
`removeExceptionListener(ExceptionListener listener)`
Removes an exception listener to this object.
`final void`
`removeTransactionListener(TransactionListener listener)`
Removes the `TransactionListener` from the list of listeners.
`protected final void`
`switchState(TransactionState newState)`
Switches current state to the supplied newState.
`protected final LockCloseable`
`withLock()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.firebirdsql.gds.ng.FbTransaction

`commit, getHandle, getTransactionInfo, prepare, rollback`

## Field Details

### exceptionListenerDispatcher

protected final ExceptionListenerDispatcher exceptionListenerDispatcher

### transactionListenerDispatcher

protected final TransactionListenerDispatcher transactionListenerDispatcher

## Constructor Details

### AbstractFbTransaction

protected AbstractFbTransaction(TransactionState initialState, FbDatabase database)
Initializes AbstractFbTransaction.

Parameters:
  `initialState` - Initial transaction state (allowed values are `TransactionState.ACTIVE` and `TransactionState.PREPARED`).
  `database` - FbDatabase that created this handle.

## Method Details

### getState

public final TransactionState getState()

Specified by:
  `getState` in interface `FbTransaction`
Returns:
  Current transaction state

### switchState

protected final void switchState(TransactionState newState) throws SQLException
Switches current state to the supplied newState.

Parameters:
  `newState` - New state to switch to
Throws:
  `SQLException` - If the requested state transition is not allowed or if the current state is also changed in a concurrent thread.

### addTransactionListener

public final void addTransactionListener(TransactionListener listener)
Description copied from interface: `FbTransaction`
Adds a `TransactionListener` to the list of strongly referenced listeners.

Specified by:
  `addTransactionListener` in interface `FbTransaction`
Parameters:
  `listener` - TransactionListener to register

### addWeakTransactionListener

public final void addWeakTransactionListener(TransactionListener listener)
Description copied from interface: `FbTransaction`
Adds a `TransactionListener` to the list of weakly referenced listeners.

If the listener is already strongly referenced, this call will be ignored

Specified by:
  `addWeakTransactionListener` in interface `FbTransaction`
Parameters:
  `listener` - TransactionListener to register

### removeTransactionListener

public final void removeTransactionListener(TransactionListener listener)
Description copied from interface: `FbTransaction`
Removes the `TransactionListener` from the list of listeners.

Specified by:
  `removeTransactionListener` in interface `FbTransaction`
Parameters:
  `listener` - TransactionListener to remove

### addExceptionListener

public final void addExceptionListener(ExceptionListener listener)
Description copied from interface: `ExceptionListenable`
Adds an exception listener to this object.

Implementations use `WeakReference`.

Specified by:
  `addExceptionListener` in interface `ExceptionListenable`
Parameters:
  `listener` - Listener to register

### removeExceptionListener

public final void removeExceptionListener(ExceptionListener listener)
Description copied from interface: `ExceptionListenable`
Removes an exception listener to this object.

Specified by:
  `removeExceptionListener` in interface `ExceptionListenable`
Parameters:
  `listener` - Listener to remove

### getTransactionInfo

public <T> T getTransactionInfo(byte[] requestItems, int bufferLength, InfoProcessor<T> infoProcessor) throws SQLException
Description copied from interface: `FbTransaction`
Request transaction info.

Specified by:
  `getTransactionInfo` in interface `FbTransaction`
Parameters:
  `requestItems` - Array of info items to request
  `bufferLength` - Response buffer length to use
  `infoProcessor` - Implementation of `InfoProcessor` to transform the info response
Returns:
  Transformed info response of type T
Throws:
  `SQLException` - For errors retrieving or transforming the response.

### getTransactionId

public long getTransactionId() throws SQLException
Description copied from interface: `FbTransaction`
Retrieves the transaction id.

The transaction id is the database transaction id, not to be confused with the attachment level transaction handle provided by `FbTransaction.getHandle()`.

Specified by:
  `getTransactionId` in interface `FbTransaction`
Returns:
  Database transaction id.
Throws:
  `SQLException`

### withLock

protected final LockCloseable withLock()

See Also:
  - `FbAttachment.withLock()`

### getDatabase

protected FbDatabase getDatabase()

### logUnexpectedState

protected final void logUnexpectedState(TransactionState expectedState, System.Logger log)