List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:storybook.model.dao.ChapterDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Date> findDates(Chapter chapter) { Query query = session.createQuery("select s.sceneTs from Scene as s" + " join s.chapter as ch" + " where s.chapter=:chapter" + " order by ch.chapterno, s.sceneno"); query.setEntity("chapter", chapter); List<Timestamp> tsList = (List<Timestamp>) query.list(); List<Date> dates = new ArrayList<Date>(); for (Timestamp ts : tsList) { Date date = DateUtil.getZeroTimeDate(ts); dates.add(date);//from w w w .java2 s . c o m } dates = LangUtil.removeNullAndDuplicates(dates); Collections.sort(dates, new DateComparator()); return dates; }
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);//w w w. j ava2s. 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> findByPart(Part part) { Query query = session.createQuery("select scene from Scene as scene" + " inner join scene.chapter as chapter" + " inner join chapter.part as part" + " where chapter.part=:part" + " order by part.number, chapter.chapterno, scene.sceneno"); query.setEntity("part", part); List<Scene> ret = query.list(); return ret;/*from w ww .ja va 2 s . com*/ }
From source file:storybook.model.dao.SceneDAOImpl.java
License:Open Source License
public long countByPerson(Person person) { Query query = session .createQuery("select count(s) from Scene as s" + " join s.persons as p" + " where p=:person"); query.setEntity("person", person); return (Long) query.uniqueResult(); }
From source file:storybook.model.dao.SceneDAOImpl.java
License:Open Source License
public long countByLocation(Location location) { Query query = session .createQuery("select count(s) from Scene as s" + " join s.locations as l" + " where l=:location"); query.setEntity("location", location); return (Long) query.uniqueResult(); }
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 va 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.dao.StrandDAOImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Scene> findScenes(Strand strand) { Query query = session.createQuery("select s from Scene as s left join s.chapter as ch" + " where s.strand=:strand" + " order by ch.chapterno, s.sceneno"); query.setEntity("strand", strand); List<Scene> ret = (List<Scene>) query.list(); return ret;//from w w w . java 2s .co m }
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 a v a 2 s . com*/ // 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; }