List of usage examples for org.hibernate Criteria createCriteria
public Criteria createCriteria(String associationPath) throws HibernateException;
From source file:es.sm2.openppm.core.dao.MetrickpiDAO.java
License:Open Source License
/** * Search metricKpis by filter/*from www. j a v a 2 s .c o 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 milestones for notify/*w ww .jav a 2s . c o m*/ * @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.NotificationDAO.java
License:Open Source License
/** * Find notifications pendings/*w w w .java 2 s. com*/ * * @param company * @param notificationsForNotify * @return */ @SuppressWarnings("unchecked") public List<Notification> findPendings(Company company, List<String> notificationsForNotify) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); crit.add(Restrictions.eq(Notification.STATUS, NotificationStatus.PENDING.toString())); crit.add(Restrictions.in(Notification.TYPE, notificationsForNotify)); Criteria contactNotCrit = crit.createCriteria(Notification.CONTACTNOTIFICATIONS); contactNotCrit.createCriteria(Contactnotification.CONTACT).add(Restrictions.eq(Contact.COMPANY, company)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.OperationDAO.java
License:Open Source License
/** * Find all of operations by company// www. ja va 2s . c om * * @param company * @param isSeller * @return */ @SuppressWarnings("unchecked") public List<Operation> findAllByCompany(Company company, boolean isSeller) { Criteria crit = getSession().createCriteria(getPersistentClass()) .addOrder(Order.asc(Operation.OPERATIONNAME)).addOrder(Order.asc(Operation.IDOPERATION)); crit.createCriteria(Operation.OPERATIONACCOUNT).add(Restrictions.eq(Operationaccount.COMPANY, company)); //Exclude externals operations if user is seller if (isSeller) { crit.add(Restrictions.eq(Operation.EXCLUDEEXTERNALS, false)); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.OperationDAO.java
License:Open Source License
/** * Find operations by employees and dates and status app3 * /*ww w. j av a 2 s . c o m*/ * @param employees * @param since * @param until * @return */ @SuppressWarnings("unchecked") public List<Operation> findByEmployeesAndDatesAndApproved(List<Employee> employees, Date since, Date until, Company company) { List<Operation> operations = null; if (ValidateUtil.isNotNull(employees)) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); // Operation // crit.addOrder(Order.asc(Operation.OPERATIONNAME)).createCriteria(Operation.OPERATIONACCOUNT) .add(Restrictions.eq(Operationaccount.COMPANY, company)); // Timesheet // Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.isNotNull(Timesheet.OPERATION)); if (!employees.isEmpty()) { sheets.add(Restrictions.in(Timesheet.EMPLOYEE, employees)); } if (since != null && until != null) { sheets.add(Restrictions.disjunction().add(Restrictions.between(Timesheet.INITDATE, since, until)) .add(Restrictions.between(Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, since), Restrictions.ge(Timesheet.ENDDATE, until)))); } operations = crit.list(); } return operations; }
From source file:es.sm2.openppm.core.dao.OperationDAO.java
License:Open Source License
/** * Find by search/*w ww. j a v a 2 s . co m*/ * * @param search * @return */ public List<Operation> find(OperationSearch search) { Criteria crit = getSession().createCriteria(getPersistentClass()) .addOrder(Order.asc(Operation.OPERATIONNAME)).addOrder(Order.asc(Operation.IDOPERATION)); crit.createCriteria(Operation.OPERATIONACCOUNT) .add(Restrictions.eq(Operationaccount.COMPANY, search.getCompany())); if (search.isAvailableForManager()) { crit.add(Restrictions.eq(Operation.AVAILABLEFORMANAGER, Boolean.TRUE)); } if (search.isAvailableForApprove()) { crit.add(Restrictions.eq(Operation.AVAILABLE_FOR_APPROVE, Boolean.TRUE)); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.ProblemcheckDAO.java
License:Open Source License
/** * Find by project/*from ww w . j a v a2 s . c o m*/ * * @param project * @return */ @SuppressWarnings("unchecked") public List<Problemcheck> findByProject(Project project) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Problemcheck.SHOWCHECK, true)); crit.createCriteria(Problemcheck.PROBLEMCHECKPROJECTS) .add(Restrictions.eq(Problemcheckproject.PROJECT, project)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.ProgramDAO.java
License:Open Source License
/** * Search by PerfOrg// ww w . j a v a2 s .co m * @param budgetYear * @param user * @return */ @SuppressWarnings("unchecked") public List<Program> searchByPerfOrg(Performingorg perfOrg, Integer budgetYear) { Criteria crit = getSession().createCriteria(getPersistentClass()).addOrder(Order.asc(Program.PROGRAMNAME)); if (budgetYear != null) { crit.add(Restrictions.disjunction().add(Restrictions.eq(Program.INITBUDGETYEAR, budgetYear + "")) .add(Restrictions.isNull(Program.INITBUDGETYEAR)) .add(Restrictions.eq(Program.INITBUDGETYEAR, ""))); } crit.createCriteria("employee").add(Restrictions.eq("performingorg", perfOrg)); 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 ww w. ja v a2 s. co m } crit.createCriteria(Program.PERFORMINGORG).add(Restrictions.eq(Performingorg.COMPANY, company)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.ProgramDAO.java
License:Open Source License
/** * Search programs by filter// w ww .j ava2s . c o m * @param name * @param performingorg * @param company * @return */ @SuppressWarnings("unchecked") public List<Program> searchPrograms(String name, Performingorg performingorg, Company company) { Criteria crit = getSession().createCriteria(getPersistentClass()); // Filter program name crit.add(Restrictions.ilike(Program.PROGRAMNAME, "%" + name + "%")); // Join performing org Criteria critPerfOrg = crit.createCriteria(Program.PERFORMINGORG); if (performingorg.getIdPerfOrg() != -1) { // Filter performing org critPerfOrg.add(Restrictions.eq(Performingorg.IDPERFORG, performingorg.getIdPerfOrg())); } else { // Filter by company critPerfOrg.add(Restrictions.eq(Performingorg.COMPANY, company)); } return crit.list(); }