public List<Employee> getData(int to, int from,
String searchField, String searchString, String searchOper,
String sord, String sidx) {
Criteria hCriteria = null;
List<Employee> viewDataList = null;
List<Employee> exactDataList = null;
try {
hSession = HibernateSessionFactory.getSession();
hTransaction = hSession.beginTransaction();
hCriteria = hSession.createCriteria(Employee.class);
if (searchString != null && searchField != null
&& searchOper != null) {
if (searchOper.equalsIgnoreCase("eq"))
hCriteria.add(Restrictions
.eq(searchField, searchString));
if (searchOper.equalsIgnoreCase("ne"))
hCriteria.add(Restrictions.ne(searchField, searchString));
if (searchOper.equalsIgnoreCase("lt"))
hCriteria.add(Restrictions.lt(searchField, searchString));
if (searchOper.equalsIgnoreCase("le"))
hCriteria.add(Restrictions.le(searchField, searchString));
if (searchOper.equalsIgnoreCase("gt"))
hCriteria.add(Restrictions.gt(searchField, searchString));
if (searchOper.equalsIgnoreCase("ge"))
hCriteria.add(Restrictions.ge(searchField, searchString));
if (searchOper.equalsIgnoreCase("cn"))
hCriteria.add(Restrictions.ilike(searchField, searchString,
MatchMode.ANYWHERE));
}
if (sord != null && sidx != null && !sidx.equals("")) {
if (sord.equals("asc"))
hCriteria.addOrder(Order.asc(sidx));
else
hCriteria.addOrder(Order.desc(sidx));
}
/*
hCriteria.setFirstResult(to);
hCriteria.setFirstResult(from);
*/
hCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
viewDataList = hCriteria.list();
// for limit
exactDataList=viewDataList.subList(from,to);
hTransaction.commit();
} catch (Exception e) {
hTransaction.rollback();
} finally {
try {
hSession.flush();
HibernateSessionFactory.closeSession();
} catch (Exception hExp) {
}
}
return exactDataList;
}