Example usage for org.hibernate.criterion DetachedCriteria forEntityName

List of usage examples for org.hibernate.criterion DetachedCriteria forEntityName

Introduction

In this page you can find the example usage for org.hibernate.criterion DetachedCriteria forEntityName.

Prototype

@SuppressWarnings("UnusedDeclaration")
public static DetachedCriteria forEntityName(String entityName) 

Source Link

Document

Static builder to create a DetachedCriteria for the given entity.

Usage

From source file:ro.cs.om.model.dao.impl.DaoDepartmentImpl.java

License:Open Source License

/**
 * List the first level SubDepartments of this Department, each of them containing only the basic information 
 * /*w  w w  .jav a2s  .c  om*/
 * @author coni
 * @param departmentId this Department's id 
 * @return
 */
public List<Department> listFirstLevelSubDepartments(Integer departmentId) {
    logger.debug("listFirstLevelSubDepartments - START - for departmentId: ".concat(departmentId.toString()));

    List<Department> subDepartments = new ArrayList<Department>();
    DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.departmentSimpleEntity);
    dc.add(Restrictions.eq("parentDepartmentId", departmentId));
    //dc.add(Restrictions.eq("organisationId", organisationId));
    subDepartments = getHibernateTemplate().findByCriteria(dc);

    logger.debug("listFirstLevelSubDepartments - END - for departmentId: ".concat(departmentId.toString()));
    return subDepartments;
}

From source file:ro.cs.om.model.dao.impl.DaoDepartmentImpl.java

License:Open Source License

/**
 * Lists all Potential Parent Departments for this Department.
 * Potential Parents are found by discriminating from all Organization's Departments
 * those that are part from this Department's subtree of departments.
 * @author dan.damian //from w ww. j av a2s.  co  m
 */
public List<Department> listPotentialParentDepartments(Integer departmentId, Integer organisationId) {
    logger.debug("listPotentialParentDepartments - START - departmentId ".concat(departmentId.toString())
            .concat("organisation Id ").concat(organisationId.toString()));

    List<Department> potentialParentDepartments = new ArrayList<Department>();
    List<Integer> allSubDepartmentsIds = listAllSubDepartmentsIds(departmentId, organisationId);

    Tools.getInstance().printList(logger, allSubDepartmentsIds);
    DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.departmentSimpleEntity);

    allSubDepartmentsIds.add(departmentId);
    dc.add(Restrictions.not(Restrictions.in("departmentId", allSubDepartmentsIds)));

    dc.add(Restrictions.eq("organisationId", organisationId));
    dc.add(Restrictions.eq("status", IConstant.NOM_DEPARTMENT_ACTIVE));

    potentialParentDepartments = getHibernateTemplate().findByCriteria(dc);
    Tools.getInstance().printList(logger, potentialParentDepartments);

    logger.debug("listPotentialParentDepartments - END - results " + potentialParentDepartments.size());
    return potentialParentDepartments;
}

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 www . j  a v a  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.DaoJobImpl.java

License:Open Source License

/**
 * Return the list of active jobs for an Organisation
 * //from   w w w . ja v a  2 s .com
 * @author mitziuro
 */
public List<Job> getActiveJobsByOrganisationId(int organisationId) {
    logger.debug("getJobsForOrganisation - START :".concat(" orgId - ").concat(String.valueOf(organisationId)));

    // set search criterion
    DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.jobEntity);

    if (organisationId != -1) {
        dc.add(Restrictions.eq("organisation.organisationId", organisationId));
    }

    dc.add(Restrictions.eq("status", ((int) IConstant.NOM_JOB_ACTIVE)));

    List<Job> res = getHibernateTemplate().findByCriteria(dc);

    logger.debug("getJobsForOrganisation - END results size : ".concat(String.valueOf(res.size())));
    return res;
}

From source file:ro.cs.om.model.dao.impl.DaoJobImpl.java

License:Open Source License

/**
 * Returns a list of jobs/*from w  ww .  j  a va 2s .  c o m*/
 * 
 * @author mitziuro
 */
public List<Job> getJobBeanFromSearch(SearchJobBean searchJobBean, boolean isChangeAction) {
    logger.debug("getJobBeanFromSearch - START - name:".concat(searchJobBean.getName()).concat(" orgId - ")
            .concat(String.valueOf(searchJobBean.getOrganisationId())));
    /*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.jobForListingEntity);
    DetachedCriteria dcCount = DetachedCriteria.forEntityName(IModelConstant.jobForListingEntity);

    if (searchJobBean.getName() != null && !"".equals(searchJobBean.getName())) {
        dc.add(Restrictions.ilike("name", "%".concat(searchJobBean.getName()).concat("%")));
        dcCount.add(Restrictions.ilike("name", "%".concat(searchJobBean.getName()).concat("%")));
    }

    if (searchJobBean.getOrganisationId() != -1) {
        logger.debug("getJobBeanFromSearch - START - name:" + searchJobBean.getOrganisationId());
        dc.add(Restrictions.eq("organisation.organisationId", searchJobBean.getOrganisationId()));
        dcCount.add(Restrictions.eq("organisation.organisationId", searchJobBean.getOrganisationId()));
    }

    if (searchJobBean.getStatus() != -1) {
        dc.add(Restrictions.eq("status", searchJobBean.getStatus()));
        dcCount.add(Restrictions.eq("status", searchJobBean.getStatus()));
    }

    // check if I have to order the results
    if (searchJobBean.getSortParam() != null && !"".equals(searchJobBean.getSortParam())) {
        // if I have to, check if I have to order them ascending or
        // descending
        if (searchJobBean.getSortDirection() == -1) {
            // ascending
            dc.addOrder(Order.asc(searchJobBean.getSortParam()));
        } else {
            // descending
            dc.addOrder(Order.desc(searchJobBean.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 (isChangeAction || searchJobBean.getNbrOfResults() == -1) {
        boolean isSearch = false;
        if (searchJobBean.getNbrOfResults() == -1) {
            isSearch = true;
        }

        // set the count(*) restriction
        dcCount.setProjection(Projections.countDistinct("jobId"));

        //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)));
        searchJobBean.setNbrOfResults(nbrOfResults);

        // get the number of pages
        if (nbrOfResults % searchJobBean.getResultsPerPage() == 0) {
            searchJobBean.setNbrOfPages(nbrOfResults / searchJobBean.getResultsPerPage());
        } else {
            searchJobBean.setNbrOfPages(nbrOfResults / searchJobBean.getResultsPerPage() + 1);
        }

        // after a job is deleted, the same page has to be displayed;
        //only when all the jobs from last page are deleted, the previous page will be shown 
        if (isChangeAction && (searchJobBean.getCurrentPage() > searchJobBean.getNbrOfPages())) {
            searchJobBean.setCurrentPage(searchJobBean.getNbrOfPages());
        } else if (isSearch) {
            searchJobBean.setCurrentPage(1);
        }
    }
    List<Job> res = (List<Job>) getHibernateTemplate().findByCriteria(dc,
            (searchJobBean.getCurrentPage() - 1) * searchJobBean.getResultsPerPage(),
            searchJobBean.getResultsPerPage());

    logger.debug("getJobBeanFromSearch - END results size : ".concat(String.valueOf(res.size())));
    return res;
}

From source file:ro.cs.om.model.dao.impl.DaoJobImpl.java

License:Open Source License

/**
 * /*from  w  w  w .  j ava 2  s  . co  m*/
 * Return the list of jobs for an organization
 * 
 * @author Adelina
 *
 * @param organisationId
 * @return
 */
public List<Job> getJobsByOrganisationId(int organisationId) {
    logger.debug(
            "getJobsByOrganisationId - START :".concat(" orgId - ").concat(String.valueOf(organisationId)));

    // set search criterion
    DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.jobEntity);

    if (organisationId != -1) {
        dc.add(Restrictions.eq("organisation.organisationId", organisationId));
    }

    List<Job> res = getHibernateTemplate().findByCriteria(dc);

    logger.debug("getJobsByOrganisationId - END results size : ".concat(String.valueOf(res.size())));
    return res;
}

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 www. j  a  v  a 2  s  .  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/*from  w w w.  j  ava2  s. com*/
  * 
  * @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//from   w w  w  . j  av  a2s.  co m
* @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;
}

From source file:ro.cs.om.model.dao.impl.DaoOOOImpl.java

License:Open Source License

/**
  * Returns all the ooo profiles/*from  ww  w  . java 2 s  .c o  m*/
  * 
  * @author Adelina
  * 
  * @return List<OutOfOffice>
  */

public List<OutOfOffice> getAllOOO() {
    logger.debug("Dao getOOO - START");

    DetachedCriteria dc = DetachedCriteria.forEntityName(IModelConstant.oooAllEntity);
    List<OutOfOffice> list = getHibernateTemplate().findByCriteria(dc);
    logger.debug("OOO list = " + list.size() + ", " + list);
    logger.debug("Dao getOOO - END");
    return list;
}