List of usage examples for org.hibernate FetchMode JOIN
FetchMode JOIN
To view the source code for org.hibernate FetchMode JOIN.
Click Source Link
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Management operations/* w w w. j ava2 s . c o m*/ * * @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.LearnedLessonDAO.java
License:Open Source License
/** * Find generated learned lesson by id// w w w.j av a 2 s. c o m * * @param id * @param joins * @return */ public LearnedLesson findGenerated(Integer id, List<String> joins) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(LearnedLesson.IDLEARNEDLESSON, id)) .setFetchMode(LearnedLesson.LEARNEDLESSONPROJECTS, FetchMode.JOIN); addJoins(crit, joins); return (LearnedLesson) crit.uniqueResult(); }
From source file:es.sm2.openppm.core.dao.MetrickpiDAO.java
License:Open Source License
/** * Find by company of user/*ww w .jav a2 s.c om*/ * @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//w ww. java 2 s . c om * * @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/*w w w . jav a2 s. c o m*/ * @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.MilestoneDAO.java
License:Open Source License
/** * Find milestones for notify//w w w. jav a 2 s . com * @return */ @SuppressWarnings("unchecked") public List<Milestones> findForNotify() { // FIXME Calcular la fecha segun los dias que esta configurado en el milestone. Cambiar la select Calendar now = DateUtil.getCalendar(); now.set(Calendar.HOUR, 0); now.set(Calendar.MINUTE, 0); now.set(Calendar.SECOND, 0); Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Milestones.NOTIFY, true)) .add(Restrictions.eq(Milestones.NOTIFYDATE, now.getTime())); crit.createCriteria(Milestones.PROJECT).add(Restrictions.eq(Project.STATUS, Constants.STATUS_CONTROL)) // PO .setFetchMode(Project.PERFORMINGORG, FetchMode.JOIN) // PM .setFetchMode(Project.EMPLOYEEBYPROJECTMANAGER, FetchMode.JOIN) .setFetchMode(Project.EMPLOYEEBYPROJECTMANAGER + "." + Employee.CONTACT, FetchMode.JOIN) // PMO .setFetchMode(Project.PERFORMINGORG, FetchMode.JOIN) .setFetchMode(Project.PERFORMINGORG + "." + Performingorg.EMPLOYEE, FetchMode.JOIN) .setFetchMode(Project.PERFORMINGORG + "." + Performingorg.EMPLOYEE + "." + Employee.CONTACT, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.OperationDAO.java
License:Open Source License
/** * Return Operations with operation account * @param operation/* w w w. j a v a 2 s . c o 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 w ww.jav a2s.c o m*/ * @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/* w w w .j a v a 2s . 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 w w w .j av a 2s . c om*/ } if (exampleInstance.getEmployee() != null) {// Find by Program Mgr. crit.add(Restrictions.eq("employee.idEmployee", exampleInstance.getEmployee().getIdEmployee())); } return crit.list(); }