|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.AbstractBatcher net.sf.basedb.core.FilterBatcher
public class FilterBatcher
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();
BioAssaySet.getFilterBatcher()
Field Summary | |
---|---|
private BioAssaySet |
bioAssaySet
The bioassayset this batcher inserts data for. |
private long |
bytes
The number of bytes this batcher has added to the experiment. |
private long |
bytesPerRow
The number of bytes used by a single row. |
private PreparedStatement |
filterSql
The statement that inserts filter data. |
private String |
filterSqlStatement
The SQL string for the filterSql 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 | |
---|---|
FilterBatcher(DbControl dc,
BioAssaySet bioAssaySet)
Create a new filter batcher for a bioassayset. |
Method Summary | |
---|---|
private void |
buildFilterSql()
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. |
int |
insert(AbstractSqlQuery query)
Insert column/position coordinates using a query. |
void |
insert(short column,
int position)
Insert a column/position coordinate that passed the filter. |
(package private) void |
onBeforeClose()
Close open SQL statements. |
Methods inherited from class net.sf.basedb.core.AbstractBatcher |
---|
analyzeTable, close, getBatchSize, getDbControl, getSessionControl, isClosed, setBatchSize, setDbControl, updateLastAccess |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final BioAssaySet bioAssaySet
private int queuedInsertCount
private int totalInsertCount
private long bytes
private final long bytesPerRow
private PreparedStatement filterSql
INSERT INTO Dynamic#Filter (cube, filter, column, position) VALUES (cube, filter, ?, ?)
private String filterSqlStatement
filterSql
statement.
Constructor Detail |
---|
FilterBatcher(DbControl dc, BioAssaySet bioAssaySet)
Method Detail |
---|
public void flush() throws BaseException
Batcher
BaseException
- If there is an errorBatcher.close()
void onBeforeClose() throws BaseException
onBeforeClose
in class AbstractBatcher
BaseException
public void insert(short column, int position) throws BaseException
column
- The column numberposition
- The position number
BaseException
- If there is an errorpublic int insert(AbstractSqlQuery query) throws BaseException
Internally 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();
query
- The query that selects the data to be inserted
BaseException
- If there is an errorprivate void buildFilterSql() throws SQLException, BaseException
SQLException
BaseException
BatchUtil.buildInsertSql(VirtualDb, VirtualTable, VirtualColumn[], Object[])
private String buildInsertSelectSql(String selectSql) throws BaseException
selectSql
- The SELECT part of the query
BaseException
BatchUtil.buildInsertSelectSql(VirtualDb, VirtualTable, VirtualColumn[], String)
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |