List of usage examples for org.hibernate Criteria setResultTransformer
public Criteria setResultTransformer(ResultTransformer resultTransformer);
From source file:com.indicator_engine.dao.GLAQuestionDaoImpl.java
License:Open Source License
/** * Updates the Execution Statistics Counter of a Specific Question. * @param ID Question ID to be searched and updated. * *///from w ww.ja v a 2 s . c o m @Override @Transactional public void updateStatistics(long ID) { Session session = factory.getCurrentSession(); GLAQuestion glaQuestion = null; Calendar calendar = Calendar.getInstance(); java.util.Date now = calendar.getTime(); Criteria criteria = session.createCriteria(GLAQuestion.class); criteria.setFetchMode("glaIndicators", FetchMode.JOIN); criteria.setFetchMode("glaQuestionProps", FetchMode.JOIN); criteria.add(Restrictions.eq("id", ID)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); Object result = criteria.uniqueResult(); if (result != null) { glaQuestion = (GLAQuestion) result; } glaQuestion.getGlaQuestionProps().setLast_executionTime(new java.sql.Timestamp(now.getTime())); glaQuestion.getGlaQuestionProps() .setTotalExecutions(glaQuestion.getGlaQuestionProps().getTotalExecutions() + 1); factory.getCurrentSession().saveOrUpdate(glaQuestion); }
From source file:com.indicator_engine.dao.GLAQuestionDaoImpl.java
License:Open Source License
@Override @Transactional// w w w.j av a 2s . c o m public List<GLAQuestion> searchQuestionsName(String searchParameter, boolean exactSearch, String colName, String sortDirection, boolean sort) { if (!exactSearch) searchParameter = "%" + searchParameter + "%"; Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLAQuestion.class); criteria.setFetchMode("glaIndicators", FetchMode.JOIN); criteria.setFetchMode("glaQuestionProps", FetchMode.JOIN); if (!exactSearch) criteria.add(Restrictions.ilike("question_name", searchParameter)); else criteria.add(Restrictions.eq("question_name", searchParameter)); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (sort) { if (sortDirection.equals("asc")) criteria.addOrder(Order.asc(colName)); else criteria.addOrder(Order.desc(colName)); } return criteria.list(); }
From source file:com.indicator_engine.dao.GLAUserDaoImpl.java
License:Open Source License
@Override @Transactional(readOnly = true)//www .j a va 2 s .c o m public List<GLAUser> loadAll(String colName, String sortDirection, boolean sort) { Session session = factory.getCurrentSession(); Criteria criteria = session.createCriteria(GLAUser.class); criteria.setFetchMode("events", FetchMode.JOIN); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); if (sort) { if (sortDirection.equals("asc")) criteria.addOrder(Order.asc(colName)); else criteria.addOrder(Order.desc(colName)); } return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public List<EmpData> getEmployeeBySearchEmployeeLeave(DistributionLeaveSchemeModel model) { DetachedCriteria listEmp = DetachedCriteria.forClass(LeaveDistribution.class) .setProjection(Property.forName("empData.id")).createAlias("leave", "lv", JoinType.INNER_JOIN) .add(Restrictions.eq("lv.id", model.getLeaveSchemeId())); Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**/* w w w. jav a 2 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, HrmUserInfoUtil.getCompanyId()); criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); // criteria.createAlias("leaveDistributions", "lv", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("employeeType", "empType", JoinType.INNER_JOIN); criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN); criteria.createAlias("golonganJabatan", "goljab", JoinType.INNER_JOIN); criteria.add(Property.forName("id").notIn(listEmp)); criteria.add(Restrictions.eq("status", HRMConstant.EMP_TERMINATION)); //ambil yg working groupnya bukan yg dipilih, dan belum punya working group // if (model.getLeaveSchemeId() != 0 || model.getLeaveSchemeId() != null) { // Disjunction disjunction = Restrictions.disjunction(); // disjunction.add(Restrictions.isNull("lv.empData")); // disjunction.add(Restrictions.not(Restrictions.eq("lv.leave.id", model.getLeaveSchemeId()))); // criteria.add(disjunction); // } //balance // if (model.getStartBalance() != 0.0){ // criteria.add(Restrictions.eq("lv.balance", model.getStartBalance())); // } //departermen equal or like if (model.getDepartmentLikeOrEqual() != 3) { if (Objects.equals(model.getDepartmentLikeOrEqual(), HRMConstant.DEPARTMENT_EQUAL)) { criteria.add(Restrictions.eq("department.departmentName", model.getDepartmentName())); } else { criteria.add(Restrictions.like("department.departmentName", model.getDepartmentName(), MatchMode.ANYWHERE)); } } //employee type equal or likeS if (model.getEmployeeTypeLikeOrEqual() != 3) { if (Objects.equals(model.getEmployeeTypeLikeOrEqual(), HRMConstant.EMPLOYEE_TYPE_EQUAL)) { criteria.add(Restrictions.eq("empType.name", model.getEmployeeTypeName())); } else { criteria.add(Restrictions.like("empType.name", model.getEmployeeTypeName(), MatchMode.ANYWHERE)); } } //gender criteria.add(Restrictions.eq("bio.gender", model.getGender())); //goljab if (model.getGolonganJabatanId() != 0) { criteria.add(Restrictions.eq("goljab.id", model.getGolonganJabatanId())); } String sortBy; if (Objects.equals(model.getSortBy(), HRMConstant.SORT_BY_NIK)) { sortBy = "nik"; } else { sortBy = "bio.firstName"; } if (Objects.equals(model.getOrderBy(), HRMConstant.ORDER_BY_ASC)) { criteria.addOrder(Order.asc(sortBy)); } else { criteria.addOrder(Order.desc(sortBy)); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
@Override public List<EmpData> getEmployeeByOtSearchParameter(DistributionOvetTimeModel model) { DetachedCriteria listEmp = DetachedCriteria.forClass(OverTimeDistribution.class) .setProjection(Property.forName("empData.id")) .createAlias("wtOverTime", "wtOverTime", JoinType.INNER_JOIN) .add(Restrictions.eq("wtOverTime.id", model.getOverTimeId())); Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /**//from w w w .java 2 s . co m * 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, HrmUserInfoUtil.getCompanyId()); criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("overTimeDistributions", "ot", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("ot.wtOverTime", "wt", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("employeeType", "empType", JoinType.INNER_JOIN); criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN); criteria.add(Property.forName("id").notIn(listEmp)); // criteria.createAlias("golonganJabatan", "goljab", JoinType.INNER_JOIN); /*if (model.getOverTimeId() != 0 || model.getOverTimeId() != null) { Criterion andCondition = Restrictions.conjunction() .add(Restrictions.isNotNull("ot.empData")) .add(Restrictions.not(Restrictions.eq("wt.id", model.getOverTimeId()))); // criteria.add(Restrictions.isNull("ot.empData")); Criterion completeCondition = Restrictions.disjunction().add(andCondition) .add(Restrictions.isNull("ot.empData")); // Disjunction conjunction = Restrictions.conjunction(); // disjunction.add(Restrictions.isNotNull("ot.empData")); // disjunction.add(Restrictions.not(Restrictions.eq("ot.wtOverTime.id", model.getOverTimeId()))); criteria.add(completeCondition); }*/ //balance // if (model.getStartBalance() != 0.0){ // criteria.add(Restrictions.eq("lv.balance", model.getStartBalance())); // } //departermen equal or like if (model.getDepartmentLikeOrEqual() != 3) { if (Objects.equals(model.getDepartmentLikeOrEqual(), HRMConstant.DEPARTMENT_EQUAL)) { criteria.add(Restrictions.eq("department.departmentName", model.getDepartmentName())); } else { criteria.add(Restrictions.like("department.departmentName", model.getDepartmentName(), MatchMode.ANYWHERE)); } } //employee type equal or likeS if (model.getEmployeeTypeLikeOrEqual() != 3) { if (Objects.equals(model.getEmployeeTypeLikeOrEqual(), HRMConstant.EMPLOYEE_TYPE_EQUAL)) { criteria.add(Restrictions.eq("empType.name", model.getEmployeeTypeName())); } else { criteria.add(Restrictions.like("empType.name", model.getEmployeeTypeName(), MatchMode.ANYWHERE)); } } //gender criteria.add(Restrictions.eq("bio.gender", model.getGender())); //goljab if (model.getGolonganJabatanId() != 0) { criteria.add(Restrictions.eq("goljab.id", model.getGolonganJabatanId())); } String sortBy; if (Objects.equals(model.getSortBy(), HRMConstant.SORT_BY_NIK)) { sortBy = "nik"; } else { sortBy = "bio.firstName"; } if (Objects.equals(model.getOrderBy(), HRMConstant.ORDER_BY_ASC)) { criteria.addOrder(Order.asc(sortBy)); } else { criteria.addOrder(Order.desc(sortBy)); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.EmpDataDaoImpl.java
/** * automatically get relations of jabatanByJabatanId, department, company * don't create alias for that entity, or will get error : duplicate * association path// ww w. j a va 2s. c o m */ /* criteria = this.addJoinRelationsOfCompanyId(criteria, HrmUserInfoUtil.getCompanyId()); criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); // criteria.createAlias("leaveDistributions", "lv", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("employeeType", "empType", JoinType.INNER_JOIN); criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN); criteria.createAlias("golonganJabatan", "goljab", JoinType.INNER_JOIN); criteria.add(Property.forName("id").notIn(listEmp)); //ambil yg working groupnya bukan yg dipilih, dan belum punya working group // if (model.getLeaveSchemeId() != 0 || model.getLeaveSchemeId() != null) { // Disjunction disjunction = Restrictions.disjunction(); // disjunction.add(Restrictions.isNull("lv.empData")); // disjunction.add(Restrictions.not(Restrictions.eq("lv.leave.id", model.getLeaveSchemeId()))); // criteria.add(disjunction); // } */ @Override public List<EmpData> getEmployeeBySearchEmployeePermit(PermitDistributionModel model) { DetachedCriteria listEmp = DetachedCriteria.forClass(PermitDistribution.class) .setProjection(Property.forName("empData.id")) .createAlias("permitClassification", "pc", JoinType.INNER_JOIN) .add(Restrictions.eq("pc.id", model.getPermitId())); Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /** * 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, HrmUserInfoUtil.getCompanyId()); criteria.add(Restrictions.neOrIsNotNull("status", HRMConstant.EMP_TERMINATION)); criteria.createAlias("permitDistributions", "lv", JoinType.LEFT_OUTER_JOIN); criteria.createAlias("employeeType", "empType", JoinType.INNER_JOIN); criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN); criteria.createAlias("golonganJabatan", "goljab", JoinType.INNER_JOIN); criteria.add(Property.forName("id").notIn(listEmp)); //ambil yg working groupnya bukan yg dipilih, dan belum punya working group /*if (model.getPermitId() != 0 || model.getPermitId() != null) { Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.isNull("permitDistributions")); disjunction.add(Restrictions.not(Restrictions.eq("lv.permitClassification.id", model.getPermitId()))); //disjunction.add(Restrictions.sqlRestriction(sql, values, types)); criteria.add(disjunction); }*/ //balance // if (model.getStartBalance() != 0.0){ // criteria.add(Restrictions.eq("lv.balance", model.getStartBalance())); // } //departermen equal or like if (model.getDepartmentLikeOrEqual() != 3) { if (Objects.equals(model.getDepartmentLikeOrEqual(), HRMConstant.DEPARTMENT_EQUAL)) { criteria.add(Restrictions.eq("department.departmentName", model.getDepartmentName())); } else { criteria.add(Restrictions.like("department.departmentName", model.getDepartmentName(), MatchMode.ANYWHERE)); } } //employee type equal or likeS if (model.getEmployeeTypeLikeOrEqual() != 3) { if (Objects.equals(model.getEmployeeTypeLikeOrEqual(), HRMConstant.EMPLOYEE_TYPE_EQUAL)) { criteria.add(Restrictions.eq("empType.name", model.getEmployeeTypeName())); } else { criteria.add(Restrictions.like("empType.name", model.getEmployeeTypeName(), MatchMode.ANYWHERE)); } } //gender criteria.add(Restrictions.eq("bio.gender", model.getGender())); //goljab if (model.getGolonganJabatanId() != 0) { criteria.add(Restrictions.eq("goljab.id", model.getGolonganJabatanId())); } String sortBy; if (Objects.equals(model.getSortBy(), HRMConstant.SORT_BY_NIK)) { sortBy = "nik"; } else { sortBy = "bio.firstName"; } if (Objects.equals(model.getOrderBy(), HRMConstant.ORDER_BY_ASC)) { criteria.addOrder(Order.asc(sortBy)); } else { criteria.addOrder(Order.desc(sortBy)); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.JabatanDaoImpl.java
@Override public List<Jabatan> getJabatanByParentCode(String parentCode) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); /** automatically get relations of department, company * don't create alias for that entity, or will get error : duplicate association path */ criteria = this.addJoinRelationsOfCompanyId(criteria, HrmUserInfoUtil.getCompanyId()); criteria.createAlias("jabatan", "jb", JoinType.INNER_JOIN); criteria.add(Restrictions.eq("jb.code", parentCode)); criteria.setFetchMode("jabatans", FetchMode.JOIN); criteria.setFetchMode("jabatans.jabatan", FetchMode.JOIN); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.RecruitSelectionTypeTemplatesDaoImpl.java
@Override public List<RecruitSelectionTypeTemplates> getByParentId(long id) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.createAlias("recruitSelectionTypeTemplates", "dp", JoinType.INNER_JOIN); criteria.add(Restrictions.eq("dp.id", id)); criteria.setFetchMode("recruitSelectionTypeTemplateses", FetchMode.JOIN); criteria.setFetchMode("recruitSelectionTypeTemplateses.recruitSelectionTypeTemplates", FetchMode.JOIN); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria.list(); }
From source file:com.inkubator.hrm.dao.impl.UnregSalaryDaoImpl.java
@Override public Long getTotalByParamBySalaryPayroll(UnregSalarySearchParameter searchParameter, Date fromPeriodPayrollType) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.createAlias("wtPeriode", "wtPeriode", JoinType.INNER_JOIN); criteria.add(Restrictions.lt("wtPeriode.fromPeriode", fromPeriodPayrollType)); doSearchByParam(searchParameter, criteria); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); }
From source file:com.itrus.ca.common.persistence.BaseDaoImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<T> manyFind(DetachedCriteria detachedCriteria, ResultTransformer resultTransformer, int size) { Criteria criteria = detachedCriteria.getExecutableCriteria(getSession()); criteria.setResultTransformer(resultTransformer); criteria.setFirstResult(0);/* w w w . jav a 2 s . com*/ criteria.setMaxResults(size); return criteria.list(); }