|
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.PositionExtraValueBatcher<I>
public class PositionExtraValueBatcher<I>
Batcher class for per-position extra values. This batcher can only be used for a new bioassayset that hasn't yet been committed to the database.
Code example: Multiply the mean of intensities of channel 1 and 2
// Get source bioassayset and extra value type DbControl dc = ... BioAssaySet source = ... ExtraValueType type = ... // Create new transformation and bioassayset to hold the // new intensities, we use the same data cube and layer as the source Transformation t = source.newTransformation(); dc.saveItem(t); BioAssaySet bas = t.newProduct(null, null, true); dc.saveItem(bas); // Create a query that selects the data of // the source bioassayset DynamicSpotQuery query = source.getSpotData(); // Multiply the mean of the intensities Expression meanCh1 = Aggregations.mean(Dynamic.column(VirtualColumn.channel(1))); Expression meanCh2 = Aggregations.mean(Dynamic.column(VirtualColumn.channel(2))); Expression product = Expressions.multiply(meanCh1, meanCh2); // Select the position and product, and group by position query.select(Dynamic.select(VirtualColumn.POSITION)); query.select(Selects.expression(product, "product")); query.group(Dynamic.column(VirtualColumn.POSITION)); // Execute the query, and use the batcher to insert the new values SpotExtraValueBatcher<Float> batcher = bas.getSpotExtraValueBatcher(Float.class, type); DynamicResultIterator spots = query.iterate(dc); int position = spots.getIndex(VirtualColumn.POSITION.getName()); int prod = spots.getIndex("product"); while (spots.hasNext()) { SqlResult r = spots.next(); batcher.insert(r.getInt(position), r.getFloat(prod)); } // Close and commit batcher.close(); dc.commit();
BioAssaySet.getPositionExtraValueBatcher(Class, ExtraValueType, Job)
Field Summary | |
---|---|
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 |
extraSql
The statement that inserts spot data. |
private String |
extraSqlStatement
The SQL string for the extraSql statement. |
private ExtraValue |
extraValue
The extra value object which links the extra value type. |
private int |
queuedInsertCount
The number of queued inserts. |
private int |
sqlType
The sql type code of the value to insert. |
private int |
totalInsertCount
The total number of inserts done by this batcher. |
private Type |
valueType
The type of values to insert. |
Fields inherited from class net.sf.basedb.core.AbstractBatcher |
---|
debugSqlEnabled, logSql |
Constructor Summary | |
---|---|
PositionExtraValueBatcher(DbControl dc,
ExtraValue extraValue)
Create a new spot batcher for a bioassayset. |
Method Summary | |
---|---|
private String |
buildInsertSelectSql(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 position extra values using a query. |
void |
insert(int position,
I value)
Insert an extra value for a given position coordinate. |
(package private) void |
onBeforeClose()
Update disk usage and 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 ExtraValue extraValue
private final Type valueType
private final int sqlType
Types
private final long bytesPerRow
private int queuedInsertCount
private int totalInsertCount
private long bytes
private PreparedStatement extraSql
INSERT INTO Dynamic#PositionExtraXxx (cube, extra, position, value) VALUES (cube, extra, ?, ?)
private String extraSqlStatement
extraSql
statement.
Constructor Detail |
---|
PositionExtraValueBatcher(DbControl dc, ExtraValue extraValue)
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(int position, I value) throws InvalidDataException, BaseException
position
- The position coordinatevalue
- The extra value
InvalidDataException
- If some data is corrupted
BaseException
- 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 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.
Note! This method can't be called for string extra values. This is
because the length of each string must be added to the disk usage. So
they must be processed individually in any case. Use the other
insert(int, Object)
method.
Here is an alternative to the example above:
// Get source bioassayset and extra value type DbControl dc = ... BioAssaySet source = ... ExtraValueType type = ... // Create new transformation and bioassayset to hold the // new intensities, we use the same data cube and layer as the source Transformation t = source.newTransformation(); dc.saveItem(t); BioAssaySet bas = t.newProduct(null, null, true); dc.saveItem(bas); // Create a query that selects the data of // the source bioassayset DynamicQuery query = source.getSpotData(); // Multiply the mean of the intensities Expression meanCh1 = Aggregations.mean(Dynamic.column(VirtualColumn.channel(1))); Expression meanCh2 = Aggregations.mean(Dynamic.column(VirtualColumn.channel(2))); Expression product = Expressions.multiply(meanCh1, meanCh2); // Select the position and product, and group by position query.select(Dynamic.select(VirtualColumn.POSITION)); query.select(Selects.expression(product, "product")); query.group(Dynamic.column(VirtualColumn.POSITION)); // Execute the query, and use the batcher to insert the new values SpotExtraValueBatcher<Float> batcher = bas.getSpotExtraValueBatcher(Float.class, type); batcher.insert(query); // Close and commit batcher.close(); dc.commit();
query
- The query that selects the data to be inserted
BaseException
- If there is an errorprivate void buildSpotSql() 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 |