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:ca.myewb.controllers.common.EventList.java

License:Open Source License

public Collection<EventModel> listVisibleEventsBetweenDates(Date start, Date end, GroupChapterModel chapter)
        throws HibernateException {
    Criteria criteria = hibernateSession.createCriteria(EventModel.class);

    LogicalExpression singleDayEvents = Restrictions.and(Restrictions.ge("startDate", start),
            Restrictions.le("endDate", end));
    LogicalExpression endsToday = Restrictions.and(Restrictions.lt("startDate", start),
            Restrictions.and(Restrictions.ge("endDate", start), Restrictions.le("endDate", end)));
    LogicalExpression startsToday = Restrictions.and(
            Restrictions.and(Restrictions.ge("startDate", start), Restrictions.le("startDate", end)),
            Restrictions.gt("endDate", end));
    LogicalExpression ongoing = Restrictions.and(Restrictions.lt("startDate", start),
            Restrictions.gt("endDate", end));

    criteria.add(Restrictions.or(singleDayEvents,
            Restrictions.or(endsToday, Restrictions.or(startsToday, ongoing))));

    if (chapter == null) {
        if (!currentUser.isAdmin()) {
            criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true)));
        } else {/* w w w.ja  va2 s .  com*/
            List<GroupModel> adminGroups = Helpers.getNationalRepLists(true, true);
            adminGroups.add(Helpers.getGroup("Exec"));
            adminGroups.add(Helpers.getGroup("ProChaptersExec"));

            criteria.add(Restrictions.in("group", adminGroups));
        }
    } else {
        criteria.add(Restrictions.in("group", Permissions.visibleGroupsInChapter(currentUser, chapter)));
    }

    criteria.addOrder(Order.asc("startDate"));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    return new SafeHibList<EventModel>(criteria).list();
}

From source file:ca.myewb.controllers.common.PostList.java

License:Open Source License

private void addBooleanFilters(boolean onlyNew, boolean findReplies, boolean onlyFlagged, boolean onlyFeatured,
        boolean findEmails, boolean sortByLastReply, Criteria criteria) {

    if (!findReplies) {
        criteria.add(Restrictions.isNull("parent"));
    }/*from ww  w. j a v a  2s  . c  o m*/

    if (!findEmails) {
        criteria.add(Restrictions.eq("emailed", false));
    }

    if (sortByLastReply) {
        criteria.addOrder(Order.desc("lastReply"));
    } else if (onlyNew) {
        SimpleExpression mainDate = Restrictions.gt("date", currentUser.getLastLogin());
        criteria.add(mainDate);
        criteria.addOrder(Order.asc("date"));
    } else {
        criteria.addOrder(Order.desc("date"));
    }

    if (onlyFlagged) {
        Set<PostModel> flaggedPosts2 = currentUser.getFlaggedPosts();
        if (flaggedPosts2.isEmpty()) {
            criteria.add(Restrictions.eq("id", 0));
        } else {
            Vector<Integer> flaggedIDs = new Vector<Integer>();
            for (PostModel p : flaggedPosts2) {
                flaggedIDs.add(p.getId());
            }

            Criterion flaggedSelf = Restrictions.in("id", flaggedIDs);
            Criterion flaggedParent = Restrictions.in("parent", flaggedPosts2);
            criteria.add(Restrictions.or(flaggedSelf, flaggedParent));
        }
    }

    if (onlyFeatured) {
        criteria.add(Restrictions.eq("featured", true));
    }

}

From source file:ca.myewb.controllers.common.WhiteboardList.java

License:Open Source License

public List<WhiteboardModel> listPaginatedVisibleWhiteboards(int startPage, int eventsPerPage)
        throws HibernateException {
    Criteria criteria = hibernateSession.createCriteria(WhiteboardModel.class);

    if (!currentUser.isAdmin() || !currentUser.getAdminToggle()) {
        criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true)));
    }/*from w w w. j  a v a  2s .c  o m*/
    criteria.add(Restrictions.ne("numEdits", 0));
    criteria.add(Restrictions.gt("lastEditDate", currentUser.getLastLogin()));
    criteria.addOrder(Order.desc("lastEditDate"));
    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    addPagination(startPage, eventsPerPage, criteria);

    return getUniqueWhiteboardList(criteria);
}

From source file:ca.myewb.controllers.common.WhiteboardList.java

License:Open Source License

public int visibleWhiteboardCount() throws HibernateException {
    Criteria criteria = hibernateSession.createCriteria(WhiteboardModel.class);

    if (!currentUser.isAdmin() || !currentUser.getAdminToggle()) {
        criteria.add(Restrictions.in("group", Permissions.visibleGroups(currentUser, true)));
    }//from  w ww  .jav a  2 s.c o  m
    criteria.add(Restrictions.ne("numEdits", 0));
    criteria.add(Restrictions.gt("lastEditDate", currentUser.getLastLogin()));

    criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);

    return getUniqueWhiteboardCount(criteria);
}

From source file:ca.myewb.model.ApplicationSessionModel.java

License:Open Source License

public static List<ApplicationSessionModel> getOpenApplicationSessions() {
    SafeHibList<ApplicationSessionModel> openSessions = new SafeHibList<ApplicationSessionModel>(HibernateUtil
            .currentSession().createCriteria(ApplicationSessionModel.class)
            .add(Restrictions.le("openDate", new Date())).add(Restrictions.gt("closeDate", new Date())));
    return openSessions.list();
}

From source file:ca.myewb.model.ApplicationSessionModel.java

License:Open Source License

public static List<ApplicationSessionModel> getFutureApplicationSessions() {
    SafeHibList<ApplicationSessionModel> openSessions = new SafeHibList<ApplicationSessionModel>(
            HibernateUtil.currentSession().createCriteria(ApplicationSessionModel.class)
                    .add(Restrictions.gt("openDate", new Date())));
    return openSessions.list();
}

From source file:ca.myewb.model.ApplicationSessionModel.java

License:Open Source License

public static List<ApplicationSessionModel> getRecentlyClosedSessions(int pastWeeks) {
    Calendar cal = GregorianCalendar.getInstance();
    cal.add(Calendar.DATE, pastWeeks * -7);

    SafeHibList<ApplicationSessionModel> openSessions = new SafeHibList<ApplicationSessionModel>(HibernateUtil
            .currentSession().createCriteria(ApplicationSessionModel.class)
            .add(Restrictions.gt("closeDate", cal.getTime())).add(Restrictions.le("closeDate", new Date())));
    return openSessions.list();

}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.EventDAO.java

License:Apache License

public List<DeletedDataSet> listDeletedDataSets(Long lastSeenDeletionEventIdOrNull) {
    final DetachedCriteria criteria = DetachedCriteria.forClass(EventPE.class);
    if (lastSeenDeletionEventIdOrNull != null) {
        criteria.add(Restrictions.gt("id", lastSeenDeletionEventIdOrNull));
    }/*  w  w  w  .  ja  v a  2 s. c om*/
    criteria.add(Restrictions.eq("eventType", EventType.DELETION));
    criteria.add(Restrictions.eq("entityType", EntityType.DATASET));
    final List<EventPE> list = cast(getHibernateTemplate().findByCriteria(criteria));
    if (operationLog.isDebugEnabled()) {
        String lastDesc = lastSeenDeletionEventIdOrNull == null ? "all"
                : "id > " + lastSeenDeletionEventIdOrNull;
        operationLog.debug(String.format("%s(%d): data set deletion events(s) have been found.",
                MethodUtils.getCurrentMethod().getName(), lastDesc, list.size()));
    }
    ArrayList<DeletedDataSet> result = new ArrayList<DeletedDataSet>();
    for (EventPE event : list) {
        result.add(new DeletedDataSet(event.getIdentifier(), event.getId()));
    }
    return result;
}

From source file:chat.service.DoChat.java

License:LGPL

/**
 * read chats according to SO' {@link Chat#out} and {@link Chat#in} from
 * {@link Chat#datime}(excluded, or oldest if null), order by {@link Chat#datime} asc
 *///from   w ww  .j  av  a2 s.co  m
@Service
@Transac.Readonly
public List<Chat> read(Chat c) throws Exception {
    Criteria<Chat> t = data.criteria(Chat.class);
    User me = new User().id(sess.me);

    Criterion out = Restrictions.eq("out", me);
    if (c.in != null)
        out = Restrictions.and(out, // chats from me
                Restrictions.eq("in", c.in));
    Criterion in = Restrictions.eq("in", me);
    if (c.out != null)
        in = Restrictions.and(in, // chats to me
                Restrictions.eq("out", c.out));
    t.add(Restrictions.or(out, in));
    if (c.datime != null)
        t.add(Restrictions.gt("datime", c.datime));
    return t.addOrder(Order.asc("datime")).list();
}

From source file:cn.hxh.springside.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,.//from  w  ww . j  a  va  2s. c  om
 */
protected Criterion buildCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    AssertUtils.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    //?MatchTypecriterion
    switch (matchType) {
    case EQ:
        criterion = Restrictions.eq(propertyName, propertyValue);
        break;
    case LIKE:
        criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        break;

    case LE:
        criterion = Restrictions.le(propertyName, propertyValue);
        break;
    case LT:
        criterion = Restrictions.lt(propertyName, propertyValue);
        break;
    case GE:
        criterion = Restrictions.ge(propertyName, propertyValue);
        break;
    case GT:
        criterion = Restrictions.gt(propertyName, propertyValue);
    }
    return criterion;
}