List of usage examples for org.hibernate.criterion DetachedCriteria setResultTransformer
public DetachedCriteria setResultTransformer(ResultTransformer resultTransformer)
From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//from w ww .j a va2 s . c o m public Bookings getBookings(Teacher teacher, DateMidnight fromDate, DateMidnight toDate) { DetachedCriteria c = DetachedCriteria.forClass(BookingImpl.class); DateTime start = fromDate.toDateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0) .withMillisOfSecond(0); DateTime end = toDate.toDateTime().withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59) .withMillisOfSecond(999); c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL)); c.createCriteria("teacher").add(Restrictions.eq("active", true)); c.add(Restrictions.eq("teacher", teacher)); c.add(Restrictions.between("date", start, end)); c.add(Restrictions.eq("active", true)); c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<Booking> bookings = getHibernateTemplate().findByCriteria(c); List<Booking> filteredBookings = filterBookings(bookings); return new BookingsImpl(filteredBookings); }
From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//from w w w . j a v a 2 s . c om public Bookings getBookings(Pupil pupil, DateMidnight fromDate, DateMidnight toDate) { DetachedCriteria c = DetachedCriteria.forClass(BookingImpl.class); DateTime start = new DateTime(fromDate).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0) .withMillisOfSecond(0); DateTime end = new DateTime(toDate).withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59) .withMillisOfSecond(999); c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL)); c.createCriteria("teacher").add(Restrictions.eq("active", true)); c.add(Restrictions.eq("pupil", pupil)); c.add(Restrictions.between("date", start, end)); c.add(Restrictions.eq("active", true)); c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<Booking> bookings = getHibernateTemplate().findByCriteria(c); List<Booking> filteredBookings = filterBookings(bookings); return new BookingsImpl(filteredBookings); }
From source file:dk.teachus.backend.dao.hibernate.HibernatePeriodDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//from www . j a v a 2s . c o m public Periods getPeriods(Teacher teacher, boolean onlyFinal) { DetachedCriteria c = DetachedCriteria.forClass(PeriodImpl.class); c.add(Restrictions.eq("teacher", teacher)); c.createCriteria("teacher").add(Restrictions.eq("active", true)); if (onlyFinal) { c.add(Restrictions.eq("status", Status.FINAL)); } else { c.add(Restrictions.ne("status", Status.DELETED)); } c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<Period> result = getHibernateTemplate().findByCriteria(c); Periods periods = new PeriodsImpl(); periods.setPeriods(result); return periods; }
From source file:dk.teachus.backend.dao.hibernate.HibernatePersonDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//from ww w. ja v a2s. c o m public Person authenticatePerson(String username, String password) { DetachedCriteria c = DetachedCriteria.forClass(PersonImpl.class); c.add(Restrictions.eq("username", username)); c.add(Restrictions.eq("password", password)); c.add(Restrictions.eq("active", true)); c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<Person> persons = getHibernateTemplate().findByCriteria(c); Person person = null; if (persons.size() == 1) { person = persons.get(0); // Pupils, which are associated with a teacher, which is inactivated should not be allowed to log in if (person instanceof Pupil) { Pupil pupil = (Pupil) person; if (pupil.getTeacher().isActive() == false) { person = null; } } } return person; }
From source file:dk.teachus.backend.dao.hibernate.HibernatePersonDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//from w ww. ja v a2 s . c o m public <P extends Person> List<P> getPersons(Class<P> personClass) { Class<? extends Person> clazz = null; if (Admin.class.equals(personClass)) { clazz = AdminImpl.class; } else if (Teacher.class.equals(personClass)) { clazz = TeacherImpl.class; } else if (Pupil.class.equals(personClass)) { clazz = PupilImpl.class; } DetachedCriteria c = DetachedCriteria.forClass(clazz); c.addOrder(Order.asc("name")); if (Pupil.class.equals(personClass)) { c.add(Restrictions.eq("active", true)); } c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); return getHibernateTemplate().findByCriteria(c); }
From source file:dk.teachus.backend.dao.hibernate.HibernatePersonDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)//w ww. j a v a2s. c o m public List<Pupil> getPupils(Teacher teacher) { DetachedCriteria c = DetachedCriteria.forClass(PupilImpl.class); c.add(Restrictions.eq("active", true)); c.createCriteria("teacher").add(Restrictions.eq("active", true)); c.add(Restrictions.eq("teacher", teacher)); c.addOrder(Order.asc("name")); c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); return getHibernateTemplate().findByCriteria(c); }
From source file:dk.teachus.backend.dao.hibernate.HibernateStatisticsDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)/*from w w w . j a v a2s.c o m*/ public List<PupilBooking> getAllBookings(DateMidnight fromDate, DateMidnight toDate) { DetachedCriteria c = DetachedCriteria.forClass(PupilBookingImpl.class); c.createCriteria("pupil").add(Restrictions.eq("active", true)); c.createCriteria("teacher").add(Restrictions.eq("active", true)); c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL)); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.and(Restrictions.ge("createDate", fromDate.toDateTime()), Restrictions.le("createDate", toDate.toDateTime()))); disjunction.add(Restrictions.and(Restrictions.ge("updateDate", fromDate.toDateTime()), Restrictions.le("updateDate", toDate.toDateTime()))); c.add(disjunction); c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<PupilBooking> bookings = getHibernateTemplate().findByCriteria(c); return bookings; }
From source file:flexmud.db.TestPersistContextCommand.java
License:Open Source License
@Test public void testFetch() { List<ContextCommand> contextCommands; Set<ContextCommandAlias> aliases; Set<ContextCommandParameter> parameters; DetachedCriteria criteria = DetachedCriteria.forClass(ContextCommand.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); contextCommands = (List<ContextCommand>) HibernateUtil.fetch(criteria); Assert.assertNotNull("List of context commands should not be null", contextCommands); Assert.assertEquals("Database should only contain one context command", 1, contextCommands.size()); aliases = contextCommands.get(0).getAliases(); Assert.assertEquals("Context Command Aliases should have been eagerly loaded", 2, aliases.size()); parameters = contextCommands.get(0).getParameters(); Assert.assertEquals("Context Command Parameter should have been eagerly loaded", 1, parameters.size()); }
From source file:flexmud.db.TestPersistContextCommand.java
License:Open Source License
private DetachedCriteria createCriteria(Class clazz) { DetachedCriteria criteria = DetachedCriteria.forClass(clazz); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return criteria; }
From source file:fr.gael.dhus.service.UserService.java
License:Open Source License
/** * Counts corresponding users at the given criteria. * * @param criteria criteria contains filter of required collection. * @return number of corresponding users. */// ww w. java2s . co m @Transactional(readOnly = true) public int countUsers(DetachedCriteria criteria) { if (criteria == null) { criteria = DetachedCriteria.forClass(User.class); } criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setProjection(Projections.rowCount()); return userDao.count(criteria); }