Class AbstractBatcher

java.lang.Object
net.sf.basedb.core.AbstractBatcher
All Implemented Interfaces:
AutoCloseable, Batcher
Direct Known Subclasses:
AnnotationBatcher, BasicBatcher, FilterBatcher, MappingBatcher, PositionBatcher, PositionExtraValueBatcher, ReporterCloneBatcher, SpotBatcher, SpotExtraValueBatcher

public abstract class AbstractBatcher
extends Object
implements Batcher
This is an abstract class for batchers that are connected to a single DbControl object. It implements all methods in the Batcher interface except the Batcher.flush() method.

A subclass may also have to override the close() method if it has opened connections or statements to the database.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2014-06-10 13:27:02 +0200 (ti, 10 jun 2014) $
  • Field Details

    • logSql

      protected static final org.slf4j.Logger logSql
      Log all SQL statements.
    • debugSqlEnabled

      protected static final boolean debugSqlEnabled
      So we don't always have to call logSql.debug()
    • sc

      private SessionControl sc
    • dc

      private WeakReference<DbControl> dc
      A reference to the current DbControl object. We use a WeakReference since we it is always the client applications responsibility to keep control over the DbControl object.
    • batchSize

      private int batchSize
      SQL command batch size.
  • Constructor Details

    • AbstractBatcher

      AbstractBatcher()
      Constructor for a batcher.
      Throws:
      BaseException - If there is an error
  • Method Details

    • getBatchSize

      public int getBatchSize()
      Description copied from interface: Batcher
      Get the current batch size of the batcher. The batch size indicates how many individual items a batcher is caching in memory before they are automatically flushed to the database.
      Specified by:
      getBatchSize in interface Batcher
      Returns:
      The current batch size, or 0 if automatic flushing is turned of
    • setBatchSize

      public void setBatchSize​(int batchSize)
      Description copied from interface: Batcher
      Sets the batch size. The batch size indicates how many individual items a batcher is caching in memory before they are automatically flushed to the database.
      Specified by:
      setBatchSize in interface Batcher
      Parameters:
      batchSize - Size of the batch, or 0 to disable automatic flushing
    • isClosed

      public final boolean isClosed()
      Check if this batcher is closed or not. The batcher is considered as closed when it isn't attached to a DbControl or if the DbControl it is attached to has been closed.
      Specified by:
      isClosed in interface Batcher
      Returns:
      TRUE if the batcher is closed, FALSE otherwise
      See Also:
      Batcher.close()
    • close

      public final void close() throws BaseException
      Description copied from interface: Batcher
      Flush the batcher and close it. A closed batcher will not accept any more data for insert, update or delete. Note! A batcher that uses an underlying DbControl to connect to the database will automatically be closed when the DbControl is closed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Batcher
      Throws:
      BaseException - If there is an error
      See Also:
      Batcher.isClosed(), Batcher.flush()
    • updateLastAccess

      void updateLastAccess()
      Update the last access time so the session control doesn't get cleaned up.
    • setDbControl

      protected final void setDbControl​(DbControl dc)
      Set the DbControl that is controlling this batcher. This method MUST be called by all subclasses after successful construction of a batcher. This method also registers the batcher with the DbControl using DbControl.addBatcher(Batcher)
      Since:
      2.4.2
    • getDbControl

      public final DbControl getDbControl() throws ConnectionClosedException
      Get the DbControl object that currently manages this batcher.
      Throws:
      ConnectionClosedException - If the batcher is connected to a closed DbControl object, or not connected at all
    • getSessionControl

      public final SessionControl getSessionControl() throws ConnectionClosedException
      Get the SessionControl object that manages this item.
      Throws:
      ConnectionClosedException - If the item is connected to a closed DbControl object, or not connected at all
    • onBeforeClose

      void onBeforeClose() throws BaseException
      Let a subclass cleanup itself before the connection to the database is closed. This method is called by the close() method after Batcher.flush() has been called but before the connection to the database is lost. Typical use of this method is to update properties on parent object (for example, spot count) and to close open SQL statements.
      Throws:
      BaseException
    • analyzeTable

      void analyzeTable​(String catalog, String schema, String table)
      Update index statistics for a table.
      See Also:
      DbEngine.analyzeAfterBatchOperation()