ps = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
ps.setLong(1, ctx.getTimeService().wallClockTime());
ps.setFetchSize(tableManipulation.getFetchSize());
rs = ps.executeQuery();
ExecutorAllCompletionService ecs = new ExecutorAllCompletionService(executor);
final TaskContextImpl taskContext = new TaskContextImpl();
//we can do better here: ATM we load the entries in the caller's thread and process them in parallel
// we can do the loading (expensive operation) in parallel as well.
while (rs.next()) {
InputStream binaryStream = rs.getBinaryStream(1);
final Bucket bucket = unmarshallBucket(binaryStream);
ecs.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
for (MarshalledEntry me : bucket.getStoredEntries(filter, ctx.getTimeService()).values()) {
if (!taskContext.isStopped()) {
if (!fetchValue || !fetchMetadata) {
me = ctx.getMarshalledEntryFactory().newMarshalledEntry(me.getKey(),
fetchValue ? me.getValue() : null, fetchMetadata ? me.getMetadata() : null);
}
task.processEntry(me, taskContext);