Example usage for org.hibernate Query setDate

List of usage examples for org.hibernate Query setDate

Introduction

In this page you can find the example usage for org.hibernate Query setDate.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setDate(String name, Date val) 

Source Link

Document

Bind the val (time is truncated) of a given Date object to a named query parameter.

Usage

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

License:Open Source License

private Query getQueryForDrawingOfficer(List<Long> desigList, Integer doId, Date assignDate,
        String codeOrName) {//from w  w w  .j a  v  a2 s  .c o m
    StringBuilder qry = new StringBuilder()
            .append("select distinct eee.id as empid,eee.name as empname,eee.code as empcode,")
            .append(" do.id as doid,do.name as doname,do.code as docode from eg_eis_employeeinfo eee")
            .append(" inner join eg_position pos on pos.id = eee.pos_id")
            .append(" inner join eg_drawingofficer do on do.id = pos.id_drawing_officer ")
            .append(" where eee.isactive=1 and pos.id_drawing_officer is not null ")
            .append(" and :enteredDate between eee.from_date and eee.to_date ");

    if ((null != desigList && !desigList.isEmpty())) {
        qry.append(" and eee.designationid in (:desList) ");
    }
    if (null != codeOrName && !codeOrName.isEmpty()) {
        qry.append(
                " and (lower(do.name) like lower(:enteredString) or lower(do.code) like lower(:enteredString) ")
                .append(" or lower(eee.name) like lower(:enteredString) or lower(eee.code) like lower(:enteredString)) ");
    }
    if (null != doId) {
        qry.append(" and do.id=:doId ");
    }
    qry.append(" order by eee.name ");
    Query query = persistenceService.getSession().createSQLQuery(qry.toString());
    query.setDate("enteredDate", assignDate);
    if (null != desigList && !desigList.isEmpty()) {
        query.setParameterList("desList", desigList);
    }
    if (null != doId) {
        query.setInteger("doId", doId);
    }
    if (null != codeOrName && !codeOrName.isEmpty()) {
        query.setString("enteredString", "%" + codeOrName + "%");
    }

    return query;
}

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

License:Open Source License

public Assignment getAssignmentByEmpAndDate(Date date, Integer empId) {
    Assignment assignment = null;//  www.j  a  v a2s  .  c  o m
    try {

        if (empId != null) {
            String mainStr = " select    ev.assignment  from EmployeeView ev  where ev.assignment.isPrimary = 'Y' and ev.id = :empId and ((ev.toDate is null and ev.fromDate <= :date1 ) OR (ev.fromDate <= :date2 AND ev.toDate >= :date3 ))";
            Query qry = getCurrentSession().createQuery(mainStr);
            qry.setInteger("empId", empId);
            qry.setDate("date1", new java.sql.Date(date.getTime()));
            qry.setDate("date2", new java.sql.Date(date.getTime()));
            qry.setDate("date3", new java.sql.Date(date.getTime()));

            if (qry.list() != null && !qry.list().isEmpty()) {
                assignment = (Assignment) qry.list().get(0);
            }
        }

    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    }
    return assignment;
}

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

License:Open Source License

public Assignment getLatestAssignmentForEmployee(Integer empId) {
    // changing sysdate to current date of java
    Date currDate = new Date();
    Assignment assignment = null;/*w ww .j a  v a  2s  .  c om*/
    try {
        String mainStr = "";
        mainStr = " select ev.assignment from EmployeeView ev where ev.assignment.isPrimary = 'Y' and ev.id = :empId and ((ev.toDate is null and ev.fromDate <= :sysDate ) OR (ev.fromDate <= :sysDate AND ev.toDate >= :sysDate))";
        Query qry = getCurrentSession().createQuery(mainStr);

        if (empId != null) {
            qry.setInteger("empId", empId);
            qry.setDate("sysDate", new java.sql.Date(currDate.getTime()));
        }
        if (qry.list() != null && !qry.list().isEmpty()) {
            for (Iterator iter = qry.list().iterator(); iter.hasNext();) {
                assignment = (Assignment) iter.next();
            }
        }
    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    }
    return assignment;
}

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

License:Open Source License

public boolean checkPos(Integer posId, Date fromDate, Date toDate, Integer empId, String isPrimary) {

    boolean b = false;

    try {//from ww  w.  j av a 2  s  . c  o  m
        Query qry = null;

        if (fromDate != null && toDate != null) {
            String main = "from Assignment ev  where ev.isPrimary =:isPrimary and ev.position.id = :posId and ";
            if (empId != null) {
                main += "ev.employee.idPersonalInformation <>:empId and ";
            }
            main += "((ev.toDate is null ) or " + " (ev.fromDate <= :fromDate and ev.toDate >= :toDate) or "
                    + " (ev.toDate <= :toDate and ev.toDate >= :fromDate) or "
                    + " (ev.fromDate >= :fromDate and ev.fromDate <= :toDate))  ";

            qry = getCurrentSession().createQuery(main);

        } else if (fromDate != null && toDate == null) {
            qry = getCurrentSession().createQuery(
                    "from Assignment ev  where ev.position.id = :posId and ((ev.toDate is null ) or (ev.fromDate <= :fromDate AND ev.toDate >= :fromDate))");

        }
        if (posId != null) {
            qry.setInteger("posId", posId);

        }
        if (empId != null) {
            qry.setInteger("empId", empId);

        }
        if (isPrimary != null) {
            qry.setCharacter("isPrimary", Character.valueOf(isPrimary.charAt(0)));
        }
        if (fromDate != null && toDate != null) {
            qry.setDate("fromDate", new java.sql.Date(fromDate.getTime()));
            qry.setDate("toDate", new java.sql.Date(toDate.getTime()));

        } else if (fromDate != null && toDate == null) {
            qry.setDate("fromDate", new java.sql.Date(fromDate.getTime()));
        }

        if (qry.list() != null && !qry.list().isEmpty()) {
            b = true;
        }

    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);

    }
    return b;

}

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

License:Open Source License

public PersonalInformation getEmpForPositionAndDate(Date dateEntered, Integer posId) throws Exception {

    PersonalInformation personalInformation = null;
    try {/*from   w w  w.  j a va 2  s .  co  m*/
        Query qry = null;
        if (dateEntered != null) {
            qry = getCurrentSession().createQuery(
                    "select ev.id from EmployeeView ev  where ev.position = :posId and ((ev.toDate is null ) or (ev.fromDate <= :fromDate AND ev.toDate >= :fromDate))");

        } else if (dateEntered == null) {
            qry = getCurrentSession().createQuery(
                    "select ev.id from EmployeeView ev  where ev.position = :posId and ((ev.toDate is null ) or (ev.fromDate <=  TO_DATE(SYSDATE,'dd-MM-yyy') AND ev.toDate >=  TO_DATE(SYSDATE,'dd-MM-yyy')))");
        }
        if (posId != null) {
            qry.setInteger("posId", posId);

        }
        if (dateEntered != null) {
            qry.setDate("fromDate", new java.sql.Date(dateEntered.getTime()));
        }

        if (qry.list() != null && !qry.list().isEmpty()) {
            for (Iterator iter = qry.list().iterator(); iter.hasNext();) {
                Integer id = (Integer) iter.next();
                personalInformation = EisManagersUtill.getEmployeeService().getEmloyeeById(id);
            }
        }

    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    }

    return personalInformation;
}

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

License:Open Source License

/**
 * Returns list of employees for a given position and date
 * // w w w.  j  a  va  2 s  . c o m
 * @param dateEntered
 * @param posId
 * @return
 * @throws Exception
 */
public List<PersonalInformation> getEmpListForPositionAndDate(Date dateEntered, Integer posId)
        throws Exception {

    PersonalInformation personalInformation = null;
    List<PersonalInformation> empList = null;
    try {
        Query qry = null;
        if (dateEntered != null) {
            qry = getCurrentSession().createQuery(
                    "select distinct ev.id from EmployeeView ev  where ev.position = :posId and ((ev.toDate is null ) or (ev.fromDate <= :fromDate AND ev.toDate >= :fromDate))");

        } else if (dateEntered == null) {
            qry = getCurrentSession().createQuery(
                    "select distinct ev.id from EmployeeView ev  where ev.position = :posId and ((ev.toDate is null ) or (ev.fromDate <=  TO_DATE(SYSDATE,'dd-MM-yyy') AND ev.toDate >=  TO_DATE(SYSDATE,'dd-MM-yyy')))");
        }
        if (posId != null) {
            qry.setInteger("posId", posId);

        }
        if (dateEntered != null) {
            qry.setDate("fromDate", new java.sql.Date(dateEntered.getTime()));
        }

        if (qry.list() != null && !qry.list().isEmpty()) {
            empList = new ArrayList();
            for (Iterator iter = qry.list().iterator(); iter.hasNext();) {
                Integer id = (Integer) iter.next();
                personalInformation = EisManagersUtill.getEmployeeService().getEmloyeeById(id);
                empList.add(personalInformation);
            }
        }

    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    }

    return empList;
}

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

License:Open Source License

/**
 * Returns a list of temporary Assignments as on given date for employees
 * that have the given code and position. If any of the parameters are null,
 * the parameter is ignored. For instance, if givenDate is null, all
 * temporary assignments for employee with given code and when assigned to
 * givenPosition will be returned/*from ww w  . j  av  a  2  s.  c  o  m*/
 * 
 * @param code
 * @param givenDate
 * @param posId
 * @return List of Assignment
 */
public List getEmpTempAssignment(String code, Date givenDate, Integer posId) {

    List assignment = null;
    try {
        String mainStr = "";
        mainStr = "from Assignment ev  where ev.isPrimary='N'";

        if (code != null && !code.equals("")) {
            mainStr += "and ev.employee.employeeCode =:code ";
        }
        if (givenDate != null) {
            mainStr += " and ev.fromDate <= :givenDate and ev.toDate >=:givenDate";
        }

        if (posId != null && posId != 0) {
            mainStr += " and ev.position.id =:posId ";
        }
        Query qry = getCurrentSession().createQuery(mainStr);
        if (code != null && !code.equals("")) {
            qry.setString("code", code);
        }
        if (givenDate != null) {
            qry.setDate("givenDate", givenDate);
        }
        if (posId != null && posId != 0) {
            qry.setInteger("posId", posId);
        }

        assignment = qry.list();
    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    }
    return assignment;

}

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

License:Open Source License

/**
 * Returns a list of assignment ids. All assignments for the employee based
 * on employee id and that fall in the given date will be returned.
 * //from  w w  w  .j  ava2s .c om
 * @param empId
 *            - Required parameter. If null is passed, the API throws an
 *            ApplicationException
 * @param givenDate
 *            . Date as on which the assignments need to be returned. If
 *            this parameter is null, the current date is considered
 * @return List of Assignment Ids
 * @throws ApplicationException
 */
public List<Integer> getAssignmentsForEmp(Integer empId, Date givenDate) throws ApplicationException {
    List list = null;
    Query query = null;
    try {

        StringBuffer stringbuffer = new StringBuffer(
                " select    ASS_ID  from EG_EIS_EMPLOYEEINFO ev  where ev.ID = :empId");

        if (empId == null) {
            throw new ApplicationException("EmployeeId  Not provided");
        } else if (givenDate == null) {
            stringbuffer.append(
                    " and ((ev.to_Date is null and ev.from_Date <= SYSDATE ) OR (ev.from_Date <= SYSDATE AND ev.to_Date >= SYSDATE))");

        } else {
            stringbuffer.append(" and  ev.from_Date <= :givenDate AND ev.to_Date >= :givenDate");
        }
        query = getCurrentSession().createSQLQuery(stringbuffer.toString()).addScalar("ASS_ID",
                IntegerType.INSTANCE);

        if (query.getQueryString().contains(":givenDate")) {
            query.setDate("givenDate", givenDate);
        }

        query.setInteger("empId", empId);

    } catch (HibernateException hibException) {
        LOGGER.error(hibException.getMessage());
        throw new ApplicationException("HibernateException:" + hibException.getMessage(), hibException);
    }

    return query.list();

}

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

License:Open Source License

/**
 * API that will return all positions for a user(temporary and permanent)
 * for a date./*w w w  .  ja v a 2  s.  com*/
 *
 * @param user
 *            . Required. User object for which the positions are queried
 * @param date
 *            Will consider current date if date is not provided
 * @return
 * @throws ApplicationException
 */

public List<Position> getPositionsForUser(User user, Date date) throws ApplicationException {

    List<Position> positionList = new ArrayList<Position>();
    Integer pos = null;
    try {
        String mainStr = "";

        mainStr = "select a.position.id from Assignment a where a.employee.userMaster.id =:userId";

        if (date != null) {
            mainStr += " and ((a.toDate is null and a.fromDate<= :date) or (a.fromDate <= :date and a.toDate >= :date))";
        } else {
            mainStr += " and ((a.toDate is null and a.fromDate<= TO_DATE(SYSDATE,'dd-MM-yyy')) or (a.fromDate <= TO_DATE(SYSDATE,'dd-MM-yyy') and a.toDate >= TO_DATE(SYSDATE,'dd-MM-yyy')))";
        }
        Query qry = getCurrentSession().createQuery(mainStr);
        if (user != null) {
            qry.setLong("userId", user.getId());
        }
        if (date != null) {
            qry.setDate("date", date);
        }

        if (qry.list() != null && !qry.list().isEmpty()) {

            for (Iterator iter = qry.list().iterator(); iter.hasNext();) {
                pos = (Integer) iter.next();
                Position position = EisManagersUtill.getEisCommonsService().getPositionById(pos);
                positionList.add(position);
            }
        }

    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    }
    return positionList;
}

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

License:Open Source License

/**
 * Returns a list of primary Assignments as on given date for employees that
 * have the given code and position. If any of the parameters are null, the
 * parameter is ignored. For instance, if givenDate is null, all primary
 * assignments for employee with given code and when assigned to
 * givenPosition will be returned//  w  w  w .j a  v a2 s  .  c o m
 *
 * @param code
 * @param givenDate
 * @param posId
 * @return
 */
public List getEmpPrimaryAssignment(String code, Date givenDate, Integer posId) {

    List assignment = null;
    try {
        String mainStr = "";
        mainStr = "from Assignment ev  where ev.isPrimary='Y'";

        if (code != null && !code.equals("")) {
            mainStr += "and ev.employee.employeeCode =:code ";
        }
        if (givenDate != null) {
            mainStr += " and ev.fromDate <= :givenDate and ev.toDate >=:givenDate";
        }

        if (posId != null && posId != 0) {
            mainStr += " and ev.position.id =:posId ";
        }
        Query qry = getCurrentSession().createQuery(mainStr);
        if (code != null && !code.equals("")) {
            qry.setString("code", code);
        }
        if (givenDate != null) {
            qry.setDate("givenDate", givenDate);
        }
        if (posId != null && posId != 0) {
            qry.setInteger("posId", posId);
        }

        assignment = qry.list();
    } catch (HibernateException he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    } catch (Exception he) {
        LOGGER.error(he);
        throw new ApplicationRuntimeException("Exception:" + he.getMessage(), he);
    }
    return assignment;

}