Source:
public Collection<String> getArticleDoisForDateRange( int pageNumber, int pageSize, SortOrder sortOrder, Optional<LocalDateTime> fromDate, Optional<LocalDateTime> toDate) { final long totalArticles = hibernateTemplate.execute(session -> { final Query query = session.createQuery("select count(*) from Article"); final Long count = (Long) query.uniqueResult(); return count; }); if (totalArticles > 0L) { pageNumber = max(pageNumber, 1); final int maxResults = min(pageSize, MAX_PAGE_SIZE); final int firstResult = (pageNumber - 1) * maxResults; if (LOG.isDebugEnabled()) { LOG.debug("pageNumber: {}, pageSize: {}", pageNumber, pageSize); LOG.debug("firstResult: {}, maxResults: {}", firstResult, maxResults); LOG.debug("sortOrder: {}", sortOrder); } if (firstResult < totalArticles) { final DetachedCriteria criteria = DetachedCriteria.forClass(Article.class); final ProjectionList projections = Projections.projectionList(); projections.add(Projections.property("doi" )); criteria.setProjection(projections); if (fromDate.isPresent()) { criteria.add(Restrictions.ge( "created" , java.sql.Timestamp.valueOf(fromDate.get()))); } if (toDate.isPresent()) { criteria.add(Restrictions.le( "created" , java.sql.Timestamp.valueOf(toDate.get()))); } if (sortOrder == SortOrder.OLDEST) { criteria.addOrder(Order.asc("created" )); criteria.addOrder(Order.asc("articleId")); } else { criteria.addOrder(Order.desc("created" )); criteria.addOrder(Order.asc("articleId")); } @SuppressWarnings("unchecked") final List<String> articleDois = (List<String>) hibernateTemplate.findByCriteria( criteria, firstResult, maxResults); return articleDois; } } return ImmutableList.of(); }

Target:
public Collection<String> getArticleDoisForDateRange( int pageNumber, int pageSize, SortOrder sortOrder, Optional<LocalDateTime> fromDate, Optional<LocalDateTime> toDate) { final long totalArticles = hibernateTemplate.execute(session -> { final Query query = session.createQuery("select count(*) from Article"); final Long count = (Long) query.uniqueResult(); return count; }); if (totalArticles > 0L) { pageNumber = max(pageNumber, 1); final int maxResults = min(pageSize, MAX_PAGE_SIZE); final int firstResult = (pageNumber - 1) * maxResults; if (LOG.isDebugEnabled()) { LOG.debug("pageNumber: {}, pageSize: {}", pageNumber, pageSize); LOG.debug("firstResult: {}, maxResults: {}", firstResult, maxResults); LOG.debug("sortOrder: {}", sortOrder); } if (firstResult < totalArticles) { final DetachedCriteria criteria = DetachedCriteria.forClass(Article.class); final ProjectionList projections = Projections.projectionList(); projections.add(Projections.property("doi" )); criteria.setProjection(projections); if (fromDate.isPresent()) { criteria.add(Restrictions.ge( "created" , java.sql.Timestamp.valueOf(fromDate.get()))); } if (toDate.isPresent()) { criteria.add(Restrictions.le( "created" , java.sql.Timestamp.valueOf(toDate.get()))); } if (sortOrder == SortOrder.OLDEST) { criteria.addOrder(Order.asc("created" )); } else { criteria.addOrder(Order.desc("created" )); } criteria.addOrder(Order.asc("articleId")); @SuppressWarnings("unchecked") final List<String> articleDois = (List<String>) hibernateTemplate.findByCriteria( criteria, firstResult, maxResults); return articleDois; } } return ImmutableList.of(); }