Package net.sf.basedb.core
Class PositionBatcher
- java.lang.Object
-
- net.sf.basedb.core.AbstractBatcher
-
- net.sf.basedb.core.PositionBatcher
-
- All Implemented Interfaces:
AutoCloseable
,Batcher
public class PositionBatcher extends AbstractBatcher
Batcher class for per-position data in the dynamic database. This batcher is used to insert data that is valid for all positions in a data cube.Normally this means linking a position to a reporter.
Code example: Dynamic API - Creating a root bioassayset
- Version:
- 2.0
- Author:
- Nicklas
- See Also:
BioAssaySet.getPositionBatcher()
- Last modified
- $Date: 2015-04-21 09:59:42 +0200 (ti, 21 apr 2015) $
-
-
Field Summary
Fields Modifier and Type Field Description private long
bytes
The number of bytes this batcher has added to the data cube and experiment.private long
bytesPerRow
The number of bytes used by a single row.private DataCube
dataCube
The datacube this batcher inserts data for.private int
maxPosition
The maximum position number inserted by the batcher.private PreparedStatement
positionSql
The statement that inserts the position/reporter link.private String
positionSqlStatement
The SQL string for thepositionSql
statement.private int
queuedInsertCount
The number of queued inserts.private int
totalInsertCount
The total number of inserts done by this batcher.-
Fields inherited from class net.sf.basedb.core.AbstractBatcher
debugSqlEnabled, logSql
-
-
Constructor Summary
Constructors Constructor Description PositionBatcher(DbControl dc, DataCube dataCube)
Create a new position batcher for a data cube.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private String
buildInsertSelectSql(String selectSql)
Build the INSERT INTO ...private void
buildPositionSql()
Builds the insert SQL statement.void
flush()
Flush the batcher and send all remaining items in memory to the database.void
insert(int position, ReporterData reporter)
Link a position to a reporter.int
insert(AbstractSqlQuery query)
Insert position/reporter links using a query.(package private) void
onBeforeClose()
Update bytes and max position on the datacube and close open SQL statements.-
Methods inherited from class net.sf.basedb.core.AbstractBatcher
analyzeTable, close, getBatchSize, getDbControl, getSessionControl, isClosed, setBatchSize, setDbControl, updateLastAccess
-
-
-
-
Field Detail
-
dataCube
private final DataCube dataCube
The datacube this batcher inserts data for.
-
queuedInsertCount
private int queuedInsertCount
The number of queued inserts. Used to check when a flush is needed.
-
totalInsertCount
private int totalInsertCount
The total number of inserts done by this batcher.
-
maxPosition
private int maxPosition
The maximum position number inserted by the batcher.
-
bytes
private long bytes
The number of bytes this batcher has added to the data cube and experiment.
-
bytesPerRow
private final long bytesPerRow
The number of bytes used by a single row.
-
positionSql
private PreparedStatement positionSql
The statement that inserts the position/reporter link.INSERT INTO Dynamic#PerPosition (cube, position, reporter_id) VALUES (cube, ?, ?)
-
positionSqlStatement
private String positionSqlStatement
The SQL string for thepositionSql
statement.
-
-
Method Detail
-
flush
public void flush() throws BaseException
Description copied from interface:Batcher
Flush the batcher and send all remaining items in memory to the database.- Throws:
BaseException
- If there is an error- See Also:
Batcher.close()
-
onBeforeClose
void onBeforeClose() throws BaseException
Update bytes and max position on the datacube and close open SQL statements.- Overrides:
onBeforeClose
in classAbstractBatcher
- Throws:
BaseException
-
insert
public void insert(int position, ReporterData reporter) throws BaseException
Link a position to a reporter.- Parameters:
position
- The position coordinatereporter
- The reporter or null if no reporter is known- Throws:
BaseException
- If there is an error
-
insert
public int insert(AbstractSqlQuery query) throws BaseException
Insert position/reporter links using a query. The query MUST select data in the following order: position, reporterIdInternally this method converts the query into a
INSERT INTO ... SELECT ...
query, making it very fast, since the data for each position doesn't have to be retreived, processed and then inserted one row at a time. It is possible to call this method multiple times with the same or different query.- Parameters:
query
- The query that selects the data to be inserted- Returns:
- int The number of rows inserted
- Throws:
BaseException
- If there is an error
-
buildPositionSql
private void buildPositionSql() throws SQLException, BaseException
Builds the insert SQL statement. Also creates the Dynamic#PerPosition table if it doesn't exists.
-
buildInsertSelectSql
private String buildInsertSelectSql(String selectSql) throws BaseException
Build the INSERT INTO ... SELECT ... statment. Also creates the Dynamic#PerPosition table if it doesn't exists.- Parameters:
selectSql
- The SELECT part of the query- Throws:
BaseException
- See Also:
BatchUtil.buildInsertSelectSql(VirtualDb, VirtualTable, VirtualColumn[], String)
-
-