Example usage for org.hibernate.criterion Restrictions and

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

Introduction

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

Prototype

public static LogicalExpression and(Criterion lhs, Criterion rhs) 

Source Link

Document

Return the conjuction of two expressions

Usage

From source file:org.dspace.xmlworkflow.storedcomponents.dao.impl.CollectionRoleDAOImpl.java

License:BSD License

@Override
public CollectionRole findByCollectionAndRole(Context context, Collection collection, String role)
        throws SQLException {
    Criteria criteria = createCriteria(context, CollectionRole.class);
    criteria.add(Restrictions.and(Restrictions.eq("collection", collection), Restrictions.eq("roleId", role)));

    return uniqueResult(criteria);

}

From source file:org.dspace.xmlworkflow.storedcomponents.dao.impl.InProgressUserDAOImpl.java

License:BSD License

@Override
public InProgressUser findByWorkflowItemAndEPerson(Context context, XmlWorkflowItem workflowItem,
        EPerson ePerson) throws SQLException {
    Criteria criteria = createCriteria(context, InProgressUser.class);
    criteria.add(Restrictions.and(Restrictions.eq("workflowItem", workflowItem),
            Restrictions.eq("ePerson", ePerson)));
    return uniqueResult(criteria);
}

From source file:org.dspace.xmlworkflow.storedcomponents.dao.impl.InProgressUserDAOImpl.java

License:BSD License

@Override
public int countInProgressUsers(Context context, XmlWorkflowItem workflowItem) throws SQLException {
    Criteria criteria = createCriteria(context, InProgressUser.class);
    criteria.add(Restrictions.and(Restrictions.eq("workflowItem", workflowItem),
            Restrictions.eq("finished", false)));

    return count(criteria);
}

From source file:org.dspace.xmlworkflow.storedcomponents.dao.impl.InProgressUserDAOImpl.java

License:BSD License

@Override
public int countFinishedUsers(Context context, XmlWorkflowItem workflowItem) throws SQLException {
    Criteria criteria = createCriteria(context, InProgressUser.class);
    criteria.add(/* w w w  .j  ava  2  s  . c o  m*/
            Restrictions.and(Restrictions.eq("workflowItem", workflowItem), Restrictions.eq("finished", true)));
    return count(criteria);
}

From source file:org.dspace.xmlworkflow.storedcomponents.dao.impl.PoolTaskDAOImpl.java

License:BSD License

@Override
public PoolTask findByWorkflowItemAndEPerson(Context context, XmlWorkflowItem workflowItem, EPerson ePerson)
        throws SQLException {
    Criteria criteria = createCriteria(context, PoolTask.class);
    criteria.add(Restrictions.and(Restrictions.eq("workflowItem", workflowItem),
            Restrictions.eq("ePerson", ePerson)));

    return uniqueResult(criteria);
}

From source file:org.dspace.xmlworkflow.storedcomponents.dao.impl.PoolTaskDAOImpl.java

License:BSD License

@Override
public PoolTask findByWorkflowItemAndGroup(Context context, Group group, XmlWorkflowItem workflowItem)
        throws SQLException {
    Criteria criteria = createCriteria(context, PoolTask.class);
    criteria.add(//w  w w.ja v  a 2 s  .c om
            Restrictions.and(Restrictions.eq("workflowItem", workflowItem), Restrictions.eq("group", group)));

    return uniqueResult(criteria);
}

From source file:org.dspace.xmlworkflow.storedcomponents.dao.impl.WorkflowItemRoleDAOImpl.java

License:BSD License

@Override
public List<WorkflowItemRole> findByWorkflowItemAndRole(Context context, XmlWorkflowItem workflowItem,
        String role) throws SQLException {
    Criteria criteria = createCriteria(context, WorkflowItemRole.class);
    criteria.add(// w  w w .  ja va2s  .  c  om
            Restrictions.and(Restrictions.eq("workflowItem", workflowItem), Restrictions.eq("role", role)));

    return list(criteria);
}

From source file:org.egov.pims.commons.service.PositionService.java

License:Open Source License

/**
 * gives vacant positions for given date range and designation 
 * @param fromDate/*from w  w w  .j ava 2s . c  om*/
 * @param toDate
 * @param designationMasterId
 * @return
 */
public Criteria getVacantPositionCriteria(Date fromDate, Date toDate, Integer designationMasterId) {
    DetachedCriteria detachAssignmentPrd = DetachedCriteria.forClass(Assignment.class, "assignment");
    detachAssignmentPrd
            .add(Restrictions.and(Restrictions.le("assignment.fromDate", fromDate),
                    Restrictions.or(Restrictions.ge("assignment.toDate", toDate),
                            Restrictions.isNull("assignment.toDate"))))
            .setProjection(Projections.property("assignment.id"));

    DetachedCriteria detachAssignment = DetachedCriteria.forClass(Assignment.class, "assignment");
    detachAssignment.add(Subqueries.propertyIn("assignment.id", detachAssignmentPrd));
    detachAssignment.add(Restrictions.eq("assignment.isPrimary", 'Y'));
    detachAssignment.setProjection(Projections.distinct(Projections.property("assignment.position.id")));

    Criteria criteria = getCurrentSession().createCriteria(Position.class, "position");
    if (designationMasterId != null && !designationMasterId.equals("0")) {
        criteria.add(Restrictions.eq("position.deptDesig.designation.id", designationMasterId));
    }

    criteria.add(Subqueries.propertyNotIn("position.id", detachAssignment));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.addOrder(Order.asc("position.name"));
    return criteria;
}

From source file:org.egov.pims.service.EisUtilService.java

License:Open Source License

/**
 * Use the API getAllDesignationsByDepartment in DesignationService.java
 * <p>//from   www.j a v a  2  s.  co m
 * return all distinct Designations to which employees are assigned in the
 * given department for given date. This list includes primary as well as
 * secondary assignments. If there is No Designation for the given
 * department then returns the empty list
 *
 * @param departmentId
 * @param givenDate
 * @return DesignationMaster List
 * @deprecated
 */
@Deprecated
public List<Designation> getAllDesignationByDept(Integer departmentId, Date givenDate) {
    Date userGivenDate = givenDate == null ? new Date() : givenDate;
    Long deptId = departmentId.longValue();
    Criteria criteria = persistenceService.getSession().createCriteria(Assignment.class, "assign")
            .createAlias("assign.department", "department").add(Restrictions.eq("department.id", deptId))
            .add(Restrictions.and(Restrictions.le("assign.fromDate", userGivenDate),
                    Restrictions.ge("assign.toDate", userGivenDate)));

    ProjectionList projections = Projections.projectionList().add(Projections.property("assign.designation"));
    criteria.setProjection(projections);
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    return (List<Designation>) criteria.list();

}

From source file:org.egov.pims.service.EmployeeServiceImpl.java

License:Open Source License

/**
 * Returns the list of Employees who are assigned to the given department
 * and designation as of current date.//  w  w w . j  a va2 s.c  o m
 * 
 * @param deptId
 *            - Integer representing id of department
 * @param desgId
 *            - Integer representing id of designation
 * @return List of EmployeeView
 */
public List<EmployeeView> getEmployeeInfoBasedOnDeptAndDesg(Integer deptId, Integer desgId) {
    List<EmployeeView> employeeList = new ArrayList<EmployeeView>();
    Criteria criteria = getCurrentSession().createCriteria(EmployeeView.class)
            .createAlias("deptId", "department").createAlias("desigId", "designation")
            .add(Restrictions.eq("department.id", deptId))
            .add(Restrictions.eq("designation.designationId", desgId))
            .add(Restrictions.and(Restrictions.le("fromDate", new Date()),
                    Restrictions.ge("toDate", new Date())))
            .add(Restrictions.eq("isPrimary", 'Y')).add(Restrictions.eq("isActive", 1));
    return criteria.list();

}