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

# Class AbstractFbDatabase<T extends AbstractConnection<IConnectionProperties,? extends FbDatabase>>

java.lang.Object
org.firebirdsql.gds.ng.AbstractFbAttachment<T>
org.firebirdsql.gds.ng.AbstractFbDatabase<T>

All Implemented Interfaces:
  `AutoCloseable`, `FbAttachment`, `FbDatabase`, `ExceptionListenable`, `TransactionListener`

Direct Known Subclasses:
  `AbstractFbWireDatabase`

public abstract class AbstractFbDatabase<T extends AbstractConnection<IConnectionProperties,? extends FbDatabase>> extends AbstractFbAttachment<T> implements FbDatabase, TransactionListener
Abstract implementation of `FbDatabase` with behavior common to the various implementations.

Since:
  3.0
Author:
  Mark Rotteveel

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final DatabaseListenerDispatcher`
  `databaseListenerDispatcher`

  ### Fields inherited from class org.firebirdsql.gds.ng.AbstractFbAttachment

  `connection, exceptionListenerDispatcher`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractFbDatabase(T connection, DatatypeCoder datatypeCoder)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `addDatabaseListener(DatabaseListener listener)`
  Adds a `DatabaseListener` instance to this database.
  `final void`
  `addWeakDatabaseListener(DatabaseListener listener)`
  Adds a `DatabaseListener` instance to this database using a weak reference.
  `final void`
  `close()`
  Detaches and closes the connection.
  `BlobParameterBuffer`
  `createBlobParameterBuffer()`
  Creates a blob parameter buffer that is usable with `FbDatabase.createBlobForInput(FbTransaction, org.firebirdsql.gds.BlobParameterBuffer, long)` and `FbDatabase.createBlobForOutput(FbTransaction, org.firebirdsql.gds.BlobParameterBuffer)` of this instance.
  `TransactionParameterBufferImpl`
  `createTransactionParameterBuffer()`
  Creates a transaction parameter buffer that is usable with `FbDatabase.startTransaction(org.firebirdsql.gds.TransactionParameterBuffer)`.
  `final RowDescriptor`
  `emptyRowDescriptor()`
  `final int`
  `getActiveTransactionCount()`
  `final short`
  `getConnectionDialect()`
  `IConnectionProperties`
  `getConnectionProperties()`
  `final short`
  `getDatabaseDialect()`
  `final <R> R`
  `getDatabaseInfo(byte[] requestItems, int bufferLength, InfoProcessor<R> infoProcessor)`
  Request database info.
  `protected InfoProcessor<FbDatabase>`
  `getDatabaseInformationProcessor()`
  `final WarningMessageCallback`
  `getDatabaseWarningCallback()`
  `protected byte[]`
  `getDescribeDatabaseInfoBlock()`
  `final int`
  `getOdsMajor()`
  `final int`
  `getOdsMinor()`
  `final OdsVersion`
  `getOdsVersion()`
  `final byte[]`
  `getParameterDescriptionInfoRequestItems()`
  `final byte[]`
  `getStatementInfoRequestItems()`
  `protected byte[]`
  `getTransactionIdBuffer(long transactionId)`
  Encodes the transactionId for use in `isc_reconnect_transaction`/`op_reconnect`.
  `protected abstract void`
  `internalDetach()`
  Actual implementation of database detach.
  `final void`
  `removeDatabaseListener(DatabaseListener listener)`
  Removes a `DatabaseListener` instance from this database.
  `protected final void`
  `setDatabaseDialect(short dialect)`
  Sets the dialect of the database.
  `protected final void`
  `setOdsMajor(int odsMajor)`
  Sets the ODS (On Disk Structure) major version of the database associated with this connection.
  `protected final void`
  `setOdsMinor(int odsMinor)`
  Sets the ODS (On Disk Structure) minor version of the database associated with this connection.
  `protected final void`
  `transactionAdded(FbTransaction transaction)`
  Called when a transaction is added by the database.
  `final void`
  `transactionStateChanged(FbTransaction transaction, TransactionState newState, TransactionState previousState)`
  Signals that the transaction state changed.

  ### Methods inherited from class org.firebirdsql.gds.ng.AbstractFbAttachment

  `addExceptionListener, checkConnected, forceClose, getDatatypeCoder, getEncoding, getEncodingFactory, getNetworkTimeout, getServerVersion, isAttached, isLockedByCurrentThread, removeExceptionListener, requireNotAttached, safelyDetach, setAttached, setDetached, setServerVersion, 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.listeners.ExceptionListenable

  `addExceptionListener, removeExceptionListener`

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

  `attach, forceClose, getDatatypeCoder, getEncoding, getEncodingFactory, getNetworkTimeout, getServerVersion, isAttached, isLockedByCurrentThread, setNetworkTimeout, withLock`

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

  `cancelEvent, cancelOperation, countEvents, createBlobForInput, createBlobForInput, createBlobForInput, createBlobForOutput, createBlobForOutput, createBlobForOutput, createDatabase, createEventHandle, createStatement, dropDatabase, executeImmediate, getDatabaseInfo, getHandle, queueEvent, reconnectTransaction, startTransaction, startTransaction`

- ## Field Details

  - ### databaseListenerDispatcher

    protected final DatabaseListenerDispatcher databaseListenerDispatcher

- ## Constructor Details

  - ### AbstractFbDatabase

    protected AbstractFbDatabase(T connection, DatatypeCoder datatypeCoder)

- ## Method Details

  - ### getDatabaseWarningCallback

    public final WarningMessageCallback getDatabaseWarningCallback()
    Returns:
      The warning callback for this database.

  - ### getActiveTransactionCount

    public final int getActiveTransactionCount()
    Returns:
      Number of active (not prepared or committed/rolled back) transactions

  - ### transactionAdded

    protected final void transactionAdded(FbTransaction transaction)
    Called when a transaction is added by the database.

    Only this `AbstractFbDatabase` instance should call this method.

  - ### getConnectionDialect

    public final short getConnectionDialect()
    Specified by:
      `getConnectionDialect` in interface `FbDatabase`
    Returns:
      The client connection dialect

  - ### getDatabaseDialect

    public final short getDatabaseDialect()
    Specified by:
      `getDatabaseDialect` in interface `FbDatabase`
    Returns:
      The database dialect

  - ### setDatabaseDialect

    protected final void setDatabaseDialect(short dialect)
    Sets the dialect of the database.

    This method should only be called by this instance.

    Parameters:
      `dialect` - Dialect of the database/connection

  - ### addDatabaseListener

    public final void addDatabaseListener(DatabaseListener listener)
    Description copied from interface: `FbDatabase`
    Adds a `DatabaseListener` instance to this database.
    Specified by:
      `addDatabaseListener` in interface `FbDatabase`
    Parameters:
      `listener` - Database listener

  - ### addWeakDatabaseListener

    public final void addWeakDatabaseListener(DatabaseListener listener)
    Description copied from interface: `FbDatabase`
    Adds a `DatabaseListener` instance to this database using a weak reference.

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

    Specified by:
      `addWeakDatabaseListener` in interface `FbDatabase`
    Parameters:
      `listener` - Database listener

  - ### removeDatabaseListener

    public final void removeDatabaseListener(DatabaseListener listener)
    Description copied from interface: `FbDatabase`
    Removes a `DatabaseListener` instance from this database.
    Specified by:
      `removeDatabaseListener` in interface `FbDatabase`
    Parameters:
      `listener` - Database Listener

  - ### internalDetach

    protected abstract void internalDetach() throws SQLException
    Actual implementation of database detach.

    Implementations of this method should only be called from `close()`, and should not notify database listeners of the database `DatabaseListener.detaching(FbDatabase)` and `DatabaseListener.detached(FbDatabase)` events.

    Throws:
      `SQLException`

  - ### close

    public final void close() throws SQLException
    Detaches and closes the connection.

    Implementation note: Calls `AbstractFbAttachment.checkConnected()` and notifies database listeners of the detaching event, then calls `internalDetach()` and finally notifies database listeners of database detach and removes all listeners.

    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `FbAttachment`
    Throws:
      `SQLException` - If not currently connected, or another problem occurred detaching.

  - ### getOdsMajor

    public final int getOdsMajor()
    Specified by:
      `getOdsMajor` in interface `FbDatabase`
    Returns:
      ODS major version

  - ### setOdsMajor

    protected final void setOdsMajor(int odsMajor)
    Sets the ODS (On Disk Structure) major version of the database associated with this connection.

    This method should only be called by this instance.

    Parameters:
      `odsMajor` - ODS major version

  - ### getOdsMinor

    public final int getOdsMinor()
    Specified by:
      `getOdsMinor` in interface `FbDatabase`
    Returns:
      ODS minor version

  - ### setOdsMinor

    protected final void setOdsMinor(int odsMinor)
    Sets the ODS (On Disk Structure) minor version of the database associated with this connection.

    This method should only be called by this instance.

    Parameters:
      `odsMinor` - ODS minor version

  - ### getOdsVersion

    public final OdsVersion getOdsVersion()
    Specified by:
      `getOdsVersion` in interface `FbDatabase`
    Returns:
      ODS version

  - ### getStatementInfoRequestItems

    public final byte[] getStatementInfoRequestItems()
    Returns:
      The (full) statement info request items.
    See Also:
      - `getParameterDescriptionInfoRequestItems()`

  - ### getParameterDescriptionInfoRequestItems

    public final byte[] getParameterDescriptionInfoRequestItems()
    Returns:
      The `isc_info_sql_describe_vars` info request items.
    See Also:
      - `getStatementInfoRequestItems()`

  - ### getDatabaseInfo

    public final <R> R getDatabaseInfo(byte[] requestItems, int bufferLength, InfoProcessor<R> infoProcessor) throws SQLException
    Description copied from interface: `FbDatabase`
    Request database info.
    Specified by:
      `getDatabaseInfo` in interface `FbDatabase`
    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.

  - ### getDescribeDatabaseInfoBlock

    protected byte[] getDescribeDatabaseInfoBlock()

  - ### getDatabaseInformationProcessor

    protected InfoProcessor<FbDatabase> getDatabaseInformationProcessor()

  - ### transactionStateChanged

    public final void transactionStateChanged(FbTransaction transaction, TransactionState newState, TransactionState previousState)
    Description copied from interface: `TransactionListener`
    Signals that the transaction state changed.
    Specified by:
      `transactionStateChanged` in interface `TransactionListener`
    Parameters:
      `transaction` - `FbTransaction` that changed state

  - ### createBlobParameterBuffer

    public BlobParameterBuffer createBlobParameterBuffer()
    Description copied from interface: `FbDatabase`
    Creates a blob parameter buffer that is usable with `FbDatabase.createBlobForInput(FbTransaction, org.firebirdsql.gds.BlobParameterBuffer, long)` and `FbDatabase.createBlobForOutput(FbTransaction, org.firebirdsql.gds.BlobParameterBuffer)` of this instance.
    Specified by:
      `createBlobParameterBuffer` in interface `FbDatabase`
    Returns:
      A blob parameter buffer.

  - ### createTransactionParameterBuffer

    public TransactionParameterBufferImpl createTransactionParameterBuffer()
    Description copied from interface: `FbDatabase`
    Creates a transaction parameter buffer that is usable with `FbDatabase.startTransaction(org.firebirdsql.gds.TransactionParameterBuffer)`.
    Specified by:
      `createTransactionParameterBuffer` in interface `FbDatabase`
    Returns:
      A transaction parameter buffer

  - ### getConnectionProperties

    public IConnectionProperties getConnectionProperties()
    Specified by:
      `getConnectionProperties` in interface `FbDatabase`
    Returns:
      An immutable copy of the connection properties of this database

  - ### emptyRowDescriptor

    public final RowDescriptor emptyRowDescriptor()
    Specified by:
      `emptyRowDescriptor` in interface `FbDatabase`
    Returns:
      A potentially cached empty row descriptor for this database.

  - ### getTransactionIdBuffer

    protected byte[] getTransactionIdBuffer(long transactionId)
    Encodes the transactionId for use in `isc_reconnect_transaction`/`op_reconnect`.
    Parameters:
      `transactionId` - transaction id
    Returns:
      byte array (4 bytes for max 31-bit transaction id, 8 bytes for larger transaction id)