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.LexGrid.LexBIG.caCore.dao.orm.translators.SDKCQLToDetachedCriteria.java

License:Open Source License

private Criterion processAttribute(CQLAttribute att, String parentAlias) {
    String name = parentAlias + "." + att.getName();
    String value = att.getValue();
    Criterion restriction = null;//from w w  w .ja  v  a 2s  .c om

    CQLPredicate attPredicate = att.getPredicate();

    if (attPredicate.equals(CQLPredicate.EQUAL_TO)) {
        restriction = Restrictions.eq(name, value);
    }
    if (attPredicate.equals(CQLPredicate.LIKE)) {
        restriction = Restrictions.like(name, value);
    }
    if (attPredicate.equals(CQLPredicate.GREATER_THAN)) {
        restriction = Restrictions.gt(name, value);
    }
    if (attPredicate.equals(CQLPredicate.GREATER_THAN_EQUAL_TO)) {
        restriction = Restrictions.ge(name, value);
    }
    if (attPredicate.equals(CQLPredicate.LESS_THAN)) {
        restriction = Restrictions.lt(name, value);
    }
    if (attPredicate.equals(CQLPredicate.LESS_THAN_EQUAL_TO)) {
        restriction = Restrictions.le(name, value);
    }
    if (attPredicate.equals(CQLPredicate.IS_NULL)) {
        restriction = Restrictions.isNull(name);
    }
    if (attPredicate.equals(CQLPredicate.IS_NOT_NULL)) {
        restriction = Restrictions.isNotNull(name);
    }
    if (attPredicate.equals(CQLPredicate.NOT_EQUAL_TO)) {
        restriction = Restrictions.ne(name, value);
    }
    return restriction;
}

From source file:org.linagora.linshare.core.repository.hibernate.AnonymousShareEntryRepositoryImpl.java

License:Open Source License

@Override
public List<AnonymousShareEntry> findUpcomingExpiredEntries(Integer date) {
    Calendar calMin = Calendar.getInstance();
    calMin.add(Calendar.DAY_OF_MONTH, date);

    Calendar calMax = Calendar.getInstance();
    calMax.add(Calendar.DAY_OF_MONTH, date + 1);

    return findByCriteria(Restrictions.lt("expirationDate", calMax), Restrictions.gt("expirationDate", calMin));
}

From source file:org.linagora.linshare.core.repository.hibernate.LogEntryRepositoryImpl.java

License:Open Source License

public List<LogEntry> findByDate(String mail, Calendar beginDate, Calendar endDate) {

    DetachedCriteria criteria = DetachedCriteria.forClass(LogEntry.class);

    criteria.add(Restrictions.eq("actorMail", mail));

    if (beginDate != null) {
        criteria.add(Restrictions.gt("actionDate", beginDate));
    }//from   w  w  w  . jav  a  2s .c o m

    if (endDate != null) {
        criteria.add(Restrictions.lt("actionDate", endDate));
    }
    return findBy(criteria);
}

From source file:org.linagora.linshare.core.repository.hibernate.LogEntryRepositoryImpl.java

License:Open Source License

public List<LogEntry> findByCriteria(LogCriteriaBean logCriteria, String domainId) {

    DetachedCriteria criteria = DetachedCriteria.forClass(LogEntry.class);

    if (CollectionUtils.isNotEmpty(logCriteria.getActorMails())) {
        Disjunction or = Restrictions.disjunction();
        for (String mail : logCriteria.getActorMails()) {
            if (StringUtils.isNotBlank(mail))
                or.add(Restrictions.like("actorMail", mail, MatchMode.ANYWHERE));
        }/* w  ww  .  j  av  a2 s. c  o  m*/
        criteria.add(or);
    }

    if (CollectionUtils.isNotEmpty(logCriteria.getTargetMails())) {
        Disjunction or = Restrictions.disjunction();
        for (String mail : logCriteria.getTargetMails()) {
            if (StringUtils.isNotBlank(mail))
                or.add(Restrictions.like("targetMail", mail, MatchMode.ANYWHERE));
        }
        criteria.add(or);
    }

    if (StringUtils.isNotBlank(logCriteria.getActorFirstname())) {
        criteria.add(Restrictions.like("actorFirstname", logCriteria.getActorFirstname(), MatchMode.ANYWHERE)
                .ignoreCase());
    }

    if (StringUtils.isNotBlank(logCriteria.getActorLastname())
            && (logCriteria.getActorLastname().length() > 0)) {
        criteria.add(Restrictions.like("actorLastname", logCriteria.getActorLastname(), MatchMode.ANYWHERE)
                .ignoreCase());
    }

    if (StringUtils.isNotBlank(domainId)) {
        criteria.add(Restrictions.like("actorDomain", domainId));
    } else if (StringUtils.isNotBlank(logCriteria.getActorDomain())) {
        criteria.add(Restrictions.like("actorDomain", logCriteria.getActorDomain()));
    }

    if (StringUtils.isNotBlank(logCriteria.getTargetFirstname())) {
        criteria.add(Restrictions.like("targetFirstname", logCriteria.getTargetFirstname(), MatchMode.ANYWHERE)
                .ignoreCase());
    }

    if (StringUtils.isNotBlank(logCriteria.getTargetLastname())) {
        criteria.add(Restrictions.like("targetLastname", logCriteria.getTargetLastname(), MatchMode.ANYWHERE)
                .ignoreCase());
    }

    if (StringUtils.isNotBlank(logCriteria.getTargetDomain())) {
        criteria.add(Restrictions.like("targetDomain", logCriteria.getTargetDomain()));
    }

    if (CollectionUtils.isNotEmpty(logCriteria.getLogActions())) {
        criteria.add(Restrictions.in("logAction", logCriteria.getLogActions()));
    }
    if (logCriteria.getBeforeDate() != null) {
        criteria.add(Restrictions.gt("actionDate", logCriteria.getBeforeDate()));
    }

    if (logCriteria.getAfterDate() != null) {
        criteria.add(Restrictions.lt("actionDate", logCriteria.getAfterDate()));
    }

    if (StringUtils.isNotBlank(logCriteria.getFileName())) {

        if (logCriteria.getFileNameMatchMode().equals(CriterionMatchMode.ANYWHERE)) {
            criteria.add(
                    Restrictions.like("fileName", logCriteria.getFileName(), MatchMode.ANYWHERE).ignoreCase());
        } else {
            criteria.add(
                    Restrictions.like("fileName", logCriteria.getFileName(), MatchMode.ANYWHERE).ignoreCase());
        }
    }

    if (StringUtils.isNotBlank(logCriteria.getFileExtension())) {
        criteria.add(Restrictions.like("fileName", logCriteria.getFileExtension(), MatchMode.END).ignoreCase());
    }

    criteria.addOrder(Order.desc("actionDate"));

    return findBy(criteria);
}

From source file:org.linagora.linshare.core.repository.hibernate.ShareEntryRepositoryImpl.java

License:Open Source License

@Override
public List<ShareEntry> findUpcomingExpiredEntries(Integer date) {
    Calendar calMin = Calendar.getInstance();
    calMin.add(Calendar.DAY_OF_MONTH, date);

    Calendar calMax = Calendar.getInstance();
    calMax.add(Calendar.DAY_OF_MONTH, date + 1);

    return findByCriteria(Restrictions.lt("expirationDate", calMax), Restrictions.gt("expirationDate", calMin));
}

From source file:org.linagora.linshare.core.repository.hibernate.UploadRequestRepositoryImpl.java

License:Open Source License

@Override
public List<String> findAllRequestsToBeNotified() {
    DetachedCriteria crit = DetachedCriteria.forClass(getPersistentClass());
    GregorianCalendar gc = new GregorianCalendar();
    gc.set(GregorianCalendar.HOUR_OF_DAY, 0);
    gc.set(GregorianCalendar.MINUTE, 0);
    gc.set(GregorianCalendar.SECOND, 0);
    gc.set(GregorianCalendar.MILLISECOND, 0);
    Date before = gc.getTime();/* w w w.j a  va 2  s  . c o m*/
    gc.add(GregorianCalendar.DAY_OF_MONTH, 1);
    Date after = gc.getTime();
    crit.add(Restrictions.lt("notificationDate", after));
    crit.add(Restrictions.gt("notificationDate", before));
    crit.add(Restrictions.ltProperty("notificationDate", "expiryDate"));
    crit.add(Restrictions.eq("status", UploadRequestStatus.STATUS_ENABLED));
    crit.setProjection(Projections.property("uuid"));
    @SuppressWarnings("unchecked")
    List<String> list = listByCriteria(crit);
    return list;
}

From source file:org.motechproject.mobile.core.dao.hibernate.GatewayRequestDAOImpl.java

License:Open Source License

/**
 *  @see {@link org.motechproject.mobile.core.dao.GatewayRequestDAO#getByStatusAndSchedule}
 *//*  ww w .  ja v a  2s. c o  m*/
public List<GatewayRequest> getByStatusAndSchedule(MStatus status, Date schedule) {
    logger.debug("variables passed to getByStatusAndSchedule. status: " + status + "And schedule: " + schedule);

    try {

        List<GatewayRequest> allbystatandSdule;
        Criteria criteria = this.getSessionFactory().getCurrentSession().createCriteria(getPersistentClass());
        if (schedule == null) {
            criteria = criteria.add(Restrictions.isNull("dateTo")).add(Restrictions.isNull("dateFrom"))
                    .add(Restrictions.eq("messageStatus", status));
        } else {
            criteria = criteria.add(Restrictions.eq("messageStatus", status))
                    .add(Restrictions.or(Restrictions.isNull("dateFrom"),
                            Restrictions.lt("dateFrom", schedule)))
                    .add(Restrictions.or(Restrictions.isNull("dateTo"), Restrictions.gt("dateTo", schedule)));
        }

        allbystatandSdule = (List<GatewayRequest>) criteria.add(Restrictions.isNotNull("gatewayRequestDetails"))
                .list();
        logger.debug(allbystatandSdule);

        return allbystatandSdule;

    } catch (HibernateException he) {

        logger.error("Persistence or JDBC Exception in Method getByStatusAndSchedule", he);
        return null;
    } catch (Exception ex) {

        logger.error("Exception in Method getByStatusAndSchedule", ex);
        return null;
    }
}

From source file:org.motechproject.mobile.core.dao.hibernate.MessageRequestDAOImpl.java

License:Open Source License

/**
 * @see  {@link org.motechproject.mobile.core.dao.MessageRequestDAO#getMsgRequestByStatusAndSchedule(org.motechproject.mobile.core.model.MStatus, java.util.Date)  }
 *///  www.  j a  v a2 s .c  o m
public List getMsgRequestByStatusAndSchedule(MStatus status, Date schedule) {
    logger.debug("variables passed to getMsgRequestByStatusAndSchedule. status: " + status + "And schedule: "
            + schedule);

    try {

        List msgRequest = this.getSessionFactory().getCurrentSession().createCriteria(this.getPersistentClass())
                .add(Restrictions.eq("status", status)).add(Restrictions.lt("dateFrom", schedule))
                .add(Restrictions.gt("dateTo", schedule)).list();
        logger.debug(msgRequest);
        return msgRequest;

    } catch (HibernateException he) {
        logger.error("Persistence or JDBC Exception in Method getMsgRequestByStatusAndSchedule", he);
        return null;
    } catch (Exception ex) {
        logger.error("Exception in Method getMsgRequestByStatusAndSchedule", ex);
        return null;
    }

}

From source file:org.motechproject.mobile.core.dao.hibernate.MessageRequestDAOImpl.java

License:Open Source License

/**
 *
 * @see {@link org.motechproject.mobile.core.dao.MessageRequestDAO#getMsgRequestByRecipientAndSchedule(java.lang.String, java.util.Date)}
 *//*from w w w .  ja v  a  2 s.c o  m*/
public List<MessageRequest> getMsgRequestByRecipientAndSchedule(String recipientID, Date schedule) {
    logger.debug("variables passed to getMsgRequestByRecipientAndSchedule. recipientID: " + recipientID
            + "And schedule: " + schedule);

    try {

        List msgRequest = this.getSessionFactory().getCurrentSession().createCriteria(this.getPersistentClass())
                .add(Restrictions.eq("recipientId", recipientID)).add(Restrictions.lt("dateFrom", schedule))
                .add(Restrictions.gt("dateTo", schedule)).list();
        logger.debug(msgRequest);
        return msgRequest;

    } catch (HibernateException he) {
        logger.error("Persistence or JDBC Exception in Method getMsgRequestByStatusAndSchedule", he);
        return null;
    } catch (Exception ex) {
        logger.error("Exception in Method getMsgRequestByStatusAndSchedule", ex);
        return null;
    }
}

From source file:org.motechproject.mobile.core.dao.hibernate.MessageRequestDAOImpl.java

License:Open Source License

/**
 *
 * @see {@link org.motechproject.mobile.core.dao.MessageRequestDAO#getMsgRequestByRecipientDateFromBetweenDates(java.lang.String, java.util.Date, java.util.Date) }
 *//*from  ww w  .j a v  a 2  s . c om*/
public List<MessageRequest> getMsgRequestByRecipientDateFromBetweenDates(String recipientID, Date startDate,
        Date endDate) {
    logger.debug("variables passed to getMsgRequestByRecipientDateFromBetweenDates. recipientID: " + recipientID
            + " dateFrom after " + startDate + " before " + endDate);

    try {

        List msgRequest = this.getSessionFactory().getCurrentSession().createCriteria(this.getPersistentClass())
                .add(Restrictions.eq("recipientId", recipientID)).add(Restrictions.gt("dateFrom", startDate))
                .add(Restrictions.lt("dateFrom", endDate)).list();
        logger.debug(msgRequest);
        return msgRequest;

    } catch (HibernateException he) {
        logger.error("Persistence or JDBC Exception in Method getMsgRequestByStatusAndSchedule", he);
        return null;
    } catch (Exception ex) {
        logger.error("Exception in Method getMsgRequestByStatusAndSchedule", ex);
        return null;
    }
}