List of usage examples for org.hibernate.criterion DetachedCriteria createCriteria
public DetachedCriteria createCriteria(String associationPath)
From source file:pl.touk.wonderfulsecurity.dao.WsecBaseDaoImpl.java
License:Apache License
/** * Builds Hibernate criteria object from map of parameters that usually comes from front end */// w ww .ja v a 2 s.c o m protected <E> DetachedCriteria buildCriteriaFromMapOfParameters(Map<String, ?> parameters, Class<E> clazz) { DetachedCriteria criteria = DetachedCriteria.forClass(clazz); if (parameters != null) { for (String key : parameters.keySet()) { if (key.indexOf(".") != -1) { //handles only one nested property //TODO: handle more nested properties String[] nestedProperties = key.split("\\."); //.addOrder(desc ? Order.desc() : Order.asc(nestedProperties[1])); applyFilters(nestedProperties[1], parameters.get(key), criteria.createCriteria(nestedProperties[0])); } else { applyFilters(key, parameters.get(key), criteria); } } } return criteria; }
From source file:ro.cs.cm.model.dao.impl.DaoTeamMemberImpl.java
License:Open Source License
/** * Get team members from projects// w w w .j ava 2 s .c o m * * @author Adelina * * @param projectIds * @return */ public List<TeamMember> getTeamMembersByProjectIds(Set<Integer> projectIds, boolean isExternal, boolean isNotDeleted) { logger.debug("getTeamMembersByProjectIds - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.teamMemberWithProjectTeamEntity); logger.debug("isExternal = " + isExternal); if (isExternal) { dc.add(Restrictions.eq("personId", new Integer(0))); } dc.createCriteria("projectTeam").add(Restrictions.in("projectId", projectIds)); logger.debug("isNotDeleted = " + isNotDeleted); if (isNotDeleted) { dc.add(Restrictions.ne("status", IConstant.NOM_TEAM_MEMBER_STATUS_DELETED)); } List<TeamMember> members = getHibernateTemplate().findByCriteria(dc); logger.debug("team members = " + members); List<TeamMember> teamMembers = new ArrayList<TeamMember>(); if (members != null && members.size() > 0) { for (TeamMember teamMember : members) { logger.debug("team member = " + teamMember); boolean changeStatus = false; if (teamMember != null && teamMember.getPersonId() > 0) { try { Person person = BLPerson.getInstance().get(teamMember.getPersonId()); logger.debug("person = " + person); Byte activated = new Byte(IConstant.NOM_PERSON_STATUS_ACTIVATED); if (person != null && !activated.equals(person.getStatus())) { changeStatus = true; } if (!changeStatus) { logger.debug("teamMember = " + teamMember); teamMembers.add(teamMember); } else { if (person != null) { changeStatus(teamMember, person.getStatus()); } } } catch (BusinessException e) { e.printStackTrace(); } } if (!isNotDeleted) { teamMembers.add(teamMember); } } } Tools.getInstance().printList(logger, teamMembers); logger.debug("getTeamMembersByProjectIds - END"); return teamMembers; }
From source file:ro.cs.cm.model.dao.impl.DaoTeamMemberImpl.java
License:Open Source License
/** * Gets team members by different search criteria * //w w w . j ava 2 s . c om * @author Coni * @param searchTeamMemberBean * @return * @throws BusinessException * @throws WSClientException * @throws IOException * @throws XmlMappingException */ public List<TeamMember> getFromSearchSimple(SearchTeamMemberBean searchTeamMemberBean) throws XmlMappingException, IOException, WSClientException { logger.debug("getFromSearchSimple - START"); DetachedCriteria dc = DetachedCriteria .forEntityName(IModelConstant.teamMemberWithProjectTeamAndProjectEntity); //retrieve all the team members for persons from the organization(which have personId != 0) or //not(which have firstName and lastName) that correspond to the search criteria if (searchTeamMemberBean.getFirstName() != null && !"".equals(searchTeamMemberBean.getFirstName()) && searchTeamMemberBean.getLastName() != null && !"".equals(searchTeamMemberBean.getLastName())) { dc.add(Restrictions.and( Restrictions.ilike("firstName", "%".concat(searchTeamMemberBean.getFirstName()).concat("%")), Restrictions.ilike("lastName", "%".concat(searchTeamMemberBean.getLastName()).concat("%")))); } else if (searchTeamMemberBean.getFirstName() != null && !"".equals(searchTeamMemberBean.getFirstName())) { dc.add(Restrictions.ilike("firstName", "%".concat(searchTeamMemberBean.getFirstName()).concat("%"))); } else if (searchTeamMemberBean.getLastName() != null && !"".equals(searchTeamMemberBean.getLastName())) { dc.add(Restrictions.ilike("lastName", "%".concat(searchTeamMemberBean.getLastName()).concat("%"))); } if (!searchTeamMemberBean.isWithDeleted()) { dc.add(Restrictions.eq("status", IConstant.NOM_TEAM_MEMBER_STATUS_ACTIVATED)); } if (searchTeamMemberBean.getProjectId() != null) { //if a project is selected, the team members project team must correspond to that project dc.createCriteria("projectTeam").add(Restrictions.eq("projectId", searchTeamMemberBean.getProjectId())); if (!searchTeamMemberBean.isIncludeFinishedAndAbandonedProjects()) { dc.createCriteria("projectTeam").createCriteria("project") .add(Restrictions.eq("status", IConstant.NOM_PROJECT_STATUS_OPENED)); } } if (searchTeamMemberBean.getOrganizationId() != null) { dc.createCriteria("projectTeam").createCriteria("project") .add(Restrictions.eq("organizationId", searchTeamMemberBean.getOrganizationId())); } List<TeamMember> members = getHibernateTemplate().findByCriteria(dc); logger.debug("getFromSearchSimple - END"); return members; }
From source file:ro.cs.cm.model.dao.impl.DaoTeamMemberImpl.java
License:Open Source License
/** * Retrieves from search a list of team members with basic info and pagination; search method * for TS person search/*from w w w.j a v a 2 s.c o m*/ * * @author Coni * @param searchTeamMemberBean * @return * @throws WSClientException * @throws IOException * @throws XmlMappingException * @throws BusinessException */ public List<TeamMember> getFromSearchSimpleWithPagination(SearchTeamMemberBean searchTeamMemberBean) throws XmlMappingException, IOException, WSClientException, BusinessException { logger.debug("getFromSearchSimpleWithPagination - START"); DetachedCriteria dc = DetachedCriteria .forEntityName(IModelConstant.teamMemberWithProjectTeamAndProjectEntity); DetachedCriteria dcCount = DetachedCriteria .forEntityName(IModelConstant.teamMemberWithProjectTeamAndProjectEntity); //retrieve all the team members for persons from the organization(which have personId != 0) or //not(which have firstName and lastName) that correspond to the search criteria if (searchTeamMemberBean.getFirstName() != null && !"".equals(searchTeamMemberBean.getFirstName()) && searchTeamMemberBean.getLastName() != null && !"".equals(searchTeamMemberBean.getLastName())) { dc.add(Restrictions.and( Restrictions.ilike("firstName", "%".concat(searchTeamMemberBean.getFirstName()).concat("%")), Restrictions.ilike("lastName", "%".concat(searchTeamMemberBean.getLastName()).concat("%")))); dcCount.add(Restrictions.and( Restrictions.ilike("firstName", "%".concat(searchTeamMemberBean.getFirstName()).concat("%")), Restrictions.ilike("lastName", "%".concat(searchTeamMemberBean.getLastName()).concat("%")))); } else if (searchTeamMemberBean.getFirstName() != null && !"".equals(searchTeamMemberBean.getFirstName())) { dc.add(Restrictions.ilike("firstName", "%".concat(searchTeamMemberBean.getFirstName()).concat("%"))); dcCount.add( Restrictions.ilike("firstName", "%".concat(searchTeamMemberBean.getFirstName()).concat("%"))); } else if (searchTeamMemberBean.getLastName() != null && !"".equals(searchTeamMemberBean.getLastName())) { dc.add(Restrictions.ilike("lastName", "%".concat(searchTeamMemberBean.getLastName()).concat("%"))); dcCount.add(Restrictions.ilike("lastName", "%".concat(searchTeamMemberBean.getLastName()).concat("%"))); } if (!searchTeamMemberBean.isWithDeleted()) { dc.add(Restrictions.eq("status", IConstant.NOM_TEAM_MEMBER_STATUS_ACTIVATED)); dcCount.add(Restrictions.eq("status", IConstant.NOM_TEAM_MEMBER_STATUS_ACTIVATED)); } DetachedCriteria dcOnProject = dc.createCriteria("projectTeam").createCriteria("project"); DetachedCriteria dcCountOnProject = dcCount.createCriteria("projectTeam").createCriteria("project"); if (searchTeamMemberBean.getProjectId() != null && !searchTeamMemberBean.getProjectId() .equals(Integer.valueOf(IConstant.NOM_TS_PERSON_SEARCH_IN_ORGANIZATION))) { if (searchTeamMemberBean.getProjectId() .equals(Integer.valueOf(IConstant.NOM_TS_PERSON_SEARCH_ALL_PROJECTS))) { //if the used doesn't have the permission to search in all the projects for team members, //the user must see all the persons from the projects where he is PM and only his person //for the projects where he isn't PM List<Project> userProjects = null; if (!searchTeamMemberBean.isHasPermissionToSeeAllProjects()) { if (!searchTeamMemberBean.isOnlyManager()) { userProjects = BLProject.getInstance().getProjectsByPerson( searchTeamMemberBean.getPersonId(), searchTeamMemberBean.isIncludeFinishedAndAbandonedProjects()); } else { userProjects = BLProject.getInstance().getProjectsByManager( searchTeamMemberBean.getPersonId(), searchTeamMemberBean.isIncludeFinishedAndAbandonedProjects()); } } else { userProjects = BLProject.getInstance().getAllProjects(searchTeamMemberBean.getOrganizationId(), searchTeamMemberBean.isIncludeFinishedAndAbandonedProjects()); } if (userProjects != null && !userProjects.isEmpty()) { List<Integer> projectIds = new ArrayList<Integer>(); for (Project prj : userProjects) { projectIds.add(prj.getProjectId()); } dcOnProject.add(Restrictions.in("projectId", projectIds)); dcCountOnProject.add(Restrictions.in("projectId", projectIds)); } else { return new ArrayList<TeamMember>(); } } else { //if a project is selected, the team members project team must correspond to that project dcOnProject.add(Restrictions.eq("projectId", searchTeamMemberBean.getProjectId())); dcCountOnProject.add(Restrictions.eq("projectId", searchTeamMemberBean.getProjectId())); } } if (searchTeamMemberBean.getOrganizationId() != null) { dcOnProject.add(Restrictions.eq("organizationId", searchTeamMemberBean.getOrganizationId())); dcCountOnProject.add(Restrictions.eq("organizationId", searchTeamMemberBean.getOrganizationId())); } // check if I have to order the results if (searchTeamMemberBean.getSortParam() != null && StringUtils.hasLength(searchTeamMemberBean.getSortParam())) { if (searchTeamMemberBean.getSortParam().equals("projectName")) { if (searchTeamMemberBean.getSortDirection() == IConstant.ASCENDING) { dcOnProject.addOrder(Order.asc("name")); } else { dcOnProject.addOrder(Order.desc("name")); } } else { // if I have to, check if I have to order them ascending or descending if (searchTeamMemberBean.getSortDirection() == IConstant.ASCENDING) { // ascending dc.addOrder(Order.asc(searchTeamMemberBean.getSortParam())); } else { // descending dc.addOrder(Order.desc(searchTeamMemberBean.getSortParam())); } } } // if the request didn't come from the pagination area, // it means that I have to set the number of result and pages if (searchTeamMemberBean.getNbrOfResults() == -1) { // set the countDistinct restriction dcCount.setProjection(Projections.countDistinct("memberId")); int nbrOfResults = ((Integer) getHibernateTemplate().findByCriteria(dcCount, 0, 0).get(0)).intValue(); searchTeamMemberBean.setNbrOfResults(nbrOfResults); logger.debug("NbrOfResults " + searchTeamMemberBean.getNbrOfResults()); logger.debug("----> searchPersonBean.getResults " + searchTeamMemberBean.getResultsPerPage()); // get the number of pages if (nbrOfResults % searchTeamMemberBean.getResultsPerPage() == 0) { searchTeamMemberBean.setNbrOfPages(nbrOfResults / searchTeamMemberBean.getResultsPerPage()); } else { searchTeamMemberBean.setNbrOfPages(nbrOfResults / searchTeamMemberBean.getResultsPerPage() + 1); } searchTeamMemberBean.setCurrentPage(1); } List<TeamMember> res = getHibernateTemplate().findByCriteria(dc, (searchTeamMemberBean.getCurrentPage() - 1) * searchTeamMemberBean.getResultsPerPage(), searchTeamMemberBean.getResultsPerPage()); logger.debug("getFromSearchSimpleWithPagination - END"); return res; }
From source file:ro.cs.om.model.dao.impl.DaoDepartmentImpl.java
License:Open Source License
/** * Searches for Departments after criterion from searchOrganisationBean. * * @author alu//from w w w. j ava 2 s . c o m * @author dan.damian */ public List<Department> getFromSearch(SearchDepartmentBean searchDepartmentBean, boolean isDeleteAction) throws ParseException { logger.debug("getFromSearch - START"); /*Once a Projection is being set to a Detached Criteria object, it cannot be removed anymore, so two identical DetachedCriteria objects must be created: -dcCount ( on which the projection is being set )used to retrieve the number of distinct results which is set when the request didn't come from the pagination area and needed further more to set the current page after a delete action; -dc used to retrieve the result set after the current page has been set in case of a delete action */ // set search criterion DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.departmentAllEntity); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.departmentAllEntity); dc.createAlias("manager", "manager", Criteria.LEFT_JOIN); dcCount.createAlias("manager", "manager", Criteria.LEFT_JOIN); if (Tools.getInstance().stringNotEmpty(searchDepartmentBean.getName())) { dc.add(Restrictions.ilike("name", "%".concat(searchDepartmentBean.getName()).concat("%"))); dcCount.add(Restrictions.ilike("name", "%".concat(searchDepartmentBean.getName()).concat("%"))); logger.debug("name: " + searchDepartmentBean.getName()); } if (searchDepartmentBean.getOrganisationId() != -1) { dc.add(Restrictions.eq("organisation.organisationId", searchDepartmentBean.getOrganisationId())); dcCount.add(Restrictions.eq("organisation.organisationId", searchDepartmentBean.getOrganisationId())); logger.debug("Organisation Id: " + searchDepartmentBean.getOrganisationId()); } if (searchDepartmentBean.getManagerFirstName() != null && !"".equals(searchDepartmentBean.getManagerFirstName())) { dc.add(Restrictions.eq("manager.firstName", searchDepartmentBean.getManagerFirstName())); dcCount.add(Restrictions.eq("manager.firstName", searchDepartmentBean.getManagerFirstName())); logger.debug("Manager first name: ".concat(searchDepartmentBean.getManagerFirstName())); } if (searchDepartmentBean.getManagerLastName() != null && !"".equals(searchDepartmentBean.getManagerLastName())) { dc.add(Restrictions.eq("manager.lastName", searchDepartmentBean.getManagerLastName())); dcCount.add(Restrictions.eq("manager.lastName", searchDepartmentBean.getManagerLastName())); logger.debug("Manager last name: ".concat(searchDepartmentBean.getManagerLastName())); } if (Tools.getInstance().stringNotEmpty(searchDepartmentBean.getParentDepartmentName())) { dc.createCriteria("parentDepartment").add(Restrictions.ilike("name", "%".concat(searchDepartmentBean.getParentDepartmentName()).concat("%"))); dcCount.createCriteria("parentDepartment").add(Restrictions.ilike("name", "%".concat(searchDepartmentBean.getParentDepartmentName()).concat("%"))); logger.debug("Parent Department Name: " + searchDepartmentBean.getParentDepartmentName()); } if (searchDepartmentBean.getParentDepartmentId() != -1) { dc.add(Restrictions.eq("parentDepartment.departmentId", searchDepartmentBean.getParentDepartmentId())); dcCount.add( Restrictions.eq("parentDepartment.departmentId", searchDepartmentBean.getParentDepartmentId())); logger.debug("Parent Department Id: " + searchDepartmentBean.getParentDepartmentId()); } dc.add(Restrictions.eq("status", IConstant.NOM_DEPARTMENT_ACTIVE)); dcCount.add(Restrictions.eq("status", IConstant.NOM_DEPARTMENT_ACTIVE)); // check if I have to order the results if (searchDepartmentBean.getSortParam() != null && !"".equals(searchDepartmentBean.getSortParam())) { // if I have to, check if I have to order them ascending or descending if (searchDepartmentBean.getSortDirection() == -1) { // ascending dc.addOrder(Order.asc(searchDepartmentBean.getSortParam())); } else { // descending dc.addOrder(Order.desc(searchDepartmentBean.getSortParam())); } } // if the request didn't come from the pagination area, // it means that I have to set the number of result and pages if (isDeleteAction || searchDepartmentBean.getNbrOfResults() == -1) { boolean isSearch = false; if (searchDepartmentBean.getNbrOfResults() == -1) { isSearch = true; } // set the countDistinct restriction dcCount.setProjection(Projections.distinct(Projections.countDistinct("departmentId"))); int nbrOfResults = ((Integer) getHibernateTemplate().findByCriteria(dcCount, 0, 0).get(0)).intValue(); searchDepartmentBean.setNbrOfResults(nbrOfResults); logger.debug("NbrOfResults " + searchDepartmentBean.getNbrOfResults()); logger.debug("----> searchOrganisationBean.getResults " + searchDepartmentBean.getResultsPerPage()); // get the number of pages if (nbrOfResults % searchDepartmentBean.getResultsPerPage() == 0) { searchDepartmentBean.setNbrOfPages(nbrOfResults / searchDepartmentBean.getResultsPerPage()); } else { searchDepartmentBean.setNbrOfPages(nbrOfResults / searchDepartmentBean.getResultsPerPage() + 1); } // after a department is deleted, the same page has to be displayed; //only when all the departments from last page are deleted, the previous page will be shown if (isDeleteAction && (searchDepartmentBean.getCurrentPage() > searchDepartmentBean.getNbrOfPages())) { searchDepartmentBean.setCurrentPage(searchDepartmentBean.getNbrOfPages()); } else if (isSearch) { searchDepartmentBean.setCurrentPage(1); } } List<Department> res = getHibernateTemplate().findByCriteria(dc, (searchDepartmentBean.getCurrentPage() - 1) * searchDepartmentBean.getResultsPerPage(), searchDepartmentBean.getResultsPerPage()); logger.debug("Res " + res.size()); logger.debug("getFromSearch - END - results size : ".concat(String.valueOf(res.size()))); return res; }
From source file:ro.cs.om.model.dao.impl.DaoDepartmentImpl.java
License:Open Source License
/** * Gets the number of departments for an organisation (without the fake departments) * //from w ww . j a v a 2 s .co m * @author Adelina * @parm organisationId * @return number of departments from an organisation */ @SuppressWarnings("unchecked") public int getCountDepartments(Integer organisationId) { logger.debug("getCountDepartments - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.departmentEntity); dc.setProjection(Projections.count("departmentId")); dc.createCriteria("organisation").add(Restrictions.eq("organisationId", organisationId)); dc.add(Restrictions.ne("status", (byte) 2)); List departaments = getHibernateTemplate().findByCriteria(dc); logger.debug("getCountDepartments - END - ".concat(String.valueOf(departaments.size()))); if (departaments != null) { int count = ((Integer) departaments.get(0)).intValue(); logger.debug("count " + count); return count; } else { return 0; } }
From source file:ro.cs.om.model.dao.impl.DaoFreeDayImpl.java
License:Open Source License
/** * Gets the list of free days for a calendar with a calendarId * /*from w w w. ja va 2 s . co m*/ * @author Adelina * @parm calendarId * @return List<FreeDay> */ @SuppressWarnings("unchecked") public List<FreeDay> getFreeDaysByCalendar(Integer calendarId) { logger.debug("getFreeDaysByCalendar DAO IMPL - START - "); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.freeDayEntity); dc.createCriteria("calendar").add(Restrictions.eq("calendarId", calendarId)); List freeDays = getHibernateTemplate().findByCriteria(dc); logger.debug("getFreeDaysByCalendar DAO IMPL - END - ".concat(String.valueOf(freeDays.size()))); return freeDays; }
From source file:ro.cs.om.model.dao.impl.DaoModuleImpl.java
License:Open Source License
/** * Returns all the modules ids for an organisation * @author Coni//from w w w. j a v a 2s . co m * @param organisationId * @return */ public List<Module> listModulesIdsByOrganisation(Integer organisationId) { logger.debug( "listModulesIdsByOrganisation - START - organisationId: ".concat(String.valueOf(organisationId))); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.moduleWithOrganisationsEntity); dc.createCriteria("organisations").add(Restrictions.eq("organisationId", organisationId)); List<Module> modules = getHibernateTemplate().findByCriteria(dc); logger.debug("listModulesIdsByOrganisation - END"); return modules; }
From source file:ro.cs.om.model.dao.impl.DaoOOOImpl.java
License:Open Source License
/** * Returns a list of persons that figure as replacements in at least one OOO profile * Receives as param a list of persons ids to look for * @author coni/* www.jav a 2 s . co m*/ * * @param personReplacementId * @return */ public List<Person> getOOOPersonReplacementsFromIds(Integer[] personReplacementId) { logger.debug("getByPersonReplacementID - START"); DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.oooAllEntity); dc.createCriteria("personReplacement").add(Restrictions.in("personId", personReplacementId)); dc.setProjection(Projections.distinct(Projections.property("personReplacement"))); List<Person> list = getHibernateTemplate().findByCriteria(dc); logger.debug("getByPersonReplacementID - END"); return list; }
From source file:ro.cs.om.model.dao.impl.DaoOOOImpl.java
License:Open Source License
/** * Searches for out of office profiles after criterion from searchOOOBean * @author alu// w w w . j a va2s. c om * @return A list of ooo beans * @throws ParseException */ public List getOOOBeanFromSearch(SearchOOOBean searchOOOBean, boolean isDeleteAction) throws ParseException { logger.debug("getOOOBeanFromSearch - START"); /*Once a Projection is being set to a Detached Criteria object, it cannot be removed anymore, so two identical DetachedCriteria objects must be created: -dcCount ( on which the projection is being set )used to retrieve the number of distinct results which is set when the request didn't come from the pagination area and needed further more to set the current page after a delete action; -dc used to retrieve the result set after the current page has been set in case of a delete action */ // set search criterion DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.oooAllEntity); DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.oooAllEntity); dc.createAlias("person", "person"); dcCount.createAlias("person", "person"); if (searchOOOBean.getOrganisationId() != -1) { dc.createCriteria("person.depts") .add(Restrictions.eq("organisationId", searchOOOBean.getOrganisationId())); dcCount.createCriteria("person.depts") .add(Restrictions.eq("organisationId", searchOOOBean.getOrganisationId())); } if (searchOOOBean.getOwnerFirstName() != null && !"".equals(searchOOOBean.getOwnerFirstName())) { dc.add(Restrictions.eq("person.firstName", searchOOOBean.getOwnerFirstName())); dcCount.add(Restrictions.eq("person.firstName", searchOOOBean.getOwnerFirstName())); logger.debug("Owner first name: ".concat(searchOOOBean.getOwnerFirstName())); } if (searchOOOBean.getOwnerLastName() != null && !"".equals(searchOOOBean.getOwnerLastName())) { dc.add(Restrictions.eq("person.lastName", searchOOOBean.getOwnerLastName())); dcCount.add(Restrictions.eq("person.lastName", searchOOOBean.getOwnerLastName())); logger.debug("Owner last name: ".concat(searchOOOBean.getOwnerLastName())); } if (searchOOOBean.getReplacementFirstName() != null && !"".equals(searchOOOBean.getReplacementFirstName()) && searchOOOBean.getReplacementLastName() != null && !"".equals(searchOOOBean.getReplacementLastName())) { dc.createCriteria("personReplacement") .add(Restrictions.eq("firstName", searchOOOBean.getReplacementFirstName())) .add(Restrictions.eq("lastName", searchOOOBean.getReplacementLastName())); dcCount.createCriteria("personReplacement") .add(Restrictions.eq("firstName", searchOOOBean.getReplacementFirstName())) .add(Restrictions.eq("lastName", searchOOOBean.getReplacementLastName())); } if (searchOOOBean.getStartPeriod() != null) { dc.add(Expression.ge("startPeriod", searchOOOBean.getStartPeriod())); dcCount.add(Expression.ge("startPeriod", searchOOOBean.getStartPeriod())); } if (searchOOOBean.getEndPeriod() != null) { dc.add(Expression.le("endPeriod", searchOOOBean.getEndPeriod())); dcCount.add(Expression.le("endPeriod", searchOOOBean.getEndPeriod())); } dc.setProjection(Projections.id()); dcCount.setProjection(Projections.id()); // until here, I've created the subquery // now, it's time to retrive all the profiles that are in the list of the subquery DetachedCriteria dc1 = DetachedCriteria.forEntityName(IModelConstant.oooAllEntity); dc1.createAlias("person", "person"); dc1.add(Subqueries.propertyIn("outOfOfficeId", dc)); // check if I have to order the results if (searchOOOBean.getSortParam() != null && !"".equals(searchOOOBean.getSortParam())) { logger.debug("Add sorting ! 234234"); // if I have to, check if I have to order them ascending or descending if (searchOOOBean.getSortDirection() == -1) { // ascending dc1.addOrder(Order.asc(searchOOOBean.getSortParam())); } else { // descending dc1.addOrder(Order.desc(searchOOOBean.getSortParam())); } } // if the request didn't come from the pagination area, // it means that I have to set the number of results and pages if (isDeleteAction || searchOOOBean.getNbrOfResults() == -1) { boolean isSearch = false; if (searchOOOBean.getNbrOfResults() == -1) { isSearch = true; } // set the count(*) restriction dcCount.setProjection(Projections.countDistinct("outOfOfficeId")); //findByCriteria must be called with firstResult and maxResults parameters; the default findByCriteria(DetachedCriteria criteria) implementation //sets firstResult and maxResults to -1, which kills the countDistinct Projection int nbrOfResults = ((Integer) getHibernateTemplate().findByCriteria(dcCount, 0, 0).get(0)).intValue(); logger.debug("search results: ".concat(String.valueOf(nbrOfResults))); searchOOOBean.setNbrOfResults(nbrOfResults); // get the number of pages if (nbrOfResults % searchOOOBean.getResultsPerPage() == 0) { searchOOOBean.setNbrOfPages(nbrOfResults / searchOOOBean.getResultsPerPage()); } else { searchOOOBean.setNbrOfPages(nbrOfResults / searchOOOBean.getResultsPerPage() + 1); } // after an ooo profile is deleted, the same page has to be displayed; //only when all the ooo profiles from last page are deleted, the previous page will be shown if (isDeleteAction && (searchOOOBean.getCurrentPage() > searchOOOBean.getNbrOfPages())) { searchOOOBean.setCurrentPage(searchOOOBean.getNbrOfPages()); } else if (isSearch) { searchOOOBean.setCurrentPage(1); } } List res = getHibernateTemplate().findByCriteria(dc1, (searchOOOBean.getCurrentPage() - 1) * searchOOOBean.getResultsPerPage(), searchOOOBean.getResultsPerPage()); logger.debug("getOOOBeanFromSearch - END results size : ".concat(String.valueOf(res.size()))); return res; }