2.17.2: 2011-06-17

net.sf.basedb.core
Class AbstractBatcher

java.lang.Object
  extended by net.sf.basedb.core.AbstractBatcher
All Implemented Interfaces:
Batcher
Direct Known Subclasses:
BasicBatcher, FilterBatcher, MappingBatcher, PositionBatcher, PositionExtraValueBatcher, 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: 2010-08-13 10:50:27 +0200 (Fri, 13 Aug 2010) $

Field Summary
private  int batchSize
          SQL command batch size.
private  WeakReference<DbControl> dc
          A reference to the current DbControl object.
protected static boolean debugSqlEnabled
          So we don't always have to call logSql.debug()
protected static Logger logSql
          Log all SQL statements.
private  SessionControl sc
           
 
Constructor Summary
AbstractBatcher()
          Constructor for a batcher.
 
Method Summary
(package private)  void analyzeTable(String catalog, String schema, String table)
          Update index statistics for a table.
 void close()
          Flush the batcher and close it.
 int getBatchSize()
          Get the current batch size of the batcher.
 DbControl getDbControl()
          Get the DbControl object that currently manages this batcher.
 SessionControl getSessionControl()
          Get the SessionControl object that manages this item.
 boolean isClosed()
          Check if this batcher is closed or not.
(package private)  void onBeforeClose()
          Let a subclass cleanup itself before the connection to the database is closed.
 void setBatchSize(int batchSize)
          Sets the batch size.
protected  void setDbControl(DbControl dc)
          Set the DbControl that is controlling this batcher.
(package private)  void updateLastAccess()
          Update the last access time so the session control doesn't get cleaned up.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.basedb.core.Batcher
flush
 

Field Detail

logSql

protected static final 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 Detail

AbstractBatcher

AbstractBatcher()
Constructor for a batcher.

Throws:
BaseException - If there is an error
Method Detail

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 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()

2.17.2: 2011-06-17