}
public EntityTree doPagedQuery( String alias,String selection,String from,int pageSize,int pageNumber ) throws Throwable
{
String rowsQuery = "SELECT COUNT(*) FROM "+from;
EntityTree rowsResult = query( alias,rowsQuery );
int rows = Integer.parseInt( rowsResult.getChild("row").getChild("cell").getValue() );
int pagesAvailable = rows/pageSize;
int startRow = pageNumber*pageSize;
int endRow = (pageNumber+1)*pageSize;
String query = "SELECT * FROM ( SELECT p.*, ROWNUM row# FROM ( SELECT "+selection+" FROM "+from+") p WHERE ROWNUM < "+endRow+" ) WHERE row# >= "+startRow;
EntityTree result = query( alias,query );
result.setAttribute("pagesAvailable",""+pagesAvailable);
result.setAttribute("pageSize",""+pageSize);
result.setAttribute("pageNumber",""+pageNumber);
System.out.println("Database Processed Paged Query "+selection+" for schema alias "+alias+" page "+pageNumber+" of "+pageSize);
return result;
}