Example usage for org.hibernate Query setTimestamp

List of usage examples for org.hibernate Query setTimestamp

Introduction

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

Prototype

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

Source Link

Document

Bind the value and the time of a given Date object to a named query parameter.

Usage

From source file:storybook.model.dao.LocationDAOImpl.java

License:Open Source License

public long countByPersonLocationDate(Person person, Location location, Date date) {
    date = DateUtil.getZeroTimeDate(date);
    Query query = session
            .createQuery("select count(s) from Scene as s" + " join s.persons as p" + " join s.locations as l"
                    + " where p=:person and l=:location" + " and s.sceneTs between :tsStart and :tsEnd");
    query.setEntity("person", person);
    query.setEntity("location", location);
    Timestamp tsStart = new Timestamp(date.getTime());
    date = DateUtils.addDays(date, 1);/*from ww  w .j a  va 2 s.c o  m*/
    date = DateUtils.addMilliseconds(date, -1);
    Timestamp tsEnd = new Timestamp(date.getTime());
    query.setTimestamp("tsStart", tsStart);
    query.setTimestamp("tsEnd", tsEnd);
    return (Long) query.uniqueResult();
}

From source file:storybook.model.dao.SceneDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Scene> findByDate(Date date) {
    if (date == null) {
        return new ArrayList<Scene>();
    }/*w  ww . j av  a  2s . com*/
    Query query = session.createQuery("select s from Scene as s"
            + " where s.sceneTs between :tsStart and :tsEnd" + " order by s.sceneTs, s.sceneno");
    Timestamp tsStart = new Timestamp(date.getTime());
    date = DateUtils.addDays(date, 1);
    date = DateUtils.addMilliseconds(date, -1);
    Timestamp tsEnd = new Timestamp(date.getTime());
    query.setTimestamp("tsStart", tsStart);
    query.setTimestamp("tsEnd", tsEnd);
    return (List<Scene>) query.list();
}

From source file:storybook.model.dao.SceneDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Scene> findByStrandAndDate(Strand strand, Date date) {
    if (date == null) {
        return new ArrayList<Scene>();
    }//from  ww  w . ja v a 2 s. c o  m
    // OLD: Query query = session
    // .createQuery("from Scene s where s.sceneTs = :sceneTs and s.strand=:strand order by s.sceneTs");
    Query query = session.createQuery("select s from Scene as s" + " left join s.chapter as ch"
            + " where s.sceneTs between :tsStart and :tsEnd and s.strand=:strand"
            + " order by s.sceneTs, ch.chapterno, s.sceneno");
    Timestamp tsStart = new Timestamp(date.getTime());
    Date date2 = DateUtils.addDays(date, 1);
    date2 = DateUtils.addMilliseconds(date2, -1);
    Timestamp tsEnd = new Timestamp(date2.getTime());
    query.setTimestamp("tsStart", tsStart);
    query.setTimestamp("tsEnd", tsEnd);
    query.setEntity("strand", strand);
    List<Scene> ret = query.list();
    // find scenes with relative date
    List<Scene> scenes = findScenesWithRelativeSceneId();
    for (Scene scene : scenes) {
        if (!scene.getStrand().getId().equals(strand.getId())) {
            continue;
        }
        Scene relativeScene = (Scene) session.get(Scene.class, scene.getRelativeSceneId());
        Date sceneDate = scene.getRelativeDate(relativeScene);
        if (sceneDate == null) {
            continue;
        }
        if (sceneDate.compareTo(date) != 0) {
            continue;
        }
        ret.add(scene);
    }
    return ret;
}

From source file:storybook.model.hbn.dao.SceneDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Scene> findByDate(Date date) {
    if (date == null) {
        return new ArrayList<>();
    }/*from  ww w  . j  a v  a2s  . c om*/
    Query query = session.createQuery("select s from Scene as s"
            + " where s.sceneTs between :tsStart and :tsEnd" + " order by s.sceneTs, s.sceneno");
    Timestamp tsStart = new Timestamp(date.getTime());
    date = DateUtils.addDays(date, 1);
    date = DateUtils.addMilliseconds(date, -1);
    Timestamp tsEnd = new Timestamp(date.getTime());
    query.setTimestamp("tsStart", tsStart);
    query.setTimestamp("tsEnd", tsEnd);
    return (List<Scene>) query.list();
}

From source file:storybook.model.hbn.dao.SceneDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Scene> findByStrandAndDate(Strand strand, Date date) {
    if (date == null) {
        return new ArrayList<>();
    }//from   w  w w .  j av  a  2s  . co  m
    // OLD: Query query = session
    // .createQuery("from Scene s where s.sceneTs = :sceneTs and s.strand=:strand order by s.sceneTs");
    Query query = session.createQuery("select s from Scene as s" + " left join s.chapter as ch"
            + " where s.sceneTs between :tsStart and :tsEnd and s.strand=:strand"
            + " order by s.sceneTs, ch.chapterno, s.sceneno");
    Timestamp tsStart = new Timestamp(date.getTime());
    Date date2 = DateUtils.addDays(date, 1);
    date2 = DateUtils.addMilliseconds(date2, -1);
    Timestamp tsEnd = new Timestamp(date2.getTime());
    query.setTimestamp("tsStart", tsStart);
    query.setTimestamp("tsEnd", tsEnd);
    query.setEntity("strand", strand);
    List<Scene> ret = query.list();
    // find scenes with relative date
    List<Scene> scenes = findScenesWithRelativeSceneId();
    for (Scene scene : scenes) {
        if (!scene.getStrand().getId().equals(strand.getId())) {
            continue;
        }
        Scene relativeScene = (Scene) session.get(Scene.class, scene.getRelativeSceneId());
        Date sceneDate = scene.getRelativeDate(relativeScene);
        if (sceneDate == null) {
            continue;
        }
        if (sceneDate.compareTo(date) != 0) {
            continue;
        }
        ret.add(scene);
    }
    return ret;
}

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

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override/*from  ww  w.ja v  a2  s.c o m*/
public List<Analysis> getAnalysisCompleteInRange(Timestamp lowDate, Timestamp highDate)
        throws LIMSRuntimeException {
    String sql = "From Analysis a where a.completedDate >= :lowDate AND a.completedDate < :highDate";

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

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

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

    return null;
}

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

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override//  w w  w . j a v  a2 s.  co  m
public List<Analysis> getAnalysisEnteredAfterDate(Timestamp date) throws LIMSRuntimeException {
    String sql = "From Analysis a where a.enteredDate > :date";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setTimestamp("date", date);

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

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

    return null;
}

From source file:us.mn.state.health.lims.dataexchange.aggregatereporting.daoimpl.ReportExternalExportDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override/*  w  w w .  ja  v  a2  s  .c  o  m*/
public List<ReportExternalExport> getReportsInDateRange(Timestamp lower, Timestamp upper,
        String reportQueueTypeId) throws LIMSRuntimeException {
    String sql = "from ReportExternalExport rq where rq.sentDate >= :lower and rq.sentDate <= :upper";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setTimestamp("lower", lower);
        query.setTimestamp("upper", upper);
        List<ReportExternalExport> reports = query.list();

        closeSession();

        return reports;
    } catch (HibernateException e) {
        handleException(e, "getReportsInDateRange");
    }

    return null;
}

From source file:us.mn.state.health.lims.dataexchange.aggregatereporting.daoimpl.ReportExternalImportDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override//from   w w  w  .ja v  a  2  s . co m
public List<ReportExternalImport> getReportsInDateRangeSorted(Timestamp lower, Timestamp upper)
        throws LIMSRuntimeException {
    String sql = "from ReportExternalImport rq where rq.eventDate >= :lower and rq.eventDate <= :upper order by rq.sendingSite";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setTimestamp("lower", lower);
        query.setTimestamp("upper", upper);

        List<ReportExternalImport> reports = query.list();

        closeSession();

        return reports;
    } catch (HibernateException e) {
        handleException(e, "getReportsInDateRangeSorted");
    }

    return null;
}

From source file:us.mn.state.health.lims.dataexchange.aggregatereporting.daoimpl.ReportExternalImportDAOImpl.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
@Override//from   w w w .  j  a v a2s  .c o  m
public List<ReportExternalImport> getReportsInDateRangeSortedForSite(Timestamp lower, Timestamp upper,
        String site) throws LIMSRuntimeException {
    String sql = "from ReportExternalImport rq where rq.eventDate >= :lower and rq.eventDate <= :upper and rq.sendingSite = :site order by rq.sendingSite";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setTimestamp("lower", lower);
        query.setTimestamp("upper", upper);
        query.setString("site", site);

        List<ReportExternalImport> reports = query.list();

        closeSession();

        return reports;
    } catch (HibernateException e) {
        handleException(e, "getReportsInDateRangeSortedForSite");
    }

    return null;
}