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:org.ikasan.wiretap.dao.HibernateWiretapDao.java

License:BSD License

/**
 * Perform a paged search for <code>WiretapFlowEvent</code>s
 * //  www. java2s.  co m
 * @param pageNo - The page number to retrieve
 * @param pageSize - The size of the page
 * @param orderBy - order by field
 * @param orderAscending - ascending flag
 * @param moduleNames - The list of module names
 * @param moduleFlow - The name of Flow internal to the Module
 * @param componentName - The component name
 * @param eventId - The event id
 * @param payloadId - The payload id
 * @param fromDate - The from date
 * @param untilDate - The to date
 * @param payloadContent - The payload content
 * 
 * @return PagedSearchResult
 */
@SuppressWarnings("unchecked")
public PagedSearchResult<WiretapEvent> findWiretapEvents(final int pageNo, final int pageSize,
        final String orderBy, final boolean orderAscending, final Set<String> moduleNames,
        final String moduleFlow, final String componentName, final String eventId, final String payloadId,
        final Date fromDate, final Date untilDate, final String payloadContent) {
    return (PagedSearchResult) getHibernateTemplate().execute(new HibernateCallback<Object>() {
        public Object doInHibernate(Session session) throws HibernateException {
            Criteria dataCriteria = getCriteria(session);
            dataCriteria.setMaxResults(pageSize);
            int firstResult = pageNo * pageSize;
            dataCriteria.setFirstResult(firstResult);
            if (orderBy != null) {
                if (orderAscending) {
                    dataCriteria.addOrder(Order.asc(orderBy));
                } else {
                    dataCriteria.addOrder(Order.desc(orderBy));
                }
            }
            List<WiretapEvent> wiretapResults = dataCriteria.list();

            Criteria metaDataCriteria = getCriteria(session);
            metaDataCriteria.setProjection(Projections.rowCount());
            Long rowCount = new Long(0);
            List<Long> rowCountList = metaDataCriteria.list();
            if (!rowCountList.isEmpty()) {
                rowCount = rowCountList.get(0);
            }

            return new ArrayListPagedSearchResult<WiretapEvent>(wiretapResults, firstResult, rowCount);
        }

        /**
         * Create a criteria instance for each invocation of data or metadata queries.
         * @param session
         * @return
         */
        private Criteria getCriteria(Session session) {
            Criteria criteria = session.createCriteria(WiretapEvent.class);

            if (restrictionExists(moduleNames)) {
                criteria.add(Restrictions.in("moduleName", moduleNames));
            }
            if (restrictionExists(moduleFlow)) {
                criteria.add(Restrictions.eq("flowName", moduleFlow));
            }
            if (restrictionExists(componentName)) {
                criteria.add(Restrictions.eq("componentName", componentName));
            }
            if (restrictionExists(eventId)) {
                criteria.add(Restrictions.eq("eventId", eventId));
            }
            //                if (restrictionExists(payloadId))
            //                {
            //                    criteria.add(Restrictions.eq("payloadId", payloadId));
            //                }
            if (restrictionExists(payloadContent)) {
                criteria.add(Restrictions.like("event", payloadContent, MatchMode.ANYWHERE));
            }
            if (restrictionExists(fromDate)) {
                criteria.add(Restrictions.gt("timestamp", fromDate.getTime()));
            }
            if (restrictionExists(untilDate)) {
                criteria.add(Restrictions.lt("timestamp", untilDate.getTime()));
            }

            return criteria;
        }
    });
}

From source file:org.ikasan.wiretap.dao.HibernateWiretapDao.java

License:BSD License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override//from ww w  .j  ava2 s .  c  o  m
public PagedSearchResult<WiretapEvent> findWiretapEvents(final int pageNo, final int pageSize,
        final String orderBy, final boolean orderAscending, final Set<String> moduleNames,
        final Set<String> moduleFlows, final Set<String> componentNames, final String eventId,
        final String payloadId, final Date fromDate, final Date untilDate, final String payloadContent) {
    return (PagedSearchResult) getHibernateTemplate().execute(new HibernateCallback<Object>() {
        public Object doInHibernate(Session session) throws HibernateException {
            Criteria dataCriteria = getCriteria(session);
            dataCriteria.setMaxResults(pageSize);
            int firstResult = pageNo * pageSize;
            dataCriteria.setFirstResult(firstResult);
            if (orderBy != null) {
                if (orderAscending) {
                    dataCriteria.addOrder(Order.asc(orderBy));
                } else {
                    dataCriteria.addOrder(Order.desc(orderBy));
                }
            }
            List<WiretapEvent> wiretapResults = dataCriteria.list();

            Criteria metaDataCriteria = getCriteria(session);
            metaDataCriteria.setProjection(Projections.rowCount());
            Long rowCount = new Long(0);
            List<Long> rowCountList = metaDataCriteria.list();
            if (!rowCountList.isEmpty()) {
                rowCount = rowCountList.get(0);
            }

            return new ArrayListPagedSearchResult<WiretapEvent>(wiretapResults, firstResult, rowCount);
        }

        /**
         * Create a criteria instance for each invocation of data or metadata queries.
         * @param session
         * @return
         */
        private Criteria getCriteria(Session session) {
            Criteria criteria = session.createCriteria(WiretapEvent.class);

            if (restrictionExists(moduleNames)) {
                criteria.add(Restrictions.in("moduleName", moduleNames));
            }
            if (restrictionExists(moduleFlows)) {
                criteria.add(Restrictions.in("flowName", moduleFlows));
            }
            if (restrictionExists(componentNames)) {
                criteria.add(Restrictions.in("componentName", componentNames));
            }
            if (restrictionExists(eventId)) {
                criteria.add(Restrictions.eq("eventId", eventId));
            }
            if (restrictionExists(payloadContent)) {
                criteria.add(Restrictions.like("event", payloadContent, MatchMode.ANYWHERE));
            }
            if (restrictionExists(fromDate)) {
                criteria.add(Restrictions.gt("timestamp", fromDate.getTime()));
            }
            if (restrictionExists(untilDate)) {
                criteria.add(Restrictions.lt("timestamp", untilDate.getTime()));
            }

            return criteria;
        }
    });
}

From source file:org.infoscoop.dao.SessionDAO.java

License:Open Source License

/**
 * Return the session counting in the designated days.
 * @param period//from www. j a v  a2 s. co m
 * @return
 */
public int getActiveSessionsCount(final int period) {
    return (Integer) super.getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(org.hibernate.Session session) throws HibernateException, SQLException {

            Criteria crit = session.createCriteria(Session.class);

            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.DATE, period);

            Date startDate = cal.getTime();
            Date endDate = new Date();

            crit.add(Restrictions.gt("Logindatetime", startDate));
            crit.add(Restrictions.lt("Logindatetime", endDate));
            Integer rowCount = (Integer) crit.setProjection(Projections.rowCount()).uniqueResult();

            return rowCount;
        }

    });
}

From source file:org.iternine.jeppetto.dao.hibernate.HibernateQueryModelDAO.java

License:Apache License

@Override
public Condition buildCondition(String conditionField, ConditionType conditionType, Iterator argsIterator) {
    Condition condition = new Condition();

    condition.setField(conditionField);//from   w  ww . j  av  a  2 s  . c  o  m

    switch (conditionType) {
    case Between:
        condition.setConstraint(Restrictions.between(conditionField, argsIterator.next(), argsIterator.next()));
        break;

    case Equal:
        condition.setConstraint(Restrictions.eq(conditionField, argsIterator.next()));
        break;

    case GreaterThan:
        condition.setConstraint(Restrictions.gt(conditionField, argsIterator.next()));
        break;

    case GreaterThanEqual:
        condition.setConstraint(Restrictions.ge(conditionField, argsIterator.next()));
        break;

    case IsNotNull:
        condition.setConstraint(Restrictions.isNotNull(conditionField));
        break;

    case IsNull:
        condition.setConstraint(Restrictions.isNull(conditionField));
        break;

    case LessThan:
        condition.setConstraint(Restrictions.lt(conditionField, argsIterator.next()));
        break;

    case LessThanEqual:
        condition.setConstraint(Restrictions.le(conditionField, argsIterator.next()));
        break;

    case NotEqual:
        condition.setConstraint(Restrictions.ne(conditionField, argsIterator.next()));
        break;

    case NotWithin:
        condition.setConstraint(
                Restrictions.not(Restrictions.in(conditionField, (Collection) argsIterator.next())));
        break;

    case Within:
        condition.setConstraint(Restrictions.in(conditionField, (Collection) argsIterator.next()));
        break;
    }

    return condition;
}

From source file:org.jasig.ssp.dao.external.RegistrationStatusByTermDao.java

License:Apache License

public RegistrationStatusByTerm getForTerm(final String schoolId, final String termCode) {
    final Criteria query = createCriteria();
    query.add(Restrictions.eq("schoolId", schoolId));
    query.add(Restrictions.eq("termCode", termCode));
    query.add(Restrictions.gt("registeredCourseCount", 0));
    return (RegistrationStatusByTerm) query.uniqueResult();
}

From source file:org.jasig.ssp.dao.external.RegistrationStatusByTermDao.java

License:Apache License

public PagingWrapper<RegistrationStatusByTerm> getAllForPerson(final Person person,
        final SortingAndPaging sAndP) {
    final Criteria query = createCriteria();
    query.add(Restrictions.eq("schoolId", person.getSchoolId()));
    query.add(Restrictions.gt("registeredCourseCount", 0));

    return processCriteriaWithSortingAndPaging(query, sAndP, false);
}

From source file:org.jasig.ssp.dao.external.RegistrationStatusByTermDao.java

License:Apache License

public PagingWrapper<RegistrationStatusByTerm> getAllForPerson(final String schoolId,
        final SortingAndPaging sAndP) {
    final Criteria query = createCriteria();
    query.add(Restrictions.eq("schoolId", schoolId));
    query.add(Restrictions.gt("registeredCourseCount", 0));

    return processCriteriaWithSortingAndPaging(query, sAndP, false);
}

From source file:org.jasig.ssp.dao.PersonSearchDao.java

License:Apache License

public List<PersonSearchResult2> directoryPersonSearch(PersonSearchRequest personSearchRequest) {
    Criteria query = sessionFactory.getCurrentSession().createCriteria(DirectoryPerson.class);
    if (personSearchRequest.getBirthDate() != null) {
        query.add(Restrictions.eq("birthDate", personSearchRequest.getBirthDate()));
    }// ww  w.  java 2s.  c om

    if (personSearchRequest.getCurrentlyRegistered() != null && personSearchRequest.getCurrentlyRegistered()) {
        query.add(Restrictions.gt("currentRegistrationStatus", 0));
    }

    if (StringUtils.isNotBlank(personSearchRequest.getDeclaredMajor())) {
        query.add(Restrictions.eq("declaredMajor", personSearchRequest.getDeclaredMajor()));
    }

    if (StringUtils.isNotBlank(personSearchRequest.getSchoolId())) {
        query.add(Restrictions.eq("schoolId", personSearchRequest.getSchoolId() + "%"));
    }

    if (StringUtils.isNotBlank(personSearchRequest.getLastName())) {
        query.add(Restrictions.like("lastName", personSearchRequest.getLastName() + "%"));
    }

    if (StringUtils.isNotBlank(personSearchRequest.getFirstName())) {
        query.add(Restrictions.like("firstName", personSearchRequest.getFirstName() + "%"));
    }

    if (personSearchRequest.getCoach() != null) {
        query.add(Restrictions.like("coach", personSearchRequest.getCoach()));
    }

    if (personSearchRequest.getProgramStatus() != null) {
        query.add(Restrictions.like("programStatus", personSearchRequest.getProgramStatus()));
    }

    if (StringUtils.isNotBlank(personSearchRequest.getPlanStatus())) {
        query.add(Restrictions.like("mapStatus", personSearchRequest.getPlanStatus()));
    }

    return null;
}

From source file:org.jasig.ssp.dao.TaskDao.java

License:Apache License

@SuppressWarnings(UNCHECKED)
public List<Task> getAllWhichNeedRemindersSent(final SortingAndPaging sAndP) {

    final Criteria criteria = createCriteria(sAndP);
    criteria.add(Restrictions.isNull("completedDate"));
    criteria.add(Restrictions.isNull("reminderSentDate"));
    criteria.add(Restrictions.isNotNull("dueDate"));
    criteria.add(Restrictions.gt("dueDate", DateTimeUtils.midnight()));
    return criteria.list();
}

From source file:org.javamexico.dao.hib3.ForumDAO.java

License:Open Source License

public List<Foro> getForosByUser(Usuario user, boolean published) {
    Session sess = sfact.getCurrentSession();
    Criteria crit = sess.createCriteria(Foro.class).add(Restrictions.eq("autor", user))
            .addOrder(Order.desc("fecha"));
    if (published) {
        crit = crit.add(Restrictions.gt("status", 0));
    }// w  w  w  .j a va2  s . co m
    @SuppressWarnings("unchecked")
    List<Foro> qus = crit.list();
    return qus;
}