List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:org.generationcp.middleware.dao.NumericDataDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Integer> getObservationUnitIdsByTraitScaleMethodAndValueCombinations( List<TraitCombinationFilter> filters, int start, int numOfRows) throws MiddlewareQueryException { try {/* w ww . j a v a 2 s .c o m*/ if (filters == null || filters.isEmpty()) { return new ArrayList<Integer>(); } Criteria criteria = getSession().createCriteria(NumericData.class); criteria.createAlias("variate", "variate"); criteria.setProjection(Projections.distinct(Projections.property("id.observationUnitId"))); // keeps track if at least one filter was added boolean filterAdded = false; for (TraitCombinationFilter combination : filters) { Object value = combination.getValue(); // accept only Double objects if (value instanceof Double || value instanceof NumericRange) { criteria.add(Restrictions.eq("variate.traitId", combination.getTraitId())); criteria.add(Restrictions.eq("variate.scaleId", combination.getScaleId())); criteria.add(Restrictions.eq("variate.methodId", combination.getMethodId())); if (value instanceof NumericRange) { NumericRange range = (NumericRange) value; if (range.getStart() != null) { criteria.add(Restrictions.gt("value", range.getStart())); } if (range.getEnd() != null) { criteria.add(Restrictions.lt("value", range.getEnd())); } } else { criteria.add(Restrictions.eq("value", combination.getValue())); } filterAdded = true; } } if (filterAdded) { // if there is at least one filter, execute query and return results criteria.setFirstResult(start); criteria.setMaxResults((numOfRows)); return criteria.list(); } else { // return empty list if no filter was added return new ArrayList<Integer>(); } } catch (HibernateException e) { throw new MiddlewareQueryException( "Error with get getObservationUnitIdsByTraitScaleMethodAndValueCombinations(filters=" + filters + ") query from NumericData: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.TransactionDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Transaction> getAllDeposit(int start, int numOfRows) throws MiddlewareQueryException { try {/* w ww . ja v a 2 s . c o m*/ Criteria criteria = getSession().createCriteria(Transaction.class); criteria.add(Restrictions.eq("status", Integer.valueOf(0))); criteria.add(Restrictions.gt("quantity", Integer.valueOf(0))); criteria.setFirstResult(start); criteria.setMaxResults(numOfRows); return criteria.list(); } catch (HibernateException e) { throw new MiddlewareQueryException( "Error with getAllDeposit() query from Transaction: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.TransactionDAO.java
License:Open Source License
public long countAllDeposit() throws MiddlewareQueryException { try {/*from w ww. j a v a 2 s. co m*/ Criteria criteria = getSession().createCriteria(Transaction.class); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq("status", Integer.valueOf(0))); criteria.add(Restrictions.gt("quantity", Integer.valueOf(0))); return ((Long) criteria.uniqueResult()).longValue(); //count } catch (HibernateException e) { throw new MiddlewareQueryException( "Error with countAllDeposit() query from Transaction: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.TransactionDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Transaction> getAllDepositByDonor(Integer personId, int start, int numOfRows) throws MiddlewareQueryException { try {//w w w. j a v a 2 s. c o m Criteria criteria = getSession().createCriteria(Transaction.class); criteria.add(Restrictions.eq("status", Integer.valueOf(0))); criteria.add(Restrictions.gt("quantity", Integer.valueOf(0))); criteria.add(Restrictions.eq("personId", personId)); criteria.setFirstResult(start); criteria.setMaxResults(numOfRows); return criteria.list(); } catch (HibernateException e) { throw new MiddlewareQueryException("Error with getAllDepositByDonor(personId=" + personId + ") query from Transaction: " + e.getMessage(), e); } }
From source file:org.generationcp.middleware.dao.TransactionDAO.java
License:Open Source License
public long countAllDepositByDonor(Integer personId) throws MiddlewareQueryException { try {/*from w w w . ja v a 2s . c o m*/ Criteria criteria = getSession().createCriteria(Transaction.class); criteria.setProjection(Projections.rowCount()); criteria.add(Restrictions.eq("status", Integer.valueOf(0))); criteria.add(Restrictions.gt("quantity", Integer.valueOf(0))); criteria.add(Restrictions.eq("personId", personId)); return ((Long) criteria.uniqueResult()).longValue(); //count } catch (HibernateException e) { throw new MiddlewareQueryException("Error with countAllDepositByDonor(personId=" + personId + ") query from Transaction: " + e.getMessage(), e); } }
From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java
License:Open Source License
@Override public void outAGtExpr(AGtExpr node) { String propertyAlias = createAlias(node.getLeft()); translatedExpressions.put(node, Restrictions.gt(propertyAlias, reader.parseAsPropertyType( translatedLiterals.get(node.getRight()).toString(), getPropertyPath(node.getLeft())))); }
From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java
License:Open Source License
@Override public void outAAfterExpr(AAfterExpr node) { String propertyAlias = createAlias(node.getAttr()); translatedExpressions.put(node,//from w w w .j a va2 s . c o m Restrictions.gt(propertyAlias, parseDate(node.getDateTime().toString().trim()))); }
From source file:org.geolatte.common.cql.hibernate.HibernateCriteriaBuilder.java
License:Open Source License
@Override public void outADuringExpr(ADuringExpr node) { PTimespanLiteral timespan = node.getTimeSpan(); Criterion greaterThan;/*from w ww .j a v a 2 s. co m*/ Criterion lowerThan; if (timespan instanceof AFromToTimespanLiteral) { AFromToTimespanLiteral fromToTimespan = (AFromToTimespanLiteral) timespan; greaterThan = Restrictions.gt(node.getAttr().toString().trim(), parseDate(fromToTimespan.getFrom().getText().trim())); lowerThan = Restrictions.lt(node.getAttr().toString().trim(), parseDate(fromToTimespan.getTo().getText().trim())); } else if (timespan instanceof AFromDurationTimespanLiteral) { AFromDurationTimespanLiteral fromDurationTimespan = (AFromDurationTimespanLiteral) timespan; Date fromDate = parseDate(fromDurationTimespan.getFrom().getText().trim()); Duration duration = (Duration) translatedLiterals.get(fromDurationTimespan.getDuration()); // Calculate to 'to' date Calendar calendar = Calendar.getInstance(); calendar.setTime(fromDate); calendar.add(Calendar.YEAR, duration.getYears()); calendar.add(Calendar.MONTH, duration.getMonths()); calendar.add(Calendar.DATE, duration.getDays()); calendar.add(Calendar.HOUR, duration.getHours()); calendar.add(Calendar.MINUTE, duration.getMinutes()); calendar.add(Calendar.SECOND, duration.getSeconds()); Date toDate = calendar.getTime(); greaterThan = Restrictions.gt(node.getAttr().toString().trim(), fromDate); lowerThan = Restrictions.lt(node.getAttr().toString().trim(), toDate); } else { // if (timespan instanceof ADurationToTimespanLiteral) greaterThan = null; lowerThan = null; } Criterion combined = Restrictions.and(greaterThan, lowerThan); translatedExpressions.put(node, combined); }
From source file:org.geomajas.layer.hibernate.CriteriaVisitor.java
License:Open Source License
/** {@inheritDoc} */ @Override// w ww. j a va 2 s. c o m public Object visit(PropertyIsGreaterThan filter, Object userData) { String propertyName = getPropertyName(filter.getExpression1()); String finalName = parsePropertyName(propertyName, userData); Object literal = getLiteralValue(filter.getExpression2()); return Restrictions.gt(finalName, castLiteral(literal, propertyName)); }
From source file:org.geomajas.layer.hibernate.CriteriaVisitor.java
License:Open Source License
/** {@inheritDoc} */ @Override/*from ww w.j av a 2s .c om*/ public Object visit(After after, Object extraData) { String propertyName = getPropertyName(after.getExpression1()); String finalName = parsePropertyName(propertyName, after); Object literal = getLiteralValue(after.getExpression2()); if (literal instanceof Date) { return Restrictions.gt(finalName, literal); } else { throw new UnsupportedOperationException("visit(Object userData)"); } }