Pagination Handler Design advice
Original Problem: one of the SQL queries in my application returns a large resultset. Instead of sending the whole resultset to the client app, I have added changes to return finite number of rows based on User Input.
Solution: This is a classical problem and found numerous resources on the web which were useful. I have already created a class which will read the user page request and return only a finite no of rows.
Problem: There are other parts of my application which could also have a similar problem. So, I thought of designing an abstract Pagination handler and have designed it as follows:
class PaginationHandler{
/**
* Returns only a finite number of rows based on user requested page.
*
*@param pageRequested page requested by the user
*@param daoClassName name of the DAO class
*@param daoMethodName name of method to be invoked in the DAO class
*@param argListToDAOMethod arguments of the DAO method
*@param classTypeofArgs class types of args to the DAO method
*/
publicstatic Page getPage(int pageRequested, String daoClassName, String daoMethodName, Object[] argListToDAOMethod, Class[] classTypesOfArguments)
{
Class daoClass = Class.forName(daoClassName);
Method method = daoClass.getMethod(daoMethodName, classTypeofArgs);
/**
* code for setting up DAO method to return finite number of rows goes here which is 3-4 lines of code.
*/
// finally invoke the DAO method which returns a finite list
List pageList = (List) method.invoke(dao, argListToDAOMethod);
}
}
// from my business class, i will call this method as follows
someMethod()
{
// let's assume in my EmployeeDAO class, I have a method that returns a list of all employees. Also, the method takes a String andinteger as params.
Object[] obArray =new Object[2];
ob[0] = location;// string
ob[1] = age;// integer
Class[] classArray =new Class[2];
classArray[0] = String.class;
classArray[1] = int.class;
PaginationHandler.getPage(10,"com.ibm.software.EmployeeDAO","getEmployeeList", obArray, classArray);
}
The code above works fine. However, my major hearburn is due the fact that I will need to pass the arguments to the DAO method as an Object array since it could vary from one method to the next. Also, if some of the arguments are null, then, I cannot determine the classtype from within my PageHandler method. Hence, I need the Class types of all the arguments.
So, I am contemplating whether to copy this function into each Business class and customize it there and not worry about code duplication since, forcing the caller to send an array of class types looks awkward.
Any input will help.
Jawahar

