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.DataTableDAO.java
License:Open Source License
@SuppressWarnings({ "rawtypes" }) public List findByFiltro(FiltroTabla filtro, Class tipo, ArrayList<String> joins) throws ParseException { Criteria crit = getSession().createCriteria(tipo).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setFirstResult(filtro.getDisplayStart()).setMaxResults(filtro.getDisplayLength()); for (DatoColumna order : filtro.getOrden()) { crit.addOrder((order.getValor().equals("asc") ? Order.asc(order.getNombre()) : Order.desc(order.getNombre()))); }/*from w w w .j ava 2 s .com*/ applyFilters(crit, filtro.getFiltro()); if (joins != null) { for (String join : joins) { crit.setFetchMode(join, FetchMode.JOIN); } } return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
@SuppressWarnings({ "rawtypes", "unchecked" }) public List<Employee> searchByExample(Employee exampleInstance, Class... joins) { Criteria crit = getSession().createCriteria(getPersistentClass()); if (exampleInstance.getPerformingorg() != null) { crit.add(Restrictions.eq("performingorg.idPerfOrg", exampleInstance.getPerformingorg().getIdPerfOrg())); }//from w w w . j a v a 2s . c om if (exampleInstance.getResourceprofiles() != null) { crit.add(Restrictions.eq("resourceprofiles.idProfile", exampleInstance.getResourceprofiles().getIdProfile())); } crit.setFetchMode("contact", FetchMode.JOIN); for (Class c : joins) { if (c.equals(Employee.class)) { crit.setFetchMode("employee", FetchMode.JOIN); crit.setFetchMode("employee.contact", FetchMode.JOIN); } else if (c.equals(Performingorg.class)) { crit.setFetchMode("performingorg", FetchMode.JOIN); } else if (c.equals(Resourceprofiles.class)) { crit.setFetchMode("resourceprofiles", FetchMode.JOIN); } } return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find by id with Contact//from w w w.j a v a 2 s. c o m * @param emp * @return */ public Employee findByIdWithContact(Employee emp) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setFetchMode("contact", FetchMode.JOIN); crit.setFetchMode("contact.company", FetchMode.JOIN); crit.add(Restrictions.eq("idEmployee", emp.getIdEmployee())); return (Employee) crit.uniqueResult(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Return employee with data/*from w w w .j a va2 s.co m*/ * @param employee * @return */ public Employee findByIdEmployee(Employee employee) { Employee empl = null; if (employee.getIdEmployee() != null) { Criteria crit = getSession().createCriteria(getPersistentClass()); crit.setFetchMode(Employee.CONTACT, FetchMode.JOIN); crit.setFetchMode(Employee.CONTACT + "." + Contact.COMPANY, FetchMode.JOIN); crit.setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN); crit.setFetchMode(Employee.RESOURCEPROFILES, FetchMode.JOIN); crit.add(Restrictions.eq("idEmployee", employee.getIdEmployee())); empl = (Employee) crit.uniqueResult(); } return empl; }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Search Employee By filter/* w ww . j a va2s.co m*/ * @param name * @param jobTitle * @param idProfile * @param idPerfOrg * @return */ @SuppressWarnings("unchecked") public List<Employee> searchByFilter(String name, String jobTitle, Integer idProfile, Integer idPerfOrg, Company company) { Criteria crit = getSession().createCriteria(getPersistentClass()).add( Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true))); crit.createCriteria(Employee.CONTACT).add(Restrictions.ilike(Contact.FULLNAME, "%" + name + "%")) .add(Restrictions.ilike(Contact.JOBTITLE, "%" + jobTitle + "%")) .add(Restrictions.eq(Contact.COMPANY, company)) .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true))) .createCriteria(Contact.COMPANY) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); if (idProfile != -1) { crit.add(Restrictions.eq(Employee.RESOURCEPROFILES, new Resourceprofiles(idProfile))); } if (idPerfOrg != -1) { crit.add(Restrictions.eq(Employee.PERFORMINGORG, new Performingorg(idPerfOrg))); } crit.setFetchMode(Employee.CONTACT, FetchMode.JOIN); crit.setFetchMode(Employee.CONTACT + "." + Contact.COMPANY, FetchMode.JOIN); crit.setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Employee> consEmployeesByUser(Contact contact) { Criteria crit = getSession().createCriteria(getPersistentClass()).add( Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true))); crit.createCriteria(Employee.RESOURCEPROFILES).addOrder(Order.asc(Resourceprofiles.PROFILENAME)); crit.setFetchMode(Employee.RESOURCEPROFILES, FetchMode.JOIN).setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN);// ww w .j ava2 s. com crit.createCriteria(Employee.CONTACT).add(Restrictions.idEq(contact.getIdContact())) .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true))) .createCriteria(Contact.COMPANY) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find employees by PO and Rol//from ww w . ja va 2 s .com * @param performingorg * @param role * @return */ @SuppressWarnings("unchecked") public List<Employee> findByPOAndRol(Performingorg performingorg, int role) { Criteria crit = getSession().createCriteria(getPersistentClass()); if (performingorg != null) { crit.add(Restrictions.eq(Employee.PERFORMINGORG, performingorg)); } crit.add(Restrictions.eq(Employee.RESOURCEPROFILES, new Resourceprofiles(role))) .setFetchMode(Employee.CONTACT, FetchMode.JOIN).createCriteria(Employee.CONTACT) .addOrder(Order.asc(Contact.FULLNAME)); crit.setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Employees where inputed hours is approval * /*from w ww .j av a2s. c om*/ * @param project * @param since * @param until * @return */ @SuppressWarnings("unchecked") public List<Employee> findInputedInProject(Project project, Date since, Date until) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); Criteria members = crit.createCriteria(Employee.TEAMMEMBERS) .add(Restrictions.or(Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_ASSIGNED), Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_RELEASED))); if (since != null && until != null) { members.add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); } members.createCriteria(Teammember.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)); 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)))); } sheets.createCriteria(Timesheet.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); crit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); crit.setFetchMode(Employee.CALENDARBASE, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Cons employees for login and profile/*ww w . j a va 2s . c o m*/ * * @param contact * @param profile * @return */ @SuppressWarnings("unchecked") public List<Employee> consEmployeesByUserAndRol(Contact contact, int profile) { Criteria crit = getSession().createCriteria(getPersistentClass()).add( Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true))); crit.createCriteria(Employee.RESOURCEPROFILES).add(Restrictions.eq(Resourceprofiles.IDPROFILE, profile)); crit.setFetchMode(Employee.RESOURCEPROFILES, FetchMode.JOIN).setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN); crit.createCriteria(Employee.CONTACT).add(Restrictions.idEq(contact.getIdContact())) .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true))) .createCriteria(Contact.COMPANY) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Employees by profile and company// w w w . jav a 2 s . com * * @param profile * @param company * @return */ @SuppressWarnings("unchecked") public List<Employee> consEmployeesByRol(int profile, Company company) { Criteria crit = getSession().createCriteria(getPersistentClass()).add( Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true))); crit.createCriteria(Employee.RESOURCEPROFILES).add(Restrictions.eq(Resourceprofiles.IDPROFILE, profile)); crit.setFetchMode(Employee.RESOURCEPROFILES, FetchMode.JOIN).setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN); Criteria critContact = crit.createCriteria(Employee.CONTACT); critContact.createCriteria(Contact.COMPANY).add(Restrictions.and( Restrictions.eq(Company.IDCOMPANY, company.getIdCompany()), Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)))); return crit.list(); }