Groovy Sql wrapper for running scrollable/streaming queries. It provides a convenient way for iterating over records which correspond to a given sql query.
Constructor and description |
---|
ScrollableQuery
(RowMapper mapper, DataSource dataSource, int fetchSize = Integer.MIN_VALUE) Creates a ScrollableQuery instance with given parameters. |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
eachBatch(String query, int batchSize, Closure cl) Executes the query and calls the closure for each batch of records. |
|
void |
eachRow(String query, Closure closure) Executes the query and calls the closure for each row. |
|
protected Sql |
prepareSql() |
|
List |
rows(String query) Load all rows and return as a list, each row in the list would be converted using the passed RowMapper This method holds all rows in memory, so this should not be used if there is going to be large number of rows. |
Creates a ScrollableQuery instance with given parameters.
mapper
- a row mapperdataSource
- a datasourcefetchSize
- the number of result set rowsExecutes the query and calls the closure for each batch of records. For example, the next snippet of code prints records in batch and its size for every 10 records: eachBatch(sqlQuery, 10) { List batch -> println batch println batch.size() }*
query
- an sql query which represents recordsbatchSize
- number of records in a single batchclosure
- a closure which is called for each batchExecutes the query and calls the closure for each row.
query
- an sql query which represents recordsclosure
- a closure which is called for each rowLoad all rows and return as a list, each row in the list would be converted using the passed RowMapper This method holds all rows in memory, so this should not be used if there is going to be large number of rows. instead use the eachRow, eachBatch which works with the scrollable resultset
query
- an sql query which represents records