Example usage for org.hibernate.criterion Restrictions ne

List of usage examples for org.hibernate.criterion Restrictions ne

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions ne.

Prototype

public static SimpleExpression ne(String propertyName, Object value) 

Source Link

Document

Apply a "not equal" constraint to the named property

Usage

From source file:es.emergya.bbdd.dao.RecursoHome.java

License:Open Source License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public Recurso[] getNotAsigned(Flota p) {
    Recurso[] res = new Recurso[0];
    if (p == null || p.getId() == null) {
        return getByFilter(new Recurso()).toArray(new Recurso[0]);
    }/*from   ww w .j a v  a2  s  .com*/
    try {
        log.debug("getNotAsigned(" + p.getId() + ")");
        Session currentSession = getSession();
        currentSession.clear();
        Criterion rhs = Restrictions.isNull("flotas");
        Criterion lhs = Restrictions.ne("flotas", currentSession.load(Patrulla.class, p.getId()));
        Criteria criteria = currentSession.createCriteria(Recurso.class).add(Restrictions.or(lhs, rhs));
        criteria = criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        res = ((List<Recurso>) criteria.list()).toArray(new Recurso[0]);

        for (Recurso r : res)
            try {
                r.getFlotas().getId();
            } catch (Throwable t) {
            }
    } catch (Throwable t) {
        log.error(t, t);
    }
    return res;
}

From source file:es.emergya.bbdd.dao.UsuarioHome.java

License:Open Source License

@Transactional(readOnly = true, rollbackFor = Throwable.class, propagation = Propagation.REQUIRES_NEW)
public Boolean isLastAdmin(String nombre) {
    org.hibernate.Session currentSession = getSession();
    currentSession.clear();/*  www.j  a v a 2s. com*/
    Criteria criteria = currentSession.createCriteria(Usuario.class).setProjection(Projections.rowCount())
            .add(Restrictions.eq("administrador", true)).add(Restrictions.eq("habilitado", true))
            .add(Restrictions.ne("nombreUsuario", nombre)).setCacheable(false);
    Integer count = (Integer) criteria.uniqueResult();
    return (count.intValue() == 0);
}

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

License:Open Source License

/**
 * Search Contacts by filter/*  w ww  .ja  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

/**
 * Find owners LLAA/*from ww w .jav  a 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.EmployeeDAO.java

License:Open Source License

/**
 * Search Employee By filter/*from  w w w. jav 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 w  w  w .ja va  2  s  .c  o  m

    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 Approvals Time Sheets by Functional Manager
 * //  w  w  w.j  av a2  s. co 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

/**
 * Cons employees for login and profile/*w  w w.j a  v a2s . co  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 ww  w . 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

/**
 * Consult resource managers by employee
 * /*from   ww  w.  j  av  a2  s .  c om*/
 * @param employee
 * @return
 */
@SuppressWarnings("unchecked")
public List<Employee> consResourceManagers(Employee employee) {

    List<Employee> listEmployee = null;

    if (employee != null && employee.getResourcepool() != null) {

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

        crit.createCriteria(Employee.MANAGEPOOLS)
                .add(Restrictions.eq(Managepool.RESOURCEPOOL, employee.getResourcepool()));

        Criteria critContact = crit.createCriteria(Employee.CONTACT);

        critContact.createCriteria(Contact.COMPANY).add(
                Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true)));

        listEmployee = crit.list();
    }

    return listEmployee;
}