Example usage for org.hibernate.criterion Restrictions gt

List of usage examples for org.hibernate.criterion Restrictions gt

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions gt.

Prototype

public static SimpleExpression gt(String propertyName, Object value) 

Source Link

Document

Apply a "greater than" constraint to the named property

Usage

From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.SubmissionDAO.java

License:Open Source License

@Override
public Submission getUngradedSubmission(Task task, int lastSubmissionID, Group group) {
    if (group == null) {
        return (Submission) getSession().createCriteria(Submission.class, "sub")
                .add(Restrictions.gt("submissionid", lastSubmissionID)).add(Restrictions.eq("task", task))
                .createCriteria("submitters").add(Restrictions.isNull("group"))
                .add(Restrictions.isNull("sub.points")).addOrder(Order.asc("group"))
                .addOrder(Order.asc("sub.submissionid")).setMaxResults(1).uniqueResult();
    } else {//  w  ww.j  av  a 2 s .  co m
        return (Submission) getSession().createCriteria(Submission.class, "sub")
                .add(Restrictions.gt("submissionid", lastSubmissionID)).add(Restrictions.eq("task", task))
                .createCriteria("submitters").add(Restrictions.eq("group", group))
                .add(Restrictions.isNull("sub.points")).addOrder(Order.asc("group"))
                .addOrder(Order.asc("sub.submissionid")).setMaxResults(1).uniqueResult();
    }
}

From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.TestDAO.java

License:Open Source License

@Override
public List<Test> getStudentTests(Task task) {
    return getSession().createCriteria(Test.class).add(Restrictions.eq("task", task))
            .add(Restrictions.gt("timesRunnableByStudents", 0)).list();
}

From source file:dk.matzon.echelog.infrastructure.hibernate.HibernateEntryRepository.java

License:Open Source License

@Override
public List<Entry> findAll(Network _network, Channel _channel, Date _start, Date _end) {
    Session currentSession = sessionFactory.getCurrentSession();
    Criteria criteria = currentSession.createCriteria(Entry.class);
    criteria.add(Restrictions.eq("network", _network.getName()));
    criteria.add(Restrictions.eq("channel", _network.getName()));
    criteria.add(Restrictions.gt("date", _start));
    criteria.add(Restrictions.lt("date", _end));
    return criteria.list();
}

From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from w ww  . j a v a 2 s .  c  o m
public List<PupilBooking> getFutureBookingsForTeacher(Teacher teacher) {
    DetachedCriteria c = DetachedCriteria.forClass(PupilBookingImpl.class);

    DateTime end = new DateTime().minusDays(1).withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59)
            .withMillisOfSecond(999);

    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    c.createCriteria("pupil").add(Restrictions.eq("teacher", teacher)).add(Restrictions.eq("active", true))
            .createCriteria("teacher").add(Restrictions.eq("active", true));
    c.add(Restrictions.gt("date", end));
    c.add(Restrictions.eq("active", true));

    c.addOrder(Order.asc("date"));

    c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);

    return getHibernateTemplate().findByCriteria(c);
}

From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*from ww  w  .  j  a v  a  2s  .  co  m*/
public List<PupilBooking> getPaidBookings(Teacher teacher, DateMidnight startDate, DateMidnight endDate) {
    DetachedCriteria c = DetachedCriteria.forClass(PupilBookingImpl.class);

    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    c.createCriteria("pupil").add(Restrictions.eq("teacher", teacher)).add(Restrictions.eq("active", true))
            .createCriteria("teacher").add(Restrictions.eq("active", true));
    c.add(Restrictions.eq("paid", true));
    c.add(Restrictions.eq("active", true));

    if (startDate != null && endDate != null) {
        c.add(Restrictions.between("date", startDate.toDateTime(), endDate.toDateTime()));
    } else if (startDate != null) {
        c.add(Restrictions.gt("date", startDate.toDateTime()));
    } else if (endDate != null) {
        c.add(Restrictions.lt("date", endDate.toDateTime()));
    }

    c.addOrder(Order.asc("date"));

    return getHibernateTemplate().findByCriteria(c);
}

From source file:dk.teachus.backend.dao.hibernate.HibernateBookingDAO.java

License:Apache License

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from   ww  w  . j  a va  2 s.c o m
public List<PupilBooking> getUnPaidBookings(Teacher teacher, DateMidnight startDate, DateMidnight endDate) {
    DetachedCriteria c = DetachedCriteria.forClass(PupilBookingImpl.class);

    c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL));
    c.createCriteria("pupil").add(Restrictions.eq("teacher", teacher)).add(Restrictions.eq("active", true))
            .createCriteria("teacher").add(Restrictions.eq("active", true));
    c.add(Restrictions.eq("paid", false));
    c.add(Restrictions.eq("active", true));

    if (startDate != null && endDate != null) {
        c.add(Restrictions.between("date", startDate.toDateTime(), endDate.toDateTime()));
    } else if (startDate != null) {
        c.add(Restrictions.gt("date", startDate.toDateTime()));
    } else if (endDate != null) {
        c.add(Restrictions.lt("date", endDate.toDateTime()));
    }

    c.addOrder(Order.asc("date"));

    return getHibernateTemplate().findByCriteria(c);
}

From source file:edu.depaul.armada.dao.ContainerLogDaoHibernate.java

License:Open Source License

/**
 * Returns a List<Metric> from all of the containers with a specified ID, within a
 * a particular amount of time, and with an average of a specified field.
 * @param containerId long/*from  ww w.jav  a  2s. c  o m*/
 * @param periodCount int
 * @param fieldToAverage String
 * @return List<Metric>
 */
@Override
public List<Metric> findWithContainerIdAndPeriod(long containerId, int periodCount, String fieldToAverage) {
    List<Metric> metrics = new ArrayList<Metric>(periodCount);
    Calendar cal = Calendar.getInstance();
    for (int i = 0; i < periodCount; i++) {
        Date end = cal.getTime();
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        cal.add(Calendar.HOUR_OF_DAY, -1);
        Date start = cal.getTime();

        Criteria criteria = newCriteria();
        criteria.createAlias("container", "container");
        criteria.add(Restrictions.eq("container.id", containerId));
        criteria.add(Restrictions.le("timestamp", end));
        criteria.add(Restrictions.gt("timestamp", start)); // we don't want overlap here
        criteria.setProjection(Projections.avg(fieldToAverage));
        Object result = criteria.uniqueResult();
        int count = (result == null) ? 0 : ((Double) result).intValue();
        Metric temp = new Metric();
        temp.setHour(hour);
        temp.setValue(count);
        metrics.add(temp);
    }
    Collections.reverse(metrics); // we want the current time to be the last hour
    return metrics;
}

From source file:edu.depaul.armada.dao.ContainerLogDaoHibernate.java

License:Open Source License

/**
 * Returns a List<Metric> from all of the containers with state fields greater-than
 * or equal to certain user defined parameters.
 * @param memThreshold long//from w  w  w . j a  v  a  2 s. com
 * @param cpuThreshold long
 * @param diskThreshold long
 * @param periodCountInHours int
 * @return List<Metric>
 */
@Override
public List<Metric> getStateCounts(long memThreshold, long cpuThreshold, long diskThreshold,
        int periodCountInHours) {
    List<Metric> metrics = new ArrayList<Metric>(periodCountInHours);
    Calendar cal = Calendar.getInstance();
    for (int i = 0; i < periodCountInHours; i++) {
        Date end = cal.getTime();
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        cal.add(Calendar.HOUR_OF_DAY, -1);
        Date start = cal.getTime();

        Criteria criteria = newCriteria();
        criteria.add(Restrictions.le("timestamp", end));
        criteria.add(Restrictions.gt("timestamp", start)); // we don't want overlap here
        criteria.add(Restrictions.disjunction().add(Restrictions.ge("cpuUsed", cpuThreshold))
                .add(Restrictions.ge("memUsed", memThreshold)).add(Restrictions.ge("diskUsed", diskThreshold)));
        criteria.setProjection(Projections.countDistinct("container"));
        int count = ((Long) criteria.uniqueResult()).intValue();
        Metric temp = new Metric();
        temp.setHour(hour);
        temp.setValue(count);
        metrics.add(temp);
    }
    Collections.reverse(metrics); // we want the current time to be the last hour
    return metrics;
}

From source file:edu.depaul.armada.dao.ContainerLogDaoHibernate.java

License:Open Source License

/**
 * Returns a List<Metric> from all of the containers with data within a specified
 * amount of time./*from   ww w  . jav a 2  s  . c o  m*/
 * @param periodInHours int
 * @return List<Metric>
 */
@Override
public List<Metric> getContainerCounts(int periodInHours) {
    List<Metric> metrics = new ArrayList<Metric>(periodInHours);
    Calendar cal = Calendar.getInstance();
    for (int i = 0; i < periodInHours; i++) {
        Date end = cal.getTime();
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        cal.add(Calendar.HOUR_OF_DAY, -1);
        Date start = cal.getTime();

        Criteria criteria = newCriteria();
        criteria.add(Restrictions.le("timestamp", end));
        criteria.add(Restrictions.gt("timestamp", start)); // we don't want overlap here
        criteria.setProjection(Projections.countDistinct("container"));
        int count = ((Long) criteria.uniqueResult()).intValue();
        Metric temp = new Metric();
        temp.setHour(hour);
        temp.setValue(count);
        metrics.add(temp);
    }
    Collections.reverse(metrics); // we want the current time to be the last hour
    return metrics;
}

From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper.java

License:Open Source License

private Criteria getExplorationGreaterThanTL(Float f) {
    if (f == null)
        return null;
    Criteria crit = HSess.get().createCriteria(User.class).add(Restrictions.eq("gameMaster", false))
            .add(Restrictions.gt("basicScore", f)).addOrder(Order.desc("basicScore"));
    return crit;//from  w  w  w  .ja  va2 s  .c  o  m
}