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:net.purnama.pureff.dao.ReturnSalesDao.java

public List getUnpaidReturnSalesList(PartnerEntity partner, CurrencyEntity currency) {
    Session session = this.sessionFactory.getCurrentSession();
    Criteria c = session.createCriteria(ReturnSalesEntity.class);
    c.add(Restrictions.eq("partner", partner));
    c.add(Restrictions.eq("currency", currency));
    c.add(Restrictions.eq("status", true));
    c.add(Restrictions.gt("remaining", 0.0));
    c.addOrder(Order.asc("date"));
    c.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
    List ls = c.list();//ww  w  .  j a v  a  2 s . c  o m
    return ls;
}

From source file:net.sf.xplanner.dao.impl.UserStoryDaoImpl.java

License:Open Source License

@Override
@Transactional()/*  ww  w.j  a va 2  s. c o  m*/
public List<UserStory> getStoriesForPersonWhereCustomer(final int personId) {
    final Criteria criteria = this.createCriteria();
    criteria.createAlias("customer", "customer");
    criteria.createAlias("iteration", "iteration");
    criteria.add(Restrictions.eq("customer.id", personId));
    criteria.add(Restrictions.gt("iteration.endDate", new Date()));
    criteria.setFetchMode("tasks", FetchMode.SELECT);
    criteria.setFetchMode("tasks.timeEntries", FetchMode.SELECT);
    return criteria.list();
}

From source file:net.sf.xplanner.dao.impl.UserStoryDaoImpl.java

License:Open Source License

@Override
@Transactional()//from  w  ww. j  av a2 s . co  m
public List<UserStory> getStoriesForPersonWhereTracker(final int personId) {
    final Criteria criteria = this.createCriteria();
    criteria.createAlias("iteration", "iteration");
    criteria.add(Restrictions.eq("trackerId", personId));
    criteria.add(Restrictions.gt("iteration.endDate", new Date()));
    criteria.setFetchMode("tasks", FetchMode.SELECT);
    criteria.setFetchMode("tasks.timeEntries", FetchMode.SELECT);
    return criteria.list();
}

From source file:net.umpay.mailbill.hql.orm.hibernate.HibernateDao.java

License:Apache License

/**
 * ??Criterion,.//from  w  w w  .jav a 2  s . co m
 */
protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue,
        final MatchType matchType) {
    Assert.hasText(propertyName, "propertyName?");
    Criterion criterion = null;
    try {

        //?MatchTypecriterion
        if (MatchType.EQ.equals(matchType)) {
            criterion = Restrictions.eq(propertyName, propertyValue);
        } else if (MatchType.LIKE.equals(matchType)) {
            criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE);
        } else if (MatchType.LE.equals(matchType)) {
            criterion = Restrictions.le(propertyName, propertyValue);
        } else if (MatchType.LT.equals(matchType)) {
            criterion = Restrictions.lt(propertyName, propertyValue);
        } else if (MatchType.GE.equals(matchType)) {
            criterion = Restrictions.ge(propertyName, propertyValue);
        } else if (MatchType.GT.equals(matchType)) {
            criterion = Restrictions.gt(propertyName, propertyValue);
        } else if (MatchType.NE.equals(matchType)) {
            criterion = Restrictions.ne(propertyName, propertyValue);
        }
    } catch (Exception e) {
        throw ReflectionUtils.convertReflectionExceptionToUnchecked(e);
    }
    return criterion;
}

From source file:ome.services.search.SearchAction.java

License:Open Source License

private void createdOrModified(Class cls, Criteria criteria, QueryBuilder qb, String path) {

    if (!IGlobal.class.isAssignableFrom(cls)) {

        if (criteria != null) {
            criteria.createAlias("details.creationEvent", "create");
        }/*from  w  w  w . ja va 2s .co  m*/

        if (values.createdStart != null) {
            if (criteria != null) {
                criteria.add(Restrictions.gt("create.time", values.createdStart));
            }
            if (qb != null) {
                String ctime = qb.unique_alias("ctimestart");
                qb.and(path + "details.creationEvent.time > :" + ctime);
                qb.param(ctime, values.createdStart);
            }
        }

        if (values.createdStop != null) {
            if (criteria != null) {
                criteria.add(Restrictions.lt("create.time", values.createdStop));
            }
            if (qb != null) {
                String ctime = qb.unique_alias("ctimestop");
                qb.and(path + "details.creationEvent.time < :" + ctime);
                qb.param(ctime, values.createdStop);
            }
        }

        if (IMutable.class.isAssignableFrom(cls)) {

            if (criteria != null) {
                criteria.createAlias("details.updateEvent", "update");
            }

            if (values.modifiedStart != null) {
                if (criteria != null) {
                    criteria.add(Restrictions.gt("update.time", values.modifiedStart));
                }

                if (qb != null) {
                    String mtime = qb.unique_alias("mtimestart");
                    qb.and(path + "details.updateEvent.time > :" + mtime);
                    qb.param(mtime, values.modifiedStart);
                }
            }

            if (values.modifiedStop != null) {
                if (criteria != null) {
                    criteria.add(Restrictions.lt("update.time", values.modifiedStop));
                }

                if (qb != null) {
                    String mtime = qb.unique_alias("mtimestart");
                    qb.and(path + "details.updateEvent.time < :" + mtime);
                    qb.param(mtime, values.modifiedStop);
                }
            }
        }
    }
}

From source file:ome.services.search.SearchAction.java

License:Open Source License

private void annotatedBetween(AnnotationCriteria ann, QueryBuilder qb, String path) {
    if (values.annotatedStart != null) {
        if (ann != null) {
            ann.getCreate().add(Restrictions.gt("anncreate.time", values.annotatedStart));
        }//  w w w.j av a 2  s  .com

        if (qb != null) {
            String astart = qb.unique_alias("astart");
            qb.and(path + "details.creationEvent.time > :" + astart);
            qb.param(astart, values.annotatedStart);
        }
    }

    if (values.annotatedStop != null) {
        if (ann != null) {
            ann.getCreate().add(Restrictions.lt("anncreate.time", values.annotatedStop));
        }

        if (qb != null) {
            String astop = qb.unique_alias("astop");
            qb.and(path + "details.creationEvent.time < :" + astop);
            qb.param(astop, values.annotatedStop);
        }
    }
}

From source file:org.apache.ode.daohib.bpel.CriteriaBuilder.java

License:Apache License

static void addFilterOnPrefixedDate(Criteria crit, String op, Date date, String dateAttribute) {
    if (op.startsWith("=")) {
        crit.add(Restrictions.eq(dateAttribute, date));
    } else if (op.startsWith("<=")) {
        crit.add(Restrictions.le(dateAttribute, date));
    } else if (op.startsWith(">=")) {
        crit.add(Restrictions.ge(dateAttribute, date));
    } else if (op.startsWith("<")) {
        crit.add(Restrictions.lt(dateAttribute, date));
    } else if (op.startsWith(">")) {
        crit.add(Restrictions.gt(dateAttribute, date));
    }//from w  ww .jav a 2s.c o  m
}

From source file:org.apache.ode.daohib.bpel.ql.HibernateInstancesQueryCompiler.java

License:Apache License

protected GreaterEvaluator<String, Criterion, Object> compileGreater(final Greater gt) {
    if (gt.getIdentifier() instanceof Property) {
        propertyInQuery = true;//from  w  ww .  j a  v  a  2 s.  c  o  m
        final Property property = (Property) gt.getIdentifier();
        return new GreaterEvaluator<String, Criterion, Object>() {
            public Criterion evaluate(Object paramValue) {
                Conjunction conj = Restrictions.conjunction();
                if (!StringUtils.isEmpty(property.getNamespace())) {
                    conj.add(Restrictions.gt(PROPERTY_NS_DB_FIELD, property.getNamespace()));
                }
                conj.add(Restrictions.gt(PROPERTY_NAME_DB_FIELD, property.getName()));
                conj.add(Restrictions.gt(PROPERTY_VALUE_DB_FIELD, gt.getValue().getValue()));

                return conj;
            };

            public String getIdentifier() {
                return property.toString();
            };
        };
    } else {
        final String fieldName = gt.getIdentifier().getName();
        final Object value = gt.getValue().getValue();

        if (INSTANCE_STATUS_FIELD.equals(fieldName)) {
            throw new IllegalArgumentException("Field " + INSTANCE_STATUS_FIELD + " is not supported.");
        }

        final String dbField = getDBField(fieldName);

        return new GreaterEvaluator<String, Criterion, Object>() {
            public Criterion evaluate(Object paramValue) {
                return Restrictions.gt(dbField, value);
            }

            public String getIdentifier() {
                return fieldName;
            }
        };
    }
}

From source file:org.apache.ode.daohib.bpel.ql.HibernateInstancesQueryCompiler.java

License:Apache License

protected INEvaluator<String, Criterion, Object> compileIn(final In in) {
    if (in.getIdentifier() instanceof Property) {
        propertyInQuery = true;/*from w ww  .j a v  a  2  s. c om*/
        final Property property = (Property) in.getIdentifier();
        return new INEvaluator<String, Criterion, Object>() {
            public Criterion evaluate(Object paramValue) {
                Disjunction disj = Restrictions.disjunction();

                String propertyNS = property.getNamespace();
                String propertyName = property.getName();

                for (Value value : in.getValues()) {
                    Conjunction conj = Restrictions.conjunction();
                    if (!StringUtils.isEmpty(property.getNamespace())) {
                        conj.add(Restrictions.gt(PROPERTY_NS_DB_FIELD, propertyNS));
                    }
                    conj.add(Restrictions.gt(PROPERTY_NAME_DB_FIELD, propertyName));
                    conj.add(Restrictions.gt(PROPERTY_VALUE_DB_FIELD, value.getValue()));

                    disj.add(conj);
                }
                return disj;
            };

            public String getIdentifier() {
                return property.toString();
            };
        };
    } else {
        final String fieldName = in.getIdentifier().getName();

        if (INSTANCE_STATUS_FIELD.equals(fieldName)) {
            short noState = 200; // TODO move to constants
            final Disjunction disj = Restrictions.disjunction();

            final Collection values = ValuesHelper.extract((Collection<Value>) in.getValues());

            if (values.contains(STATUS_ACTIVE)) {
                disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_NEW));
                disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_ACTIVE));
                disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_READY));
            }
            if (values.contains(STATUS_SUSPENDED)) {
                disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_SUSPENDED));
            }
            if (values.contains(STATUS_ERROR)) {
                disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, noState)); // Error instance state doesn't exist yet
            }
            if (values.contains(STATUS_COMPLETED)) {
                disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_COMPLETED_OK));
            }
            if (values.contains(STATUS_TERMINATED)) {
                disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_TERMINATED));
            }
            if (values.contains(STATUS_FAULTED)) {
                disj.add(Restrictions.eq(INSTANCE_STATUS_DB_FIELD, ProcessState.STATE_COMPLETED_WITH_FAULT));
            }
            return new INEvaluator<String, Criterion, Object>() {
                public Criterion evaluate(Object paramValue) {
                    return disj;
                };

                public String getIdentifier() {
                    return INSTANCE_STATUS_DB_FIELD;
                };
            };
        } else {
            final Collection objValues;
            final Collection<Value> values = in.getValues();
            if (INSTANCE_ID_FIELD.equals(fieldName)) {
                objValues = new ArrayList<Long>(values.size());
                for (Value value : values) {
                    objValues.add(Long.valueOf((String) value.getValue()));
                }
            } else if (INSTANCE_STARTED_FIELD.equals(fieldName)
                    || INSTANCE_LAST_ACTIVE_FIELD.equals(fieldName)) {
                objValues = new ArrayList<Date>(values.size());
                try {
                    for (Value value : values) {
                        objValues.add(ISO8601DateParser.parse((String) value.getValue()));
                    }
                } catch (ParseException ex) {
                    // TODO
                    throw new RuntimeException(ex);
                }
            } else {
                objValues = ValuesHelper.extract((Collection<Value>) values);
            }
            final String dbField = getDBField(fieldName);
            return new INEvaluator<String, Criterion, Object>() {
                /**
                 * @see org.apache.ode.ql.eval.skel.CommandEvaluator#evaluate(java.lang.Object)
                 */
                public Criterion evaluate(Object paramValue) {
                    return Restrictions.in(dbField, objValues);
                }

                /**
                 * @see org.apache.ode.ql.eval.skel.Identified#getIdentifier()
                 */
                public String getIdentifier() {
                    return dbField;
                }
            };
        }
    }
}

From source file:org.apache.usergrid.apm.service.charts.filter.BiggerThanFilter.java

License:Apache License

public Criterion getCriteria() {
    if (getFilterEmpty())
        return null;

    return Restrictions.gt("this." + propertyName, propertyValue);
}