0

I am using query builder to return number of search result from the database table. Now I would like to display the result in the UI by only first three rows. How can I achieve this?

Vasanth
  • 35
  • 5

1 Answers1

1

QueryAPI is lazy, when .toList(), .toTypedArray(), .toCollection(), .where(), etc occurs all resultset is retrieved (eager).

I recommend you to use this:

var limit = 3
var rs = Query.make(entity.XXX)...select()
rs.setPageSize(limit)
var paginatedRS = com.google.common.collect.Iterables.limit(rs,limit)

setPageSize method specifies how many rows will be fetch "by page"

limit method make a new iterator that have only the first (limit) rows

Carlos Duque
  • 482
  • 3
  • 7