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
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 Summary
Modifier and TypeFieldDescriptionprivate int
SQL command batch size.private WeakReference<DbControl>
A reference to the current DbControl object.protected static final boolean
So we don't always have to call logSql.debug()protected static final Logger
Log all SQL statements.private SessionControl
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) void
analyzeTable
(String catalog, String schema, String table) Update index statistics for a table.final void
close()
Flush the batcher and close it.int
Get the current batch size of the batcher.final DbControl
Get theDbControl
object that currently manages this batcher.final SessionControl
Get theSessionControl
object that manages this item.final boolean
isClosed()
Check if this batcher is closed or not.(package private) void
Let a subclass cleanup itself before the connection to the database is closed.void
setBatchSize
(int batchSize) Sets the batch size.protected final void
Set the DbControl that is controlling this batcher.(package private) void
Update the last access time so the session control doesn't get cleaned up.
-
Field Details
-
logSql
Log all SQL statements. -
debugSqlEnabled
protected static final boolean debugSqlEnabledSo we don't always have to call logSql.debug() -
sc
-
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 batchSizeSQL 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 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. -
close
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:
-
updateLastAccess
void updateLastAccess()Update the last access time so the session control doesn't get cleaned up. -
setDbControl
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
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
Get theSessionControl
object that manages this item.- Throws:
ConnectionClosedException
- If the item is connected to a closedDbControl
object, or not connected at all
-
onBeforeClose
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
Update index statistics for a table.- See Also:
-