Example usage for org.hibernate Criteria setMaxResults

List of usage examples for org.hibernate Criteria setMaxResults

Introduction

In this page you can find the example usage for org.hibernate Criteria setMaxResults.

Prototype

public Criteria setMaxResults(int maxResults);

Source Link

Document

Set a limit upon the number of objects to be retrieved.

Usage

From source file:com.inkubator.datacore.dao.impl.IDAOImpl.java

/**
 * Get All data for specific Entity (T). Note this method only return data
 * that have primary key, page able, and Sorting
 *
 * @param firstResult is int type and begin from 0
 * @param maxResults is int type//from ww  w .  ja v a2 s .c  om
 * @param order
 * @return List of entity
 */
public List<T> getAllDataPageAble(int firstResult, int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.addOrder(order);
    criteria.add(Restrictions.isNotNull("id"));
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return (List<T>) criteria.list();
}

From source file:com.inkubator.datacore.dao.impl.IDAOImpl.java

/**
 * Get All data for specific Entity (T). Note this method only return data
 * that have primary key, page able, Sorting, and isActive condition
 *
 * @param firstResult is int type and begin from 0
 * @param maxResults is int type/*from   w  w  w  .  j  a va2  s . c  o m*/
 * @param order is Hibernate Order
 * @param isActive is Boolean condition true or false
 * @return List of entity
 */
public List<T> getAllDataPageAbleIsActive(int firstResult, int maxResults, Order order, Boolean isActive) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.addOrder(order);
    criteria.add(Restrictions.isNotNull("id"));
    cekIsActive(criteria, isActive);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return (List<T>) criteria.list();
}

From source file:com.inkubator.datacore.dao.impl.IDAOImpl.java

/**
 * Get All data for specific Entity (T). Note this method only return data
 * that have primary key, page able, Sorting, and isActive condition
 *
 * @param firstResult is int type and begin from 0
 * @param maxResults is int type//  w  w w  . j  a  va2  s.  c o m
 * @param order is Hibernate Order
 * @param isActive is Integer condition 0 or 1
 * @return List of entity
 */
public List<T> getAllDataPageAbleIsActive(int firstResult, int maxResults, Order order, Integer isActive) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.addOrder(order);
    criteria.add(Restrictions.isNotNull("id"));
    cekIsActive(criteria, isActive);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return (List<T>) criteria.list();
}

From source file:com.inkubator.datacore.dao.impl.IDAOImpl.java

/**
 * Get All data for specific Entity (T). Note this method only return data
 * that have primary key, page able, Sorting, and isActive condition
 *
 * @param firstResult is int type and begin from 0
 * @param maxResults is int type//from   ww  w.ja  va2  s .  co m
 * @param order is Hibernate Order
 * @param isActive is Byte condition -127 or 127
 * @return List of entity
 */
public List<T> getAllDataPageAbleIsActive(int firstResult, int maxResults, Order order, Byte isActive) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.addOrder(order);
    criteria.add(Restrictions.isNotNull("id"));
    cekIsActive(criteria, isActive);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return (List<T>) criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.ApprovalDefinitionDaoImpl.java

@Override
public List<ApprovalDefinition> getByParam(ApprovalDefinitionSearchParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchApprovalDefinitionByParam(searchParameter, criteria);
    criteria.addOrder(order);/*from  w w w.jav a2 s  .com*/
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.AttendanceStatusDaoImpl.java

@Override
public List<AttendanceStatus> getByParam(AttendanceStatusSearchParamater searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchAttendanceStatusByParam(searchParameter, criteria);
    criteria.addOrder(order);//from  w ww  . ja va 2  s.c om
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.BankGroupDaoImpl.java

@Override
public List<BankGroup> getByParam(BankGroupSearchParameter searchParameter, int firstResult, int maxResults,
        Order order) {//from   w  ww .jav a 2 s  . co m
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchByParam(searchParameter, criteria);
    criteria.addOrder(order);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.BatchJobExecutionDaoImpl.java

@Override
public List<BatchJobExecution> getByParam(BatchJobExecutionSearchParameter parameter, int firstResult,
        int maxResults, Order orderable) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("batchJobInstance", "batchJobInstance", JoinType.INNER_JOIN);

    if (parameter.getJobName() != null) {

        //            criteria.createAlias("batchJobInstance", "bj", JoinType.INNER_JOIN);
        criteria.add(Restrictions.like("batchJobInstance.jobName", parameter.getJobName(), MatchMode.ANYWHERE));
    }/*from www. j  ava 2s .c  o m*/
    if (parameter.getStatus() != null) {
        criteria.add(Restrictions.like("BatchJobExecution", parameter.getStatus()));
    }
    criteria.addOrder(orderable);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    //criteria.setFetchMode("batchJobInstance", FetchMode.JOIN);
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.BioDataDaoImpl.java

@Override
public List<BioData> getByParam(BioDataSearchParameter parameter, int firstResult, int maxResults,
        Order orderable) {/*w  w w.j  av  a2 s  .c o  m*/
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchBioDataByParam(parameter, criteria);
    criteria.setFetchMode("religion", FetchMode.JOIN);
    criteria.setFetchMode("maritalStatus", FetchMode.JOIN);

    criteria.addOrder(orderable);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

From source file:com.inkubator.hrm.dao.impl.BioDataDaoImpl.java

@Override
public List<BioData> getByName(String name) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    //        criteria.createAlias("empDatas", "emp",JoinType.INNER_JOIN);
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.like("firstName", name, MatchMode.ANYWHERE));
    disjunction.add(Restrictions.like("lastName", name, MatchMode.ANYWHERE));

    criteria.add(disjunction);// w w  w .ja  v a  2 s  .co m
    criteria.add(Restrictions.isEmpty("empDatas"));
    criteria.addOrder(Order.asc("firstName"));
    criteria.setFirstResult(0);
    criteria.setMaxResults(7);
    return criteria.list();
}