Source:
<code><START> public ResultsStream.QueryBuilder<String> findAllDeviceTokenForVariantIDByCriteria(String variantID, List<String> categories, List<String> aliases, List<String> deviceTypes, final int maxResults, String lastTokenFromPreviousBatch) { <END> final StringBuilder jpqlString = new StringBuilder(FIND_ALL_DEVICES_FOR_VARIANT_QUERY); final Map<String, Object> parameters = new LinkedHashMap<String, Object>(); parameters.put("variantID", variantID); appendDynamicQuery(jpqlString, parameters, categories, aliases, deviceTypes); if (lastTokenFromPreviousBatch != null) { jpqlString.append(" AND installation.deviceToken > :lastTokenFromPreviousBatch"); parameters.put("lastTokenFromPreviousBatch", lastTokenFromPreviousBatch); } jpqlString.append(" ORDER BY installation.deviceToken ASC"); return new ResultsStream.QueryBuilder<String>() { private Integer fetchSize = null; @Override public ResultsStream.QueryBuilder<String> fetchSize(int fetchSize) { this.fetchSize = fetchSize; return this; } @Override public ResultsStream<String> executeQuery() { Query hibernateQuery = JPAInstallationDao.this.createHibernateQuery(jpqlString.toString()); hibernateQuery.setMaxResults(maxResults); for (Entry<String, Object> parameter : parameters.entrySet()) { Object value = parameter.getValue(); if (value instanceof Collection<?>) { hibernateQuery.setParameterList(parameter.getKey(), (Collection<?>) parameter.getValue()); } else { hibernateQuery.setParameter(parameter.getKey(), parameter.getValue()); } } hibernateQuery.setReadOnly(true); if (fetchSize != null) { hibernateQuery.setFetchSize(fetchSize); } final ScrollableResults results = hibernateQuery.scroll(ScrollMode.FORWARD_ONLY); return new ResultsStream<String>() { @Override public boolean next() throws BatchException { return results.next(); } @Override public String get() throws BatchException { return (String) results.get()[0]; } }; } }; }</code><technical_language>this generic, for other results</technical_language>

Target:
public ResultsStream.QueryBuilder<String> findAllDeviceTokenForVariantIDByCriteria(String variantID, List<String> categories, List<String> aliases, List<String> deviceTypes, final int maxResults, String lastTokenFromPreviousBatch) { final StringBuilder jpqlString = new StringBuilder(FIND_ALL_DEVICES_FOR_VARIANT_QUERY); final Map<String, Object> parameters = new LinkedHashMap<String, Object>(); parameters.put("variantID", variantID); appendDynamicQuery(jpqlString, parameters, categories, aliases, deviceTypes); if (lastTokenFromPreviousBatch != null) { jpqlString.append(" AND installation.deviceToken > :lastTokenFromPreviousBatch"); parameters.put("lastTokenFromPreviousBatch", lastTokenFromPreviousBatch); } jpqlString.append(" ORDER BY installation.deviceToken ASC"); return new ResultsStream.QueryBuilder<String>() { private Integer fetchSize = null; @Override public ResultsStream.QueryBuilder<String> fetchSize(int fetchSize) { this.fetchSize = fetchSize; return this; } @Override public ResultsStream<String> executeQuery() { Query hibernateQuery = JPAInstallationDao.this.createHibernateQuery(jpqlString.toString()); hibernateQuery.setMaxResults(maxResults); for (Entry<String, Object> parameter : parameters.entrySet()) { Object value = parameter.getValue(); if (value instanceof Collection<?>) { hibernateQuery.setParameterList(parameter.getKey(), (Collection<?>) parameter.getValue()); } else { hibernateQuery.setParameter(parameter.getKey(), parameter.getValue()); } } hibernateQuery.setReadOnly(true); if (fetchSize != null) { hibernateQuery.setFetchSize(fetchSize); } final ScrollableResults results = hibernateQuery.scroll(ScrollMode.FORWARD_ONLY); return new ResultsStream<String>() { @Override public boolean next() throws ResultStreamException { return results.next(); } @Override public String get() throws ResultStreamException { return (String) results.get()[0]; } }; } }; }