Example usage for org.hibernate FetchMode JOIN

List of usage examples for org.hibernate FetchMode JOIN

Introduction

In this page you can find the example usage for org.hibernate FetchMode JOIN.

Prototype

FetchMode JOIN

To view the source code for org.hibernate FetchMode JOIN.

Click Source Link

Document

Fetch using an outer join.

Usage

From source file:es.sm2.openppm.core.dao.EmployeeDAO.java

License:Open Source License

/**
 * Search Employee By filter//from   w ww  .  j av  a 2 s .  c o 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);/*from  ww  w.j a  va  2s .c  om*/

    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/*  www.j a va  2 s . c o m*/
 * @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

/**
 * Search employee by contact and PO and rol
 * @param idContact//  w  ww .ja  va2 s. c  o m
 * @param performingorg
 * @param idProfile
 * @return
 */
public Employee findByContactAndPOAndRol(int idContact, Performingorg performingorg, int idProfile) {

    Criteria crit = getSession().createCriteria(getPersistentClass());

    crit.add(Restrictions.eq(Employee.CONTACT, new Contact(idContact)));

    if (performingorg != null) {
        crit.add(Restrictions.eq(Employee.PERFORMINGORG, performingorg));
    }

    crit.add(Restrictions.eq(Employee.RESOURCEPROFILES, new Resourceprofiles(idProfile)))
            .setFetchMode(Employee.CONTACT, FetchMode.JOIN).createCriteria(Employee.CONTACT)
            .addOrder(Order.asc(Contact.FULLNAME));

    return (Employee) crit.uniqueResult();
}

From source file:es.sm2.openppm.core.dao.EmployeeDAO.java

License:Open Source License

/**
 * Find Approvals Time Sheets by Functional Manager
 * /*from w ww  . jav a2 s. c o m*/
 * @param user
 * @param initDate
 * @param endDate
 * @param status
 * @param statusResource
 * @param includeClosed
 * @param onlyOperations 
 * @param employees - not equals
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> findApprovals(Employee user, Date initDate, Date endDate, String status,
        String statusResource, boolean includeClosed, List<Employee> employees, boolean onlyOperations) {

    Resourceprofiles profile = user.getResourceprofiles();

    Criteria crit = getSession().createCriteria(getPersistentClass(), "e")
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).setFetchMode(Employee.CONTACT, FetchMode.JOIN);

    if (ValidateUtil.isNotNull(employees)) {

        List<Integer> ids = new ArrayList<Integer>();
        for (Employee item : employees) {
            ids.add(item.getIdEmployee());
        }

        crit.add(Restrictions.not(Restrictions.in("e." + Employee.IDEMPLOYEE, ids)));
    }

    crit.createCriteria(Employee.TIMESHEETS, "ts").add(Restrictions.eq(Timesheet.INITDATE, initDate))
            .add(Restrictions.eq(Timesheet.ENDDATE, endDate)).add(Restrictions.eq(Timesheet.STATUS, status))
            .createAlias(Timesheet.PROJECTACTIVITY, "pa", Criteria.LEFT_JOIN)
            .createAlias("pa." + Projectactivity.PROJECT, "p", Criteria.LEFT_JOIN);

    if (ValidateUtil.isNotNull(statusResource)) {
        crit.createCriteria("pa." + Projectactivity.TEAMMEMBERS)
                .add(Restrictions.eq(Teammember.STATUS, statusResource)).createCriteria(Teammember.EMPLOYEE)
                .add(Restrictions.eqProperty(Employee.IDEMPLOYEE, "e." + Employee.IDEMPLOYEE));
    } else if (onlyOperations) {
        crit.add(Restrictions.isNotNull("ts." + Timesheet.OPERATION));
    }

    // Exluce projects closed
    if (!includeClosed) {
        crit.add(Restrictions.and(Restrictions.ne("p." + Project.STATUS, Constants.STATUS_CLOSED),
                Restrictions.ne("p." + Project.STATUS, Constants.STATUS_ARCHIVED)));
    }

    // Filter by User. Settings by company for last approval. 
    if (profile.getIdProfile() == Constants.ROLE_FM) {

        crit.add(Restrictions.or(Restrictions.eq("p." + Project.EMPLOYEEBYFUNCTIONALMANAGER, user),
                Restrictions.and(Restrictions.isNull("ts." + Timesheet.PROJECTACTIVITY),
                        Restrictions.eq("e." + Employee.PERFORMINGORG, user.getPerformingorg()))));
    } else if (profile.getIdProfile() == Constants.ROLE_PMO) {

        crit.add(Restrictions.or(Restrictions.eq("p." + Project.PERFORMINGORG, user.getPerformingorg()),
                Restrictions.and(Restrictions.isNull("ts." + Timesheet.PROJECTACTIVITY),
                        Restrictions.eq("e." + Employee.PERFORMINGORG, user.getPerformingorg()))));
    }

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.EmployeeDAO.java

License:Open Source License

/**
 * Find Approvals Expenses by Functional Manager
 * @param user/*w  w  w.  ja  v  a 2  s  . c o  m*/
 * @param since
 * @param until
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> findApprovalsExpense(Employee user, Date since, Date until) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).setFetchMode(Employee.CONTACT, FetchMode.JOIN);

    crit.createCriteria(Employee.EXPENSESHEETS)
            .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until))
            .add(Restrictions.or(Restrictions.eq(Expensesheet.STATUS, Constants.TIMESTATUS_APP2),
                    Restrictions.eq(Expensesheet.STATUS, Constants.TIMESTATUS_APP3)));

    crit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg()));

    return crit.list();
}

From source file:es.sm2.openppm.core.dao.EmployeeDAO.java

License:Open Source License

/**
 * Find Employees where inputed hours is approval
 * /* ww  w.j ava  2 s .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/*from  w ww.  ja  v a 2  s.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/*from  w ww .j  a v  a  2s  .c  om*/
 * 
 * @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();
}

From source file:es.sm2.openppm.core.dao.EmployeeDAO.java

License:Open Source License

/**
 * Find Employees where inputed hours is approval
 * /*w w w . j  a v  a 2  s .c o m*/
 * @param idResourcePools 
 * @param projects
 * @param fullName 
 * @param idJobCategories 
 * @param idPMs 
 * @param idSellers 
 * @param idCategories 
 * @param since
 * @param until
 * @param order 
 * @param nameOrder 
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> findInputedInProjects(Integer[] idResourcePools, List<Project> projects, Integer[] idPMs,
        Integer[] idJobCategories, Integer[] idSellers, Integer[] idCategories, String fullName, Date since,
        Date until, String nameOrder, String order, Employee user) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    // Filter by user
    if (user != null) {
        crit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg()));
    }

    // Aliases 
    //
    crit.createAlias(Employee.TEAMMEMBERS, "tm", CriteriaSpecification.INNER_JOIN)
            .createAlias(Employee.TIMESHEETS, "ts", CriteriaSpecification.INNER_JOIN)
            .createAlias("tm." + Teammember.PROJECTACTIVITY, "pa", CriteriaSpecification.INNER_JOIN)
            .createAlias("pa." + Projectactivity.PROJECT, "p", CriteriaSpecification.LEFT_JOIN)
            .createAlias("p." + Project.EMPLOYEEBYPROJECTMANAGER, "pm", CriteriaSpecification.LEFT_JOIN)
            .createAlias(Employee.RESOURCEPOOL, "rp", CriteriaSpecification.LEFT_JOIN)
            .createAlias(Employee.SELLER, "s", CriteriaSpecification.LEFT_JOIN)
            .createAlias("tm." + Teammember.JOBCATEGORY, "jc", CriteriaSpecification.LEFT_JOIN)
            .createAlias("p." + Project.CATEGORY, "c", CriteriaSpecification.LEFT_JOIN);

    // Teammembers 
    //
    crit.add(Restrictions.eq("tm." + Teammember.STATUS, Constants.RESOURCE_ASSIGNED));

    if (since != null && until != null) {

        crit.add(Restrictions.disjunction().add(Restrictions.between("tm." + Teammember.DATEIN, since, until))
                .add(Restrictions.between("tm." + Teammember.DATEOUT, since, until))
                .add(Restrictions.and(Restrictions.le("tm." + Teammember.DATEIN, since),
                        Restrictions.ge("tm." + Teammember.DATEOUT, until))));
    }

    // Timesheets 
    //
    crit.add(Restrictions.eq("ts." + Timesheet.STATUS, Constants.TIMESTATUS_APP3));

    if (since != null && until != null) {

        crit.add(Restrictions.disjunction().add(Restrictions.between("ts." + Timesheet.INITDATE, since, until))
                .add(Restrictions.between("ts." + Timesheet.ENDDATE, since, until))
                .add(Restrictions.and(Restrictions.le("ts." + Timesheet.INITDATE, since),
                        Restrictions.ge("ts." + Timesheet.ENDDATE, until))));
    }

    // Filters
    //
    Conjunction conjunction = Restrictions.conjunction();

    // Filter by projects
    if (ValidateUtil.isNotNull(projects)) {
        conjunction.add(Restrictions.in("pa." + Projectactivity.PROJECT, projects));
    }
    // Filter by project managers
    if (ValidateUtil.isNotNull(idPMs)) {
        conjunction.add(Restrictions.in("pm." + Employee.IDEMPLOYEE, idPMs));
    }
    // Filter by resourcepools
    if (ValidateUtil.isNotNull(idResourcePools)) {
        conjunction.add(Restrictions.in("rp." + Resourcepool.IDRESOURCEPOOL, idResourcePools));
    }
    // Filter by sellers
    if (ValidateUtil.isNotNull(idSellers)) {
        conjunction.add(Restrictions.in("s." + Seller.IDSELLER, idSellers));
    }
    // Filter by jobcategories
    if (ValidateUtil.isNotNull(idJobCategories)) {
        conjunction.add(Restrictions.in("jc." + Jobcategory.IDJOBCATEGORY, idJobCategories));
    }
    // Filter by categories
    if (ValidateUtil.isNotNull(idCategories)) {
        conjunction.add(Restrictions.in("c." + Category.IDCATEGORY, idCategories));
    }

    crit.add(conjunction);

    // Filter by Full Name
    Criteria contactCrit = crit.createCriteria(Employee.CONTACT);

    if (ValidateUtil.isNotNull(fullName)) {
        contactCrit.add(Restrictions.ilike(Contact.FULLNAME, "%" + fullName + "%"));
    }

    // Apply Order
    Criteria orderCrit = null;

    String alias = StringPool.BLANK;

    if (Project.IDPROJECT.equals(nameOrder)) {

        alias = "pm.";
        orderCrit = crit;
    } else if (Jobcategory.IDJOBCATEGORY.equals(nameOrder)) {
        alias = "jc.";
        orderCrit = crit;
    } else {
        orderCrit = contactCrit;
    }

    if (nameOrder != null) {

        if (Constants.DESCENDENT.equals(order)) {
            orderCrit.addOrder(Order.desc(alias + nameOrder));
        } else {
            orderCrit.addOrder(Order.asc(alias + nameOrder));
        }
    }

    // Calendar base 
    crit.setFetchMode(Employee.CALENDARBASE, FetchMode.JOIN);

    return crit.list();
}