Hi,
database driver name=Oracle JDBC driver
database driver version=9.2.0.5.0
database product version=Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Number of rows presnet in the DB = 2,000,000
Here is the Code:
public List getPageDataUsingCriteria(String className,
Map<String, Object> matchingCriteria,
String sortCol, int sortOrder,
int pagelength, int pageOffset, String[] colList)
throws IErrorException
{
Criteria criteria = getSession().createCriteria(className);
boolean isSortOrderChangeReq = false;
Set keys = matchingCriteria.keySet();
for(Object key : keys)
{
String propKey = (String) key;
List<Object> propValue = (List<Object>) matchingCriteria.get(propKey);
criteria.add(Expression.in(propKey, propValue));
}
criteria.setProjection(Projections.rowCount());
Object object = criteria.uniqueResult();
int totalCount = ((Integer)object).intValue();
System.out.println("Total Number of Rows = "+totalCount);
if( colList != null && colList.length > 0)
{
ProjectionList proj = Projections.projectionList();
for( String column: colList)
{
proj.add(Projections.property(column));
}
criteria.setProjection(proj);
}
if(sortOrder == IConstants.ASC_ORDER)
{
criteria.addOrder(Order.asc(sortCol));
criteria.addOrder(Order.asc("id")); //Todo
}
else
{
criteria.addOrder(Order.desc(sortCol));
criteria.addOrder(Order.desc("id")); //Todo
}
criteria.setMaxResults(pagelength);
criteria.setFirstResult(pageOffset);
List<Object[]> pageData = criteria.list();
if(pageData == null)
{
return new ArrayList();
}
return pageData;
}
Thanks
Venkat
|