jodd-joy/src/main/java/jodd/joy/page/DbPager.java
public <T> PageData<T> page(PageRequest pageRequest, final String sql, final Map params, final String[] sortColumns, final Class[] target) {
		if (pageRequest == null) {
			pageRequest = getDefaultPageRequest();
		}

		// check sort

		String sortColumName = null;
		boolean ascending = true;

		int sort = pageRequest.getSort();
		if (sort != 0) {
			ascending = sort > 0;
			if (!ascending) {
				sort = -sort;
			}
			int index = sort - 1;

			if (index >= sortColumns.length) {
				index = 1;
			}
			sortColumName = sortColumns[index];
		}

		// page

		int page = pageRequest.getPage();
		int pageSize = pageRequest.getSize();

		PageData<T> pageData = page(sql, params, page, pageSize, sortColumName, ascending, target);

		// fix the out-of-bounds

		if (pageData.getItems().isEmpty() && pageData.currentPage != 0) {
			if (pageData.currentPage != page) {
				// out of bounds
				int newPage = pageData.getCurrentPage();
				pageData = page(sql, params, newPage, pageSize, sortColumName, ascending, target);
			}
		}

		return pageData;
	}
public <T> PageData<T> page(PageRequest pageRequest, final String sql, final Map params, final String[] sortColumns, final Class[] target) {
		if (pageRequest == null) {
			pageRequest = getDefaultPageRequest();
		}

		// check sort

		String sortColumName = null;
		boolean ascending = true;

		int sort = pageRequest.getSort();
		if (sort != 0) {
			ascending = sort > 0;
			if (!ascending) {
				sort = -sort;
			}
			int index = sort - 1;

			if (index >= sortColumns.length) {
				index = 1;
			}
			sortColumName = sortColumns[index];
		}

		// page

		int page = pageRequest.getPage();
		int pageSize = pageRequest.getSize();

		PageData<T> pageData = page(sql, params, page, pageSize, sortColumName, ascending, target);

		// fix the out-of-bounds

		if (pageData.getItems().isEmpty() && pageData.currentPage != 0) {
			if (pageData.currentPage != page) {
				// out of bounds
				int newPage = pageData.getCurrentPage();
				pageData = page(sql, params, newPage, pageSize, sortColumName, ascending, target);
			}
		}

		return pageData;
	}
public < T > PageData < T > page ( PageRequest pageRequest , final String sql , final Map params , final String [ ] sortColumns , final Class [ ] target ) { if ( pageRequest == null ) { pageRequest = getDefaultPageRequest ( ) ; } // check sort String sortColumName = null ; boolean ascending = true ; int sort = pageRequest . getSort ( ) ; if ( sort != 0 ) { ascending = sort > 0 ; if ( ! ascending ) { sort = - sort ; } int index = sort - 1 ; if ( index >= sortColumns . length ) { index = 1 ; } sortColumName = sortColumns [ index ] ; } // page int page = pageRequest . getPage ( ) ; int pageSize = pageRequest . getSize ( ) ; PageData < T > pageData = page ( sql , params , page , pageSize , sortColumName , ascending , target ) ; // fix the out-of-bounds if ( pageData . getItems ( ) . isEmpty ( ) && pageData . currentPage != 0 ) { if ( pageData . currentPage != page ) { // out of bounds int newPage = pageData . getCurrentPage ( ) ; pageData = page ( sql , params , newPage , pageSize , sortColumName , ascending , target ) ; } } return pageData ; }
Performs the pagination with given {@link jodd.joy.page.PageRequest}.

@param pageRequest page request, may be <code>null</code>, then the {@link #getDefaultPageRequest() default page request} will be used
@param sql SQL query that lists <b>all</b> items
@param params SQL query parameters or <code>null</code>
@param sortColumns array of all column names
@param target db entities for mapping (as usual in DbOom)

@see #page(String, java.util.Map, int, int, String, boolean, Class[])
Performs the pagination with given { @link jodd . joy . page . PageRequest } .