I try to implement pagination using with postgresql and primefaces' lazy datagrid model.
I call my db in this primeface's lazymodel overrided function:
@Override
public List<Query> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,Object> filters) {
queryDb.getQueries(settingsBean.getUserBean().getUser().getId(), pageSize, first);
setRowCount(queryDb.getTotal()); //total is total=rs.getRow(); (here is a problem I'll explain)
setPageSize(pageSize);
//and goes on...
}
In QueryDb.java, My search string is like:
public List<Query> getQueries(Integer user_id, Integer pageSize, Integer first){
String searchStr = "select * from public.saved_queries "
+ "where user_id=? "
+ "order by id desc "
+ "limit ? offset ? ";
//and then
statement.setInt(1, user_id);
statement.setInt(2, pageSize);
statement.setInt(3, first);
And my connection is:
statement=connection.prepareStatement(searchStr, rs.TYPE_SCROLL_INSENSITIVE,rs.CONCUR_UPDATABLE);
And I also want to get all row counts of that table to set lazy datagrid's row count.
rs.last();
total=rs.getRow();
But the problem is that total
is equal to primefaces' pagesize. Because I set the limit as primafaces page size. I need to gel all row count there.
How to get it?
setRowCount(queryDb.getTotal()); // this equals my pagesize, I need all row count of that table