Package net.sf.basedb.core
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 singleDbControl
object. It implements all methods in theBatcher
interface except theBatcher.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 Summary
Fields Modifier and Type Field Description 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 org.slf4j.Logger
logSql
Log all SQL statements.private SessionControl
sc
-
Constructor Summary
Constructors Constructor Description AbstractBatcher()
Constructor for a batcher.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (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 theDbControl
object that currently manages this batcher.SessionControl
getSessionControl()
Get theSessionControl
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.
-
-
-
Field Detail
-
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 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 interfaceBatcher
- 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 interfaceBatcher
- 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 aDbControl
or if theDbControl
it is attached to has been closed.- Specified by:
isClosed
in interfaceBatcher
- 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 underlyingDbControl
to connect to the database will automatically be closed when theDbControl
is closed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceBatcher
- 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 usingDbControl.addBatcher(Batcher)
- Since:
- 2.4.2
-
getDbControl
public final DbControl getDbControl() throws ConnectionClosedException
Get theDbControl
object that currently manages this batcher.- Throws:
ConnectionClosedException
- If the batcher is connected to a closedDbControl
object, or not connected at all
-
getSessionControl
public final SessionControl getSessionControl() throws ConnectionClosedException
Get theSessionControl
object that manages this item.- Throws:
ConnectionClosedException
- If the item is connected to a closedDbControl
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 theclose()
method afterBatcher.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()
-
-