Package net.sf.basedb.core
Class FilterBatcher
java.lang.Object
net.sf.basedb.core.AbstractBatcher
net.sf.basedb.core.FilterBatcher
- All Implemented Interfaces:
AutoCloseable
,Batcher
Batcher class for filtered bioassaysets. A filtered bioassayset is normally
the result of a filtering transformation and uses the same data cube and
layer as the source bioassayset to store it's data. This batcher is used
to specify the column/position coordinates of the original spots that
remains after the filter has been applied.
Code example: Filter spots where ch1 <= 2 * ch2
// Get source bioassayset DbControl dc = ... BioAssaySet source = ... // Create new transformation and bioassayset to hold the // filtered result Transformation t = source.newTransformation(); dc.saveItem(t); BioAssaySet filtered = t.newProduct(null, null, true); dc.saveItem(filtered); // Create a query that selects the column // and position of all spots where ch1 > 2 * ch2 DynamicSpotQuery query = source.getSpotData(); query.select(Dynamic.select(VirtualColumn.COLUMN)); query.select(Dynamic.select(VirtualColumn.POSITION)); query.restrict( Restriction.gt( Dynamic.column(VirtualColumn.channel(1)), Expressions.multiply( Expressions.integer(2), Dynamic.column(VirtualColumn.channel(2)) ) ) ); // Execute the query, and use the batcher to insert the result FilterBatcher batcher = filtered.getFilterBatcher(); DynamicResultIterator result = query.iterate(dc); int column = result.getIndex(VirtualColumn.COLUMN.getName()); int position = result.getIndex(VirtualColumn.POSITION.getName()); while (result.hasNext()) { SqlResult r = result.next(); batcher.insert(r.getShort(column), r.getInt(position)); } // Close, save and commit batcher.close(); dc.commit();
- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2014-06-10 15:52:45 +0200 (ti, 10 jun 2014) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate final BioAssaySet
The bioassayset this batcher inserts data for.private long
The number of bytes this batcher has added to the experiment.private final long
The number of bytes used by a single row.private PreparedStatement
The statement that inserts filter data.private String
The SQL string for thefilterSql
statement.private int
The number of queued inserts.private int
The total number of inserts done by this batcher.Fields inherited from class net.sf.basedb.core.AbstractBatcher
debugSqlEnabled, logSql
-
Constructor Summary
ConstructorDescriptionFilterBatcher
(DbControl dc, BioAssaySet bioAssaySet) Create a new filter batcher for a bioassayset. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Builds the insert SQL statement.private String
buildInsertSelectSql
(String selectSql) Build the INSERT INTO ...void
flush()
Flush the batcher and send all remaining items in memory to the database.void
insert
(short column, int position) Insert a column/position coordinate that passed the filter.int
insert
(AbstractSqlQuery query) Insert column/position coordinates using a query.(package private) void
Close open SQL statements.Methods inherited from class net.sf.basedb.core.AbstractBatcher
analyzeTable, close, getBatchSize, getDbControl, getSessionControl, isClosed, setBatchSize, setDbControl, updateLastAccess
-
Field Details
-
bioAssaySet
The bioassayset this batcher inserts data for. -
queuedInsertCount
private int queuedInsertCountThe number of queued inserts. Used to check when a flush is needed. -
totalInsertCount
private int totalInsertCountThe total number of inserts done by this batcher. -
bytes
private long bytesThe number of bytes this batcher has added to the experiment. -
bytesPerRow
private final long bytesPerRowThe number of bytes used by a single row. -
filterSql
The statement that inserts filter data.INSERT INTO Dynamic#Filter (cube, filter, column, position) VALUES (cube, filter, ?, ?)
-
filterSqlStatement
The SQL string for thefilterSql
statement.
-
-
Constructor Details
-
FilterBatcher
FilterBatcher(DbControl dc, BioAssaySet bioAssaySet) Create a new filter batcher for a bioassayset. It is assumed that the calling code has checked that the bioassayset is allowed to receive more data (ie. it hasn't been committed to the database).
-
-
Method Details
-
flush
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:
-
onBeforeClose
Close open SQL statements.- Overrides:
onBeforeClose
in classAbstractBatcher
- Throws:
BaseException
-
insert
Insert a column/position coordinate that passed the filter.- Parameters:
column
- The column numberposition
- The position number- Throws:
BaseException
- If there is an error
-
insert
Insert column/position coordinates using a query. The query MUST select data in the following order: column, positionInternally this method converts the query into a
INSERT INTO ... SELECT ...
query, making it very fast, since the data for each coordinate 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.Here is an alternative to the example above:
// Get source bioassayset DbControl dc = ... BioAssaySet source = ... // Create new transformation and bioassayset to hold the // filtered result Transformation t = source.newTransformation(); dc.saveItem(t); BioAssaySet filtered = t.newProduct(null, null, true); dc.saveItem(filtered); // Create a query that selects the column // and position of all spots where ch1 > 2 * ch2 DynamicSpotQuery query = source.getSpotData(); query.select(Dynamic.select(VirtualColumn.COLUMN)); query.select(Dynamic.select(VirtualColumn.POSITION)); query.restrict( Restriction.gt( Dynamic.column(VirtualColumn.channel(1)), Expressions.multiply( Expressions.integer(2), Dynamic.column(VirtualColumn.channel(2)) ) ) ); // Execute the query, and use the batcher to insert the result FilterBatcher batcher = filtered.getFilterBatcher(); batcher.insert(query); // Close, save and commit batcher.close(); dc.commit();
- 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
-
buildFilterSql
Builds the insert SQL statement. Also creates the Dynamic#Filter table if it doesn't exists. -
buildInsertSelectSql
Build the INSERT INTO ... SELECT ... statment. Also creates the Dynamic#Filter table if it doesn't exists.- Parameters:
selectSql
- The SELECT part of the query- Throws:
BaseException
- See Also:
-