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:uk.ac.ox.oucs.vle.CourseDAOImpl.java

License:Educational Community License

@SuppressWarnings("unchecked")
public Integer countSignupByCourse(final String courseId, final Set<Status> statuses, final Date now) {
    return (Integer) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Query query = session.createQuery("select count(signup.id) from CourseSignupDAO signup "
                    + "left join signup.components component " + "left join signup.group grp "
                    + "where grp.courseId = :courseId " + "and component.starts > :now "
                    + "and signup.status in (:statuses)");
            query.setString("courseId", courseId);
            query.setDate("now", now);
            query.setParameterList("statuses", statuses);
            return ((Number) query.uniqueResult()).intValue();
        }//from  w w  w.j  ava 2s.c  o  m

    });
}

From source file:uk.ac.ox.oucs.vle.CourseDAOImpl.java

License:Educational Community License

@SuppressWarnings("unchecked")
public List<CourseSignupDAO> findSignupByComponent(final String componentId, final Set<Status> statuses,
        final Integer year) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Query query;
            LocalDate startYear = null;
            LocalDate endYear = null;

            StringBuffer querySQL = new StringBuffer();
            querySQL.append("select cs from CourseSignupDAO cs " + "inner join fetch cs.components cc "
                    + "where cc.presentationId = :componentId");

            if (null != statuses && !statuses.isEmpty()) {
                querySQL.append(" and cs.status in (:statuses)");
            }/*from w  w  w  .jav  a 2  s .  c o  m*/

            if (null != year) {
                startYear = FIRST_DAY_OF_ACADEMIC_YEAR.toLocalDate(year);
                endYear = FIRST_DAY_OF_ACADEMIC_YEAR.toLocalDate(year + 1);
                querySQL.append(" and cc.starts between :starts and :ends");
            }

            query = session.createQuery(querySQL.toString());
            query.setString("componentId", componentId);
            if (null != statuses && !statuses.isEmpty()) {
                query.setParameterList("statuses", statuses);
            }

            if (null != year) {
                query.setDate("starts", startYear.toDate());
                query.setDate("ends", endYear.toDate());
            }
            return query.list();
        }
    });
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override//from   ww w  . j a  v a 2  s. c o  m
public List<Analysis> getAnalysisStartedOnExcludedByStatusId(Date collectionDate, Set<Integer> statusIds)
        throws LIMSRuntimeException {
    if (statusIds == null || statusIds.isEmpty()) {
        return getAnalysisStartedOn(collectionDate);
    }

    String sql = "from Analysis a where a.startedDate = :startedDate and a.statusId not in ( :statusList )";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setDate("startedDate", collectionDate);
        query.setParameterList("statusList", statusIds);

        List<Analysis> analysisList = query.list();
        closeSession();
        return analysisList;
    } catch (HibernateException e) {
        handleException(e, "getAnalysisStartedOnExcludedByStatusId");
    }

    return null;
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
public List<Analysis> getAnalysisStartedOn(Date collectionDate) throws LIMSRuntimeException {

    try {/*from   w w w  .j ava  2  s. c o m*/
        String sql = "from Analysis a where a.startedDate = :startedDate";
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setDate("startedDate", collectionDate);

        List<Analysis> list = query.list();
        closeSession();
        return list;

    } catch (HibernateException he) {
        handleException(he, "getAnalysisStartedOn");
    }

    return null;
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override/*from  w  w w.j ava2  s.  c o m*/
public List<Analysis> getAnalysisCollectedOnExcludedByStatusId(Date collectionDate, Set<Integer> statusIds)
        throws LIMSRuntimeException {
    if (statusIds == null || statusIds.isEmpty()) {
        return getAnalysisStartedOn(collectionDate);
    }

    String sql = "from Analysis a where a.sampleItem.collectionDate = :startedDate and a.statusId not in ( :statusList )";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setDate("startedDate", collectionDate);
        query.setParameterList("statusList", statusIds);

        List<Analysis> analysisList = query.list();
        closeSession();
        return analysisList;
    } catch (HibernateException e) {
        handleException(e, "getAnalysisStartedOnExcludedByStatusId");
    }

    return null;
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
public List<Analysis> getAnalysisCollectedOn(Date collectionDate) throws LIMSRuntimeException {

    try {/*from   www  . j av a  2 s.com*/
        String sql = "from Analysis a where a.sampleItem.collectionDate = :startedDate";
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setDate("startedDate", collectionDate);

        List<Analysis> list = query.list();
        closeSession();
        return list;

    } catch (HibernateException he) {
        handleException(he, "getAnalysisStartedOn");
    }

    return null;
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
public List<Analysis> getAnalysisByTestSectionAndCompletedDateRange(String sectionID, Date lowDate,
        Date highDate) throws LIMSRuntimeException {

    String sql = "From Analysis a where a.testSection.id = :testSectionId and a.completedDate BETWEEN :lowDate AND :highDate";

    try {/*from  w  ww  . j  a v  a 2s.com*/
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setInteger("testSectionId", Integer.parseInt(sectionID));
        query.setDate("lowDate", lowDate);
        query.setDate("highDate", highDate);

        List<Analysis> list = query.list();
        closeSession();
        return list;
    } catch (HibernateException he) {
        handleException(he, "getAnalysisByTestSectionAndCompletedDateRange");
    }

    return null;
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
public List<Analysis> getAnalysisStartedOrCompletedInDateRange(Date lowDate, Date highDate)
        throws LIMSRuntimeException {
    String sql = "From Analysis a where a.startedDate BETWEEN :lowDate AND :highDate or a.completedDate BETWEEN :lowDate AND :highDate";

    try {//www  .  j ava2 s.  co m
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setDate("lowDate", lowDate);
        query.setDate("highDate", highDate);

        List<Analysis> list = query.list();
        closeSession();
        return list;
    } catch (HibernateException he) {
        handleException(he, "getAnalysisStartedOrCompletedInDateRange");
    }

    return null;

}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override//from w  w w.j a v a2s . com
public List<Analysis> getAnalysisStartedOnRangeByStatusId(Date lowDate, Date highDate, String statusID)
        throws LIMSRuntimeException {
    String sql = "From Analysis a where a.statusId = :statusID and a.startedDate BETWEEN :lowDate AND :highDate";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setInteger("statusID", Integer.parseInt(statusID));
        query.setDate("lowDate", lowDate);
        query.setDate("highDate", highDate);

        List<Analysis> analysisList = query.list();
        closeSession();
        return analysisList;

    } catch (HibernateException e) {
        handleException(e, "getAnalysisStartedOnRangeByStatusId");
    }

    return null;
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

License:Mozilla Public License

@Override
public List<Analysis> getAnalysisByTestNamesAndCompletedDateRange(List<String> testNames, Date lowDate,
        Date highDate) throws LIMSRuntimeException {
    if (testNames.isEmpty()) {
        return new ArrayList<Analysis>();
    }//  w w w  .j  av a  2 s  .  c  o  m

    String sql = "From Analysis a where a.test.testName in (:testNames) and a.completedDate BETWEEN :lowDate AND :highDate";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setParameterList("testNames", testNames);
        query.setDate("lowDate", lowDate);
        query.setDate("highDate", highDate);

        @SuppressWarnings("unchecked")
        List<Analysis> list = query.list();
        closeSession();
        return list;
    } catch (HibernateException he) {
        handleException(he, "getAnalysisByTestNamesAndCompletedDateRange");
    }

    return null;
}