Example usage for org.hibernate Criteria createCriteria

List of usage examples for org.hibernate Criteria createCriteria

Introduction

In this page you can find the example usage for org.hibernate Criteria createCriteria.

Prototype

public Criteria createCriteria(String associationPath) throws HibernateException;

Source Link

Document

Create a new Criteria, "rooted" at the associated entity.

Usage

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

License:Open Source License

/**
 * Find by change control and order by control account name
 * //  w  w  w .  j a v  a2 s . com
 * @param changecontrol
 * @return
 */
@SuppressWarnings("unchecked")
public List<Changerequestwbsnode> findByChangeControl(Changecontrol changecontrol) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Changerequestwbsnode.CHANGECONTROL, changecontrol));

    // Order and join
    //
    Criteria wbsNodeCrit = crit.createCriteria(Changerequestwbsnode.WBSNODE);
    addOrder(wbsNodeCrit, Wbsnode.NAME, Constants.ASCENDENT);

    return crit.list();
}

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

License:Open Source License

/**
 * Find By Project//from  w w w . j ava2  s  . c om
 * 
 * @param project
 * @param propertyOrder
 * @param typeOrder
 * @return
 */
@SuppressWarnings("unchecked")
public List<Checklist> findByProject(Project project, String propertyOrder, String typeOrder) {

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

    addOrder(crit, propertyOrder, typeOrder);

    crit.createCriteria(Checklist.WBSNODE).add(Restrictions.eq(Wbsnode.PROJECT, project));

    return crit.list();
}

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

License:Open Source License

/**
 * Search Contacts by filter//  w  ww  .  j a  v a  2  s.c o  m
 * @param resourcepools
  * @param fullName
  * @param fileAs
  * @param performingorg
  * @param company
  * @param skills
  *@param jobcategories @return
 */
@SuppressWarnings("unchecked")
public List<Contact> searchByFilter(String fullName, String fileAs, Performingorg performingorg,
        Company company, List<Resourcepool> resourcepools, List<Skill> skills,
        List<Jobcategory> jobcategories) {

    Contact example = new Contact();
    example.setFileAs(fileAs);
    example.setFullName(fullName);

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .add(Example.create(example).ignoreCase().enableLike(MatchMode.ANYWHERE))
            .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true)));

    // Company
    //
    crit.createCriteria(Contact.COMPANY).add(Restrictions.idEq(company.getIdCompany()))
            .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)));

    // Employee
    Criteria critEmployee = crit.createCriteria(Contact.EMPLOYEES, CriteriaSpecification.LEFT_JOIN);

    if (performingorg != null && performingorg.getIdPerfOrg() != null && performingorg.getIdPerfOrg() != -1) {

        critEmployee.createCriteria(Employee.PERFORMINGORG)
                .add(Restrictions.idEq(performingorg.getIdPerfOrg()));
    }

    if (ValidateUtil.isNotNull(resourcepools)) {
        critEmployee.add(Restrictions.in(Employee.RESOURCEPOOL, resourcepools));
    }

    if (ValidateUtil.isNotNull(skills)) {
        critEmployee.createCriteria(Employee.SKILLSEMPLOYEES)
                .add(Restrictions.in(Skillsemployee.SKILL, skills));
    }

    if (ValidateUtil.isNotNull(jobcategories)) {
        critEmployee.createCriteria(Employee.JOBCATEMPLOYEES)
                .add(Restrictions.in(Jobcatemployee.JOBCATEGORY, jobcategories));
    }

    return crit.list();
}

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

License:Open Source License

/**
 * These contact has profile in company/* w  w  w.  j  a  va  2 s .c o m*/
 * @param perfOrg
 * @param contact
 * @param profile
 * @return
 */
public boolean hasProfile(Performingorg perfOrg, Contact contact, Resourceprofiles profile) {
    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.idEq(contact.getIdContact()));

    crit.createCriteria(Contact.EMPLOYEES).add(Restrictions.eq(Employee.RESOURCEPROFILES, profile))
            .add(Restrictions.eq(Employee.PERFORMINGORG, perfOrg));

    return ((Integer) crit.uniqueResult() > 0);
}

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

License:Open Source License

/**
 * These contact has a resource pool in company
 * @param contact/*  ww w . j a  v  a 2s  .  com*/
 * @return
 */
public boolean hasResourcePool(Contact contact, Resourceprofiles teamMember) {
    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount())
            .add(Restrictions.idEq(contact.getIdContact()));

    crit.createCriteria(Contact.EMPLOYEES).add(Restrictions.eq(Employee.RESOURCEPROFILES, teamMember))
            .add(Restrictions.isNotNull(Employee.RESOURCEPOOL));

    return ((Integer) crit.uniqueResult() > 0);
}

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

License:Open Source License

/**
 * Find owners LLAA/*w ww .  ja  va  2 s .  co m*/
 *
 * @param company
 * @return
 */
public List<Contact> findUsedInLLAA(Company company) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY)
            .add(Restrictions.eq(Contact.COMPANY, company))
            .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true)))
            .addOrder(Order.asc(Contact.FULLNAME));

    crit.createCriteria(Contact.LEARNEDLESSONS).add(Restrictions.eq(LearnedLesson.COMPANY, company));

    return crit.list();
}

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

License:Open Source License

/**
 * Find notifications by contact//from   w w w  .j  ava 2  s  .co  m
 * 
 * @param company
 * @return
 */
@SuppressWarnings("unchecked")
public List<Contactnotification> findByContact(Contact contact) {

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

    if (contact != null && contact.getCompany() != null) {

        // Filter by contact and company
        crit.createCriteria(Contactnotification.CONTACT)
                .add(Restrictions.eq(Contact.COMPANY, contact.getCompany()))
                .add(Restrictions.eq(Contact.IDCONTACT, contact.getIdContact()));

        // Join notification and orders
        //
        crit.createCriteria(Contactnotification.NOTIFICATION).addOrder(Order.desc(Notification.CREATIONDATE));

        crit.addOrder(Order.desc(Contactnotification.READNOTIFY));

        // Max results
        crit.setMaxResults(50);
    }

    return crit.list();
}

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

License:Open Source License

/**
 * Find notifications/*from   w  ww  .java 2s.c om*/
 *
 * @param notificationSearch
 * @return
 */
public List<Contactnotification> find(NotificationSearch notificationSearch) {

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

    // TODO javier.hernandez - 14/09/2015 - implement filters

    // Filter by contact and company
    crit.createCriteria(Contactnotification.CONTACT)
            .add(Restrictions.eq(Contact.IDCONTACT, notificationSearch.getContact().getIdContact()));

    // Join notification and orders
    //
    crit.createCriteria(Contactnotification.NOTIFICATION).addOrder(Order.desc(Notification.CREATIONDATE));

    crit.addOrder(Order.desc(Contactnotification.READNOTIFY));

    // Max results
    crit.setMaxResults(50);

    return crit.list();
}

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

License:Open Source License

private void applyFilters(Criteria crit, List<DatoColumna> filtrosExtras) throws ParseException {

    SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");

    for (DatoColumna filtroColumna : filtrosExtras) {

        if (filtroColumna.getTipo() == Date.class) {

            // Filtramos si es una fecha
            Date tempDate = df.parse(filtroColumna.getValor());
            crit.add(Restrictions.eq(filtroColumna.getNombre(), tempDate));
        } else if (filtroColumna.getTipo() == Integer.class) {

            // Filtramos si es un numero
            Integer integer = Integer.parseInt(filtroColumna.getValor());
            crit.add(Restrictions.eq(filtroColumna.getNombre(), integer));
        } else if (filtroColumna.getTipo() == Boolean.class) {

            // Filtramos si es un booleano
            Boolean bool = Boolean.parseBoolean(filtroColumna.getValor());
            crit.add(Restrictions.eq(filtroColumna.getNombre(), bool));
        } else if (filtroColumna.getTipo() == List.class) {

            // Since Until
            if (filtroColumna.getSubTipo() != null && filtroColumna.getSubTipo() == Date.class) {

                Date sinceDate = (Date) filtroColumna.getObjectList()[0];
                Date untilDate = (Date) filtroColumna.getObjectList()[1];

                String sinceName = (String) filtroColumna.getNombreList()[0];
                String untilName = (String) filtroColumna.getNombreList()[1];

                crit.add(Restrictions.disjunction().add(Restrictions.between(sinceName, sinceDate, untilDate))
                        .add(Restrictions.between(untilName, sinceDate, untilDate)).add(Restrictions.and(
                                Restrictions.le(sinceName, sinceDate), Restrictions.ge(untilName, untilDate))));
            } else {
                // Tiene que estar en la lista
                crit.add(Restrictions.in(filtroColumna.getNombre(), filtroColumna.getValorList()));
            }//from   w  ww  .ja v  a  2s . c om
        } else if (filtroColumna.getTipo() == String.class) {

            if (filtroColumna.getSubTipo() == List.class) {

                if (!ValidateUtil.isNull(filtroColumna.getValor())) {
                    String[] value = filtroColumna.getValor().split(",");
                    List<Integer> ids = new ArrayList<Integer>();

                    for (String id : value) {
                        ids.add(Integer.parseInt(id));
                    }
                    if (filtroColumna.getCriteria() != null) {
                        Criteria crit2 = crit.createCriteria(filtroColumna.getCriteria());
                        crit2.add(Restrictions.in(filtroColumna.getNombre(), ids));
                    } else {
                        crit.add(Restrictions.in(filtroColumna.getNombre(), ids));
                    }
                }
            } else {
                // Comparando texto
                crit.add(Restrictions.like(filtroColumna.getNombre(), "%" + filtroColumna.getValor() + "%"));
            }
        } else {

            // Filtrando Objectos
            crit.add(Restrictions.eq(filtroColumna.getNombre(), filtroColumna.getObject()));
        }
    }
}

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

License:Open Source License

/**
 * Search Employee By filter/* ww  w .  java  2s .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();
}