List of usage examples for org.hibernate Criteria setFetchMode
public Criteria setFetchMode(String associationPath, FetchMode mode) throws HibernateException;
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Employees where inputed hours is approval * //w w w. j a v a 2 s. c om * @param idResourcePools * @param projects * @param fullName * @param idJobCategories * @param idPMs * @param idSellers * @param idCategories * @param since * @param until * @param order * @param nameOrder * @return */ @SuppressWarnings("unchecked") public List<Employee> findInputedInProjects(Integer[] idResourcePools, List<Project> projects, Integer[] idPMs, Integer[] idJobCategories, Integer[] idSellers, Integer[] idCategories, String fullName, Date since, Date until, String nameOrder, String order, Employee user) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Filter by user if (user != null) { crit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg())); } // Aliases // crit.createAlias(Employee.TEAMMEMBERS, "tm", CriteriaSpecification.INNER_JOIN) .createAlias(Employee.TIMESHEETS, "ts", CriteriaSpecification.INNER_JOIN) .createAlias("tm." + Teammember.PROJECTACTIVITY, "pa", CriteriaSpecification.INNER_JOIN) .createAlias("pa." + Projectactivity.PROJECT, "p", CriteriaSpecification.LEFT_JOIN) .createAlias("p." + Project.EMPLOYEEBYPROJECTMANAGER, "pm", CriteriaSpecification.LEFT_JOIN) .createAlias(Employee.RESOURCEPOOL, "rp", CriteriaSpecification.LEFT_JOIN) .createAlias(Employee.SELLER, "s", CriteriaSpecification.LEFT_JOIN) .createAlias("tm." + Teammember.JOBCATEGORY, "jc", CriteriaSpecification.LEFT_JOIN) .createAlias("p." + Project.CATEGORY, "c", CriteriaSpecification.LEFT_JOIN); // Teammembers // crit.add(Restrictions.eq("tm." + Teammember.STATUS, Constants.RESOURCE_ASSIGNED)); if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between("tm." + Teammember.DATEIN, since, until)) .add(Restrictions.between("tm." + Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le("tm." + Teammember.DATEIN, since), Restrictions.ge("tm." + Teammember.DATEOUT, until)))); } // Timesheets // crit.add(Restrictions.eq("ts." + Timesheet.STATUS, Constants.TIMESTATUS_APP3)); if (since != null && until != null) { crit.add(Restrictions.disjunction().add(Restrictions.between("ts." + Timesheet.INITDATE, since, until)) .add(Restrictions.between("ts." + Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le("ts." + Timesheet.INITDATE, since), Restrictions.ge("ts." + Timesheet.ENDDATE, until)))); } // Filters // Conjunction conjunction = Restrictions.conjunction(); // Filter by projects if (ValidateUtil.isNotNull(projects)) { conjunction.add(Restrictions.in("pa." + Projectactivity.PROJECT, projects)); } // Filter by project managers if (ValidateUtil.isNotNull(idPMs)) { conjunction.add(Restrictions.in("pm." + Employee.IDEMPLOYEE, idPMs)); } // Filter by resourcepools if (ValidateUtil.isNotNull(idResourcePools)) { conjunction.add(Restrictions.in("rp." + Resourcepool.IDRESOURCEPOOL, idResourcePools)); } // Filter by sellers if (ValidateUtil.isNotNull(idSellers)) { conjunction.add(Restrictions.in("s." + Seller.IDSELLER, idSellers)); } // Filter by jobcategories if (ValidateUtil.isNotNull(idJobCategories)) { conjunction.add(Restrictions.in("jc." + Jobcategory.IDJOBCATEGORY, idJobCategories)); } // Filter by categories if (ValidateUtil.isNotNull(idCategories)) { conjunction.add(Restrictions.in("c." + Category.IDCATEGORY, idCategories)); } crit.add(conjunction); // Filter by Full Name Criteria contactCrit = crit.createCriteria(Employee.CONTACT); if (ValidateUtil.isNotNull(fullName)) { contactCrit.add(Restrictions.ilike(Contact.FULLNAME, "%" + fullName + "%")); } // Apply Order Criteria orderCrit = null; String alias = StringPool.BLANK; if (Project.IDPROJECT.equals(nameOrder)) { alias = "pm."; orderCrit = crit; } else if (Jobcategory.IDJOBCATEGORY.equals(nameOrder)) { alias = "jc."; orderCrit = crit; } else { orderCrit = contactCrit; } if (nameOrder != null) { if (Constants.DESCENDENT.equals(order)) { orderCrit.addOrder(Order.desc(alias + nameOrder)); } else { orderCrit.addOrder(Order.asc(alias + nameOrder)); } } // Calendar base crit.setFetchMode(Employee.CALENDARBASE, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Management operations// w ww .j a v a 2s. com * * @param search * @param user * @param resourcePools * @return */ public List<Employee> find(TimeSheetOperationSearch search, Employee user, List<Resourcepool> resourcePools) { Criteria timeSheetCrit = getSession().createCriteria(Timesheet.class); // Operation // timeSheetCrit.createCriteria(Timesheet.OPERATION) .add(Restrictions.eq(Operation.IDOPERATION, search.getCodeOperation())) .add(Restrictions.eq(Operation.AVAILABLEFORMANAGER, Boolean.TRUE)); if (search.getSince() != null && search.getUntil() != null) { timeSheetCrit.add(Restrictions.disjunction() .add(Restrictions.between(Timesheet.INITDATE, search.getSince(), search.getUntil())) .add(Restrictions.between(Timesheet.ENDDATE, search.getSince(), search.getUntil())) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, search.getSince()), Restrictions.ge(Timesheet.ENDDATE, search.getUntil())))); } // Filter by NOT Resource if (user != null && user.getResourceprofiles() != null && !Resourceprofiles.Profile.RESOURCE.equals(user.getResourceprofiles().getProfile())) { List<String> statusList = new ArrayList<String>(); statusList.add(Constants.TIMESTATUS_APP1); statusList.add(Constants.TIMESTATUS_APP2); statusList.add(Constants.TIMESTATUS_APP3); timeSheetCrit.add(Restrictions.in(Timesheet.STATUS, statusList)); } // Employee // Criteria employeeCriteria = timeSheetCrit.createCriteria(Timesheet.EMPLOYEE); if (ValidateUtil.isNotNull(resourcePools)) { employeeCriteria.add(Restrictions.in(Employee.RESOURCEPOOL, resourcePools)); } if (search.getCodePool() != null) { employeeCriteria.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(search.getCodePool()))); } if (ValidateUtil.isNotNull(search.getCodeJobCategoryList())) { employeeCriteria.createCriteria(Employee.JOBCATEMPLOYEES).createCriteria(Jobcatemployee.JOBCATEGORY) .add(Restrictions.in(Jobcategory.IDJOBCATEGORY, search.getCodeJobCategoryList())); } if (ValidateUtil.isNotNull(search.getCodeSkillList())) { employeeCriteria.createCriteria(Employee.SKILLSEMPLOYEES).createCriteria(Skillsemployee.SKILL) .add(Restrictions.in(Skill.IDSKILL, search.getCodeSkillList())); } // Contact // Criteria critContact = employeeCriteria.createCriteria(Employee.CONTACT); if (ValidateUtil.isNotNull(search.getCodeContactList())) { critContact.add(Restrictions.in(Contact.IDCONTACT, search.getCodeContactList())); } critContact.createCriteria(Contact.COMPANY) .add(Restrictions.eq(Company.IDCOMPANY, search.getCompany().getIdCompany())) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); timeSheetCrit.setFetchMode(Timesheet.EMPLOYEE, FetchMode.JOIN); timeSheetCrit.setFetchMode(Timesheet.EMPLOYEE + StringPool.PERIOD + Employee.CONTACT, FetchMode.JOIN); timeSheetCrit.setFetchMode(Timesheet.EMPLOYEE + StringPool.PERIOD + Employee.RESOURCEPOOL, FetchMode.JOIN); timeSheetCrit.setFetchMode(Timesheet.EMPLOYEE + StringPool.PERIOD + Employee.SELLER, FetchMode.JOIN); HashMap<Integer, Employee> groupingTime = new HashMap<Integer, Employee>(); List<Employee> employees = new ArrayList<Employee>(); for (Timesheet timesheet : (List<Timesheet>) timeSheetCrit.list()) { if (groupingTime.containsKey(timesheet.getEmployee().getIdEmployee())) { Employee employee = groupingTime.get(timesheet.getEmployee().getIdEmployee()); employee.getTimesheets().add(timesheet); } else { Employee employee = timesheet.getEmployee(); employee.setTimesheets(new HashSet<Timesheet>()); employee.getTimesheets().add(timesheet); groupingTime.put(timesheet.getEmployee().getIdEmployee(), employee); employees.add(employee); } } return employees; }
From source file:es.sm2.openppm.core.dao.MetrickpiDAO.java
License:Open Source License
/** * Find by company of user/* w w w .ja v a 2 s .c o m*/ * @param company * @param joins * @return */ @SuppressWarnings("unchecked") public List<Metrickpi> findByCompany(Company company, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()); if (joins != null && !joins.isEmpty()) { for (String join : joins) { crit.setFetchMode(join, FetchMode.JOIN); } } crit.add(Restrictions.eq(Metrickpi.COMPANY, company)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.MetrickpiDAO.java
License:Open Source License
/** * Search metricKpis by filter/*from w w w. ja va 2 s . co m*/ * * @param name * @param type *@param company @return */ @SuppressWarnings("unchecked") public List<Metrickpi> searchByFilter(String name, Integer idBSCDimension, String type, Project project, Company company, List<String> joins) { Metrickpi example = new Metrickpi(); example.setName(name); Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) .add(Example.create(example).ignoreCase().enableLike(MatchMode.ANYWHERE)); // Add joins if (joins != null && !joins.isEmpty()) { for (String join : joins) { crit.setFetchMode(join, FetchMode.JOIN); } } // by company crit.createCriteria(Metrickpi.COMPANY).add(Restrictions.idEq(company.getIdCompany())) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); // By bsc dimension if (!idBSCDimension.equals(-1)) { crit.add(Restrictions.eq(Metrickpi.BSCDIMENSION, new Bscdimension(idBSCDimension))); } // By type if (ValidateUtil.isNotNull(type)) { crit.add(Restrictions.eq(Metrickpi.TYPE, type)); } // By project if (project.getIdProject() != -1) { crit.createCriteria(Projectkpi.PROJECT).add(Restrictions.idEq(project.getIdProject())); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.MilestoneDAO.java
License:Open Source License
/** * Find Milestone with Project Activity/* www. ja v a2 s. c om*/ * @param milestone * @return */ public Milestones findMilestone(Milestones milestone) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setFetchMode("projectactivity", FetchMode.JOIN); crit.add(Restrictions.eq("idMilestone", milestone.getIdMilestone())); return (Milestones) crit.uniqueResult(); }
From source file:es.sm2.openppm.core.dao.OperationDAO.java
License:Open Source License
/** * Return Operations with operation account * @param operation/*from ww w . ja v a 2 s.co m*/ * @return */ public Operation findByIdOperation(Operation operation) { Operation ope = null; if (operation.getIdOperation() != null) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setFetchMode("operationaccount", FetchMode.JOIN); crit.add(Restrictions.eq("idOperation", operation.getIdOperation())); ope = (Operation) crit.uniqueResult(); } return ope; }
From source file:es.sm2.openppm.core.dao.ProcurementpaymentsDAO.java
License:Open Source License
/** * Get Procurement Payments from Project * @param proj/*from ww w . j a va2s. com*/ * @param joins * @return */ @SuppressWarnings("unchecked") public List<Procurementpayments> consProcurementPaymentsByProject(Project proj, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()); for (String join : joins) { crit.setFetchMode(join, FetchMode.JOIN); } crit.addOrder(Order.asc(Procurementpayments.SELLER)) .add(Restrictions.eq(Procurementpayments.PROJECT, proj)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.ProcurementpaymentsDAO.java
License:Open Source License
/** * Get Procurement Budgets from Project/*from www. j av a 2 s . c o m*/ * * @param proj * @param joins * @return */ public List<ProcurementBudget> consProcurementBudgetsByProject(Project proj, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()); for (String join : joins) { crit.setFetchMode(join, FetchMode.JOIN); } crit.addOrder(Order.asc(Procurementpayments.SELLER)) .setProjection(Projections.projectionList().add(Projections.sum(Procurementpayments.PLANNEDPAYMENT)) .add(Projections.sum(Procurementpayments.ACTUALPAYMENT)).add(Projections.rowCount()) .add(Projections.groupProperty(Procurementpayments.SELLER))) .add(Restrictions.eq(Procurementpayments.PROJECT, proj)); List<ProcurementBudget> lista = new ArrayList<ProcurementBudget>(); List<String> purchase = null; for (int i = 0; i < crit.list().size(); i++) { ProcurementBudget budget = new ProcurementBudget(); Object[] row = (Object[]) crit.list().get(i); budget.setPlannedPayment((Double) row[0]); budget.setActualPayment((Double) row[1]); budget.setnPayments((Integer) row[2]); Seller seller = (Seller) row[3]; budget.setSeller(seller.getName()); purchase = consPruchaseOrder(seller, proj); String order = ""; if (purchase != null) { for (String s : purchase) { if (!order.equals("")) { order += ", "; } order += s; } } budget.setPurchaseOrder(order); lista.add(budget); } return lista; }
From source file:es.sm2.openppm.core.dao.ProgramDAO.java
License:Open Source License
@SuppressWarnings({ "unchecked", "rawtypes" }) public List<Program> searchByExample(Program exampleInstance, Class... joins) { Criteria crit = getSession().createCriteria(getPersistentClass()).addOrder(Order.asc(Program.PROGRAMNAME)); for (Class c : joins) { if (c.equals(Contact.class)) { crit.setFetchMode("employee", FetchMode.JOIN); crit.setFetchMode("employee.contact", FetchMode.JOIN); }/*from www.jav a 2 s .co m*/ } if (exampleInstance.getEmployee() != null) {// Find by Program Mgr. crit.add(Restrictions.eq("employee.idEmployee", exampleInstance.getEmployee().getIdEmployee())); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.ProgramDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Program> consByCompany(Company company, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()).addOrder(Order.asc(Program.PROGRAMNAME)); if (joins != null) { for (String join : joins) { crit.setFetchMode(join, FetchMode.JOIN); }/*from w w w . j a v a 2 s.co m*/ } crit.createCriteria(Program.PERFORMINGORG).add(Restrictions.eq(Performingorg.COMPANY, company)); return crit.list(); }