class PagingWriter {

    public void write(final QueryStatement queryStatement, final int pageNumber, final int pageSize) throws QueryBuildException {
        try {
            queryStatement.getBodyWriter().write("LIMIT(?)OFFSET(?)");
            queryStatement.pushParameterSetter((statement, index) -> {
                int size = pageSize;
                int page = pageNumber - 1;

                page = (page < 0) ? 0 : page;
                size = (size > MAX_PAGE_SIZE) ?
                        MAX_PAGE_SIZE : ((size < MIN_PAGE_SIZE) ? MIN_PAGE_SIZE : size);

                statement.setInt(index++, size);
                statement.setInt(index++, size * page);
                return index;
            });
        } catch (IOException e) {
            throw new QueryBuildException("Error while writing PAGING clause of search query", e);
        }
    }

    public  PagingWriter();

}