Class SpotExtraValueBatcher<I>
- All Implemented Interfaces:
AutoCloseable
,Batcher
Code example: Multiply the intensities of channel 1 and 2
// Get source bioassayset, extra value type and job(null can be used if no job) DbControl dc = ... BioAssaySet source = ... ExtraValueType type = ... Job job = ... // 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 from // the source bioassayset DynamicSpotQuery query = source.getSpotData(); // Execute the query, and use the batcher to insert the new values SpotExtraValueBatcher<Float> batcher = bas.getSpotExtraValueBatcher(Float.class, type, job); DynamicResultIterator spots = query.iterate(dc); int column = spots.getIndex(VirtualColumn.COLUMN.getName()); int position = spots.getIndex(VirtualColumn.POSITION.getName()); int ch1 = spots.getIndex(VirtualColumn.channel(1).getName()); int ch2 = spots.getIndex(VirtualColumn.channel(2).getName()); while (spots.hasNext()) { SqlResult r = spots.next(); batcher.insert(r.getShort(column), r.getInt(position), r.getFloat(ch1) * r.getFloat(ch2)); } // Close and commit batcher.close(); dc.commit();
- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2015-05-12 11:27:08 +0200 (ti, 12 maj 2015) $
-
Field Summary
Modifier and TypeFieldDescriptionprivate 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 spot data.private String
The SQL string for theextraSql
statement.private final ExtraValue
The extra value object which links the extra value type.private int
The number of queued inserts.private final int
The sql type code of the value to insert.private int
The total number of inserts done by this batcher.private final Type
The type of values to insert.Fields inherited from class net.sf.basedb.core.AbstractBatcher
debugSqlEnabled, logSql
-
Constructor Summary
ConstructorDescriptionSpotExtraValueBatcher
(DbControl dc, ExtraValue extraValue) Create a new spot batcher for a bioassayset. -
Method Summary
Modifier and TypeMethodDescriptionprivate String
buildInsertSelectSql
(String selectSql) Build the INSERT INTO ...private void
Builds the insert SQL statement.void
flush()
Flush the batcher and send all remaining items in memory to the database.Get the extra value item representing all extra values.void
Insert an extra value for a given column/position coordinate.int
insert
(AbstractSqlQuery query) Insert extra values using a query.(package private) void
Update disk usage and close open SQL statementsMethods inherited from class net.sf.basedb.core.AbstractBatcher
analyzeTable, close, getBatchSize, getDbControl, getSessionControl, isClosed, setBatchSize, setDbControl, updateLastAccess
-
Field Details
-
extraValue
The extra value object which links the extra value type. -
valueType
The type of values to insert. -
sqlType
private final int sqlTypeThe sql type code of the value to insert.- See Also:
-
bytesPerRow
private final long bytesPerRowThe number of bytes used by a single row. -
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. -
extraSql
The statement that inserts spot data.INSERT INTO Dynamic#SpotExtraXxx (cube, extra, column, position, value) VALUES (cube, extra, ?, ?, ?)
-
extraSqlStatement
The SQL string for theextraSql
statement.
-
-
Constructor Details
-
SpotExtraValueBatcher
SpotExtraValueBatcher(DbControl dc, ExtraValue extraValue) Create a new spot 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
Update disk usage and close open SQL statements- Overrides:
onBeforeClose
in classAbstractBatcher
- Throws:
BaseException
-
insert
Insert an extra value for a given column/position coordinate.- Parameters:
column
- The column coordinateposition
- The position coordinatevalue
- The extra value- Throws:
BaseException
- If there is another errorInvalidDataException
-
insert
Insert extra values using a query. The query MUST select data in the following order: column, position, extraValueInternally 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.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(short, 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 from // the source bioassayset DynamicSpotQuery query = source.getSpotData(); query.select(Dynamic.select(VirtualColumn.COLUMN)); query.select(Dynamic.select(VirtualColumn.POSITION)); Expression product = Expressions.multiply( Dynamic.column(VirtualColumn.channel(1)), Dynamic.column(VirtualColumn.channel(2)) ); query.select(Selections.expression(product, "product")); // 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();
- Parameters:
query
- The query that selects the data to be inserted- Returns:
- int The number of spots inserted
- Throws:
BaseException
- If there is an error
-
getExtraValue
Get the extra value item representing all extra values. -
buildSpotSql
Builds the insert SQL statement. Also creates the Dynamic#SpotExtraXxx table if it doesn't exists. -
buildInsertSelectSql
Build the INSERT INTO ... SELECT ... statment. Also creates the Dynamic#SpotExtraXxx table if it doesn't exists.- Parameters:
selectSql
- The SELECT part of the query- Throws:
BaseException
- See Also:
-