Example usage for org.hibernate Criteria createAlias

List of usage examples for org.hibernate Criteria createAlias

Introduction

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

Prototype

@Deprecated
public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException;

Source Link

Document

Join an association using the specified join-type, assigning an alias to the joined association.

Usage

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

@Override
public List<EmpData> getAllDataNotTerminatePaging(TempAttendanceRealizationSearchParameter parameter,
        int firstResult, int maxResult, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.not(Restrictions.eq("status", HRMConstant.EMP_TERMINATION)));
    if (parameter.getNik() != null) {
        criteria.add(Restrictions.like("nik", parameter.getNik(), MatchMode.ANYWHERE));
    }/*from w  w w.  j ava2s. c  om*/
    criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN);
    if (parameter.getName() != null) {
        //            criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN);
        Disjunction orCondition = Restrictions.disjunction();
        orCondition.add(
                Restrictions.ilike("bio.combineName", parameter.getName().toLowerCase(), MatchMode.ANYWHERE));
        orCondition.add(Restrictions.like("nik", parameter.getName(), MatchMode.ANYWHERE));
        criteria.add(orCondition);
    }

    //String sorting = "bio." + order;
    criteria.addOrder(order);
    //        if (order==null) {
    //            criteria.addOrder(order);
    //        } else {
    //            if (order.isAscending()) {
    //             
    //                criteria.addOrder(Order.asc(sorting));
    //            } else {
    //                
    //                criteria.addOrder(Order.desc(sorting));
    //            }
    //        }

    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResult);
    return criteria.list();
}

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

@Override
public Long getTotalNotTerminatePaging(TempAttendanceRealizationSearchParameter parameter) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());

    criteria.add(Restrictions.not(Restrictions.eq("status", HRMConstant.EMP_TERMINATION)));
    if (parameter.getNik() != null) {
        criteria.add(Restrictions.like("nik", parameter.getNik(), MatchMode.ANYWHERE));
    }/*from   w  w  w.ja  v a  2  s .  com*/

    if (parameter.getName() != null) {
        criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN);
        Disjunction orCondition = Restrictions.disjunction();
        orCondition.add(
                Restrictions.ilike("bio.combineName", parameter.getName().toLowerCase(), MatchMode.ANYWHERE));
        orCondition.add(Restrictions.like("nik", parameter.getName(), MatchMode.ANYWHERE));
        criteria.add(orCondition);
    }
    return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
}

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

@Override
public EmpData getByIdWithBioData(long id) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.add(Restrictions.eq("id", id));
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    return (EmpData) criteria.uniqueResult();
}

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

@Override
public List<EmpData> getAllDataByParam(EmpDataSearchParameter searchParameter, int firstResult, int maxResults,
        Order order) {// w w w. j  a  v a2s .  c  o m
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("golonganJabatan", "golonganJabatan", JoinType.LEFT_OUTER_JOIN);
    //        criteria.createAlias("taxFree", "taxFree", JoinType.INNER_JOIN);
    criteria.setFetchMode("bioData.city", FetchMode.JOIN);
    criteria.setFetchMode("bioData.maritalStatus", 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);
    doSearchByParam(searchParameter, criteria);
    criteria.addOrder(order);
    criteria.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

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

private void doSearchByParam(EmpDataSearchParameter dataSearchParameter, Criteria criteria) {
    criteria.add(Restrictions.not(Restrictions.eq("status", HRMConstant.EMP_TERMINATION)));

    criteria.createAlias("jabatanByJabatanId", "jabatanByJabatanId", JoinType.INNER_JOIN);
    criteria.createAlias("wtGroupWorking", "wtGroupWorking", JoinType.LEFT_OUTER_JOIN);
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);

    if (dataSearchParameter.getJabatanKode() != null) {
        criteria.add(Restrictions.like("jabatanByJabatanId.code", dataSearchParameter.getJabatanKode(),
                MatchMode.START));//from www  . j  ava  2  s .  co m
    }
    if (dataSearchParameter.getJabatanName() != null) {
        criteria.add(Restrictions.like("jabatanByJabatanId.name", dataSearchParameter.getJabatanName(),
                MatchMode.ANYWHERE));
    }
    if (dataSearchParameter.getWorkingGroupName() != null) {
        criteria.add(Restrictions.like("wtGroupWorking.name", dataSearchParameter.getWorkingGroupName(),
                MatchMode.ANYWHERE));
    }
    if (dataSearchParameter.getNIK() != null) {
        criteria.add(Restrictions.like("nik", dataSearchParameter.getNIK(), MatchMode.START));
    }
    if (dataSearchParameter.getName() != null) {
        criteria.add(Restrictions.ilike("bioData.combineName", dataSearchParameter.getName().toLowerCase(),
                MatchMode.ANYWHERE));
    }
}

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

@Override
public List<EmpData> getAllDataByParamForOnlyEmployee(Long companyId, EmpDataSearchParameter searchParameter,
        int firstResult, int maxResults, Order order) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    doSearchByParamOnlyEmployee(companyId, searchParameter, criteria);
    criteria.addOrder(order);/* w  w w.java  2  s  .c  o m*/
    criteria.createAlias("golonganJabatan", "golonganJabatan", JoinType.LEFT_OUTER_JOIN);
    //        criteria.createAlias("taxFree", "taxFree", JoinType.INNER_JOIN);
    criteria.setFetchMode("bioData.city", FetchMode.JOIN);
    criteria.setFetchMode("bioData.maritalStatus", 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.setFirstResult(firstResult);
    criteria.setMaxResults(maxResults);
    return criteria.list();
}

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

private void doSearchByParamOnlyEmployee(Long companyId, EmpDataSearchParameter dataSearchParameter,
        Criteria criteria) {
    criteria = this.addJoinRelationsOfCompanyId(criteria, companyId);
    criteria.add(Restrictions.not(Restrictions.eq("status", HRMConstant.EMP_TERMINATION)));
    if (dataSearchParameter.getJabatanKode() != null) {
        criteria.add(Restrictions.like("jabatanByJabatanId.code", dataSearchParameter.getJabatanKode(),
                MatchMode.START));/* w ww.  j  ava2 s.co  m*/
    }

    if (dataSearchParameter.getJabatanName() != null) {
        criteria.add(Restrictions.like("jabatanByJabatanId.name", dataSearchParameter.getJabatanName(),
                MatchMode.ANYWHERE));
    }

    if (dataSearchParameter.getNIK() != null) {
        criteria.add(Restrictions.like("nik", dataSearchParameter.getNIK(), MatchMode.START));
    }
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    if (dataSearchParameter.getName() != null) {
        criteria.add(Restrictions.ilike("bioData.combineName", dataSearchParameter.getName().toLowerCase(),
                MatchMode.ANYWHERE));
    }
}

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

private void doSearchByParamOnlyEmployeeNotIncludeCompany(EmpDataSearchParameter dataSearchParameter,
        Criteria criteria) {
    //        criteria = this.addJoinRelationsOfCompanyId(criteria, companyId);
    //        criteria.add(Restrictions.not(Restrictions.eq("status", HRMConstant.EMP_TERMINATION)));
    //        if (dataSearchParameter.getJabatanKode() != null) {
    //            criteria.add(Restrictions.like("jabatanByJabatanId.code", dataSearchParameter.getJabatanKode(), MatchMode.START));
    //        }/*w  ww  .  java 2s  .c  om*/
    //
    //        if (dataSearchParameter.getJabatanName() != null) {
    //            criteria.add(Restrictions.like("jabatanByJabatanId.name", dataSearchParameter.getJabatanName(), MatchMode.ANYWHERE));
    //        }
    criteria.createAlias("taxFree", "taxFree", JoinType.LEFT_OUTER_JOIN);
    if (dataSearchParameter.getNIK() != null) {
        criteria.add(Restrictions.like("nik", dataSearchParameter.getNIK(), MatchMode.START));
    }
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    if (dataSearchParameter.getName() != null) {
        criteria.add(Restrictions.ilike("bioData.combineName", dataSearchParameter.getName().toLowerCase(),
                MatchMode.ANYWHERE));
    }
}

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

@Override
public List<EmpData> getAllByJabatanAndCompanyAndStatus(long jabataId, String status) {
    Criteria criteria = getCurrentSession().createCriteria(getEntityClass());
    criteria.createAlias("bioData", "bi", JoinType.INNER_JOIN);
    criteria.createAlias("jabatanByJabatanId", "jb", JoinType.INNER_JOIN);
    criteria.add(Restrictions.eq("jb.id", jabataId));
    criteria.add(Restrictions.not(Restrictions.eq("status", status)));
    criteria.setFetchMode("bioData", FetchMode.JOIN);
    criteria.addOrder(Order.asc("bi.firstName"));
    return criteria.list();
}

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

public void doSearchEmployeeForRecruitAggrementNotice(RecruitAgreementNoticeSearchParameter searchParameter,
        Criteria criteria) {
    criteria.createAlias("bioData", "bioData", JoinType.INNER_JOIN);
    criteria.createAlias("jabatanByJabatanId", "jabatanByJabatanId", JoinType.INNER_JOIN);

    if (searchParameter.getEmpDataName() != null) {
        criteria.add(Restrictions.ilike("bioData.combineName", searchParameter.getEmpDataName().toLowerCase(),
                MatchMode.ANYWHERE));/*from   w  w  w  . jav a 2s  . c  o  m*/
    }
}