public class SpotBatcher extends AbstractBatcher
Code example: Swap the intensities of channel 1 and 2
// Get source bioassayset DbControl dc = ... BioAssaySet source = ... // Create new transformation and bioassayset to hold the // new intensities, we use the same data cube as the source // but a different layer Transformation t = source.newTransformation(); dc.saveItem(t); BioAssaySet bas = t.newProduct(null, "new", true); dc.saveItem(bas); // Create a query that selects the data of // the source bioassayset DynamicSpotQuery query = source.getSpotData(); // Execute the query, and use the batcher to swap the // intensities SpotBatcher batcher = bas.getSpotBatcher(); DynamicResultIterator result = query.iterate(dc); int column = result.getIndex(VirtualColumn.COLUMN.getName()); int position = result.getIndex(VirtualColumn.POSITION.getName()); int ch1 = result.getIndex(VirtualColumn.channel(1).getName()); int ch2 = result.getIndex(VirtualColumn.channel(2).getName()); while (result.hasNext()) { SqlResult r = result.next(); batcher.insert(r.getShort(column), r.getInt(position), r.getFloat(ch2), r.getFloat(ch1)); } // Close and commit batcher.close(); dc.commit();
BioAssaySet.getSpotBatcher()
Modifier and Type | Field and Description |
---|---|
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 int |
numChannels
The number of channels used in the raw data type of the
experiment where the bioassayset belongs.
|
private int |
queuedInsertCount
The number of queued inserts.
|
private java.sql.PreparedStatement |
spotSql
The statement that inserts spot data.
|
private java.lang.String |
spotSqlStatement
The SQL string for the
spotSql statement. |
private int |
totalInsertCount
The total number of inserts done by this batcher.
|
debugSqlEnabled, logSql
Constructor and Description |
---|
SpotBatcher(DbControl dc,
BioAssaySet bioAssaySet)
Create a new spot batcher for a bioassayset.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
buildInsertSelectSql(java.lang.String selectSql)
Build the INSERT INTO ...
|
private void |
buildSpotSql()
Builds the insert SQL statement.
|
void |
flush()
Flush the batcher and send all remaining items in memory to the
database.
|
int |
insert(AbstractSqlQuery query)
Insert spot intensities using a query.
|
void |
insert(short column,
int position,
float... intensities)
Insert intensities for a given column/position coordinate.
|
(package private) void |
onBeforeClose()
Update disk usage and close open SQL statements
|
analyzeTable, close, getBatchSize, getDbControl, getSessionControl, isClosed, setBatchSize, setDbControl, updateLastAccess
private final BioAssaySet bioAssaySet
private final int numChannels
private int queuedInsertCount
private int totalInsertCount
private long bytes
private final long bytesPerRow
private java.sql.PreparedStatement spotSql
INSERT INTO Dynamic#PerSpot (cube, layer, column, position, ch1, ch2, ...) VALUES (cube, layer, ?, ?, ?, ?, ...)
private java.lang.String spotSqlStatement
spotSql
statement.SpotBatcher(DbControl dc, BioAssaySet bioAssaySet)
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, float... intensities) throws BaseException
column
- The column coordinateposition
- The position coordinateintensities
- An array holding the intensities for the coordinate,
the length must match the number of channels of the raw data typeInvalidDataException
- If the intensities array is null or
of the incorrect lengthBaseException
- If there is another 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 spot 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 // new intensities, we use the same data cube as the source // but a different layer Transformation t = source.newTransformation(); dc.saveItem(t); BioAssaySet bas = t.newProduct(null, "new", true); dc.saveItem(bas); // Create a query that selects the data of // the source bioassayset, swap the order of the channels DynamicSpotQuery query = source.getSpotData(); query.select(Dynamic.select(VirtualColumn.COLUMN)); query.select(Dynamic.select(VirtualColumn.POSITION)); query.select(Dynamic.select(VirtualColumn.channel(2))); query.select(Dynamic.select(VirtualColumn.channel(1))); // Execute the query, and use the batcher to insert the result SpotBatcher batcher = bas.getSpotBatcher(); batcher.insert(query); // Close and commit batcher.close(); dc.commit();
query
- The query that selects the data to be insertedBaseException
- If there is an errorprivate void buildSpotSql() throws java.sql.SQLException, BaseException
java.sql.SQLException
BaseException
BatchUtil.buildInsertSql(VirtualDb, VirtualTable, VirtualColumn[], Object[])
private java.lang.String buildInsertSelectSql(java.lang.String selectSql) throws BaseException
selectSql
- The SELECT part of the queryBaseException
BatchUtil.buildInsertSelectSql(VirtualDb, VirtualTable, VirtualColumn[], String)