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.hrm.dao.impl.BioPotensiSwotDaoImpl.java

@Override
public List<BioPotensiSwot> getByParam(BioPotensiSwotSearchParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchByParam(searchParameter, criteria);
    criteria.addOrder(order);//w ww . j a v  a2 s.  c  o  m
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

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

@Override
public List<BioRelasiPerusahaan> getByParam(BioRelasiPerusahaanSearchParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchByParam(searchParameter, criteria);
    criteria.addOrder(order);/*from   w  w w  .j  a v  a 2 s.c  om*/
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

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

@Override
public List<CareerTerminationType> getListByParam(CareerTerminationTypeSearchParameter searchParameter,
        int firstResult, int maxResults, Order orderable) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchTerminationTypeByParam(searchParameter, criteria);
    criteria.addOrder(orderable);/*  w  w w .j a v a 2  s  .c  o m*/
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);

    return criteria.list();
}

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

@Override
public List<Divisi> getByParam(DivisiSearchParameter searchParameter, int firstResult, int maxResults,
        Order order) {//from www  .  ja  v  a2s .  c  o  m
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchByParam(searchParameter, criteria);
    criteria.addOrder(order);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    //criteria.setFetchMode("department", FetchMode.JOIN);
    criteria.createAlias("department", "department", JoinType.INNER_JOIN);
    return criteria.list();
}

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

@Override
public List<EmpCareerHistory> getByParamReport(ReportEmpMutationParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    criteria.createAlias("jabatan", "jabatan", JoinType.INNER_JOIN);
    doSearchEmpRotasiByParamReport(searchParameter, criteria);

    DetachedCriteria maxTglPengangkatanQuery = DetachedCriteria.forClass(getEntityClass());
    ProjectionList proj = Projections.projectionList();
    proj.add(Projections.max("tglPenganngkatan"));
    proj.add(Projections.groupProperty("nik"));
    maxTglPengangkatanQuery.setProjection(proj);

    criteria.add(Subqueries.propertiesIn(new String[] { "tglPenganngkatan", "nik" }, maxTglPengangkatanQuery));
    criteria.addOrder(order);/*from  w  w w. ja v a 2  s . c  o m*/
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);

    List<EmpCareerHistory> listEmpCareerHistorys = criteria.list();

    //Set Jabatan Lama/sebelumnya dari masing - masing record
    for (EmpCareerHistory ech : listEmpCareerHistorys) {
        Criteria criteriaOldPosition = getCurrentSession().createCriteria(getEntityClass());
        criteriaOldPosition.setFetchMode("jabatan", FetchMode.JOIN);
        criteriaOldPosition.add(Restrictions.eq("nik", ech.getNik()));
        criteriaOldPosition.add(Restrictions.lt("tglPenganngkatan", ech.getTglPenganngkatan()));
        criteriaOldPosition.addOrder(Order.desc("tglPenganngkatan"));
        criteriaOldPosition.setMaxResults(1);
        EmpCareerHistory prevPosition = (EmpCareerHistory) criteriaOldPosition.uniqueResult();

        //jika sebelumnya dia sudah pernah menjabat di posisi lain maka set oldJabatan dengan posisi tersebut
        if (null != prevPosition) {
            ech.setJabatanOldCode(prevPosition.getJabatan().getCode());
            ech.setJabatanOldName(prevPosition.getJabatan().getName());
        } else {
            ech.setJabatanOldCode("-");
        }
    }

    return listEmpCareerHistorys;
}

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

@Override
public List<EmpData> getAllDataByParam(Long companyId, EmpDataSearchParameter searchParameter, int firstResult,
        int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchByParam(companyId, searchParameter, criteria);
    criteria.addOrder(order);//w  ww  .j  a va  2s .co m
    criteria.createAlias("golonganJabatan", "golonganJabatan", JoinType.LEFT_OUTER_JOIN);
    //        criteria.createAlias("bioData", "bioData", JoinType.LEFT_OUTER_JOIN);

    //        criteria.createAlias("jabatanByJabatanId", "bioData", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("taxFree", "taxFree", JoinType.INNER_JOIN);
    //        criteria.setFetchMode("bioData", FetchMode.JOIN);
    criteria.setFetchMode("bioData.city", FetchMode.JOIN);
    criteria.setFetchMode("bioData.maritalStatus", FetchMode.JOIN);
    //        criteria.setFetchMode("jabatanByJabatanId", FetchMode.JOIN);
    //        criteria.setFetchMode("golonganJabatan", FetchMode.JOIN);
    criteria.setFetchMode("golonganJabatan.pangkat", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.department", FetchMode.JOIN);
    criteria.setFetchMode("jabatanByJabatanId.unitKerja", FetchMode.JOIN);
    criteria.setFetchMode("wtGroupWorking", FetchMode.JOIN);
    //        criteria.setFetchMode("taxFree", FetchMode.JOIN);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

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

@Override
public List<EmpData> getAllDataByNameOrNik(String param, Long companyId) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    /**/*  www .j  a v a2 s . c  om*/
     * automatically get relations of jabatanByJabatanId, department,
     * company don't create alias for that entity, or will get error :
     * duplicate association path
     */
    criteria = this.addJoinRelationsOfCompanyId(criteria, companyId);
    //criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION));
    criteria.add(Restrictions.isNotNull("status"));
    criteria.add(Restrictions
            .not(Restrictions.in("status", Arrays.asList(HRMConstant.EMP_TERMINATION, HRMConstant.EMP_DISCHAGED,
                    HRMConstant.EMP_LAID_OFF, HRMConstant.EMP_STOP_CONTRACT, HRMConstant.EMP_PENSION))));

    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.like("bioData.firstName", param, MatchMode.ANYWHERE));
    disjunction.add(Restrictions.like("bioData.lastName", param, MatchMode.ANYWHERE));
    disjunction.add(Restrictions.like("nik", param, MatchMode.ANYWHERE));
    criteria.add(disjunction);
    criteria.setMaxResults(20);
    return criteria.list();
}

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

@Override
public List<EmpData> getAllDataByNameOrNik(String param) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    //criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION));
    criteria.add(Restrictions.isNotNull("status"));
    criteria.add(Restrictions/*from   ww w  . j a  va 2  s  .  co  m*/
            .not(Restrictions.in("status", Arrays.asList(HRMConstant.EMP_TERMINATION, HRMConstant.EMP_DISCHAGED,
                    HRMConstant.EMP_LAID_OFF, HRMConstant.EMP_STOP_CONTRACT, HRMConstant.EMP_PENSION))));

    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    Disjunction disjunction = Restrictions.disjunction();
    disjunction.add(Restrictions.like("bioData.firstName", param, MatchMode.ANYWHERE));
    disjunction.add(Restrictions.like("bioData.lastName", param, MatchMode.ANYWHERE));
    disjunction.add(Restrictions.like("nik", param, MatchMode.ANYWHERE));
    criteria.add(disjunction);
    criteria.setMaxResults(20);
    return criteria.list();
}

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

@Override
public List<EmpData> getAllDataNotExistInUserByParam(String param, int firstResult, int maxResults,
        Order order) {/*ww w .jav a  2 s .  c o  m*/
    DetachedCriteria subQuery = DetachedCriteria.forClass(HrmUser.class, "user")
            .setProjection(Projections.property("user.id"));
    subQuery.add(Property.forName("employee.id").eqProperty("user.empData.id"));

    Criteria criteria = getCurrentSession().createCriteria(getEntityClass(), "employee");
    criteria.add(Subqueries.notExists(subQuery));
    criteria = this.doSearchNotExistInUserByParam(param, criteria);

    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    criteria.addOrder(order);

    return criteria.list();
}

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

@Override
public List<EmpData> getAllDataReportEmpWorkingGroupByParam(ReportEmpWorkingGroupParameter param,
        int firstResult, int maxResults, Order orderable) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    criteria.createAlias("wtGroupWorking", "wtGroupWorking", JoinType.LEFT_OUTER_JOIN);
    doSearchReportEmpWorkingGroupByParam(param, criteria);
    criteria.addOrder(orderable);/* www. j  ava  2s  .  com*/
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}