List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:org.motechproject.mobile.model.dao.hibernate.imp.IncomingMessageDAOImpl.java
License:Open Source License
/** * * @see {@link org.motechproject.mobile.model.dao.imp.IncomingMessageDAO#getByContentBefore(java.lang.String, java.util.Date) } */// w ww . j ava2 s .c o m public IncomingMessage getByContentBefore(String content, Date beforeDate) { logger.debug("variable passed to IncomingMessage.getByContent: " + content); try { IncomingMessage message = (IncomingMessage) this.getSessionFactory().getCurrentSession() .createCriteria(this.getPersistentClass()).add(Restrictions.eq("content", content)) .add(Restrictions.gt("dateCreated", beforeDate)).setMaxResults(1).uniqueResult(); logger.debug(message); return message; } catch (HibernateException he) { logger.error("Persistence or JDBC Exception in getByCode", he); return null; } catch (Exception ex) { logger.error("Exception in getByCode", ex); return null; } }
From source file:org.motechproject.server.model.db.hibernate.HibernateMotechDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<MessageProgramEnrollment> getActiveMessageProgramEnrollments(Integer personId, String program, Integer obsId, Long minExclusiveId, Integer maxResults) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(MessageProgramEnrollment.class); criteria.add(Restrictions.isNotNull("startDate")); criteria.add(Restrictions.isNull("endDate")); if (personId != null) { criteria.add(Restrictions.eq("personId", personId)); }//from www. j av a2 s . c o m if (program != null) { criteria.add(Restrictions.eq("program", program)); } if (obsId != null) { criteria.add(Restrictions.eq("obsId", obsId)); } if (minExclusiveId != null) { criteria.add(Restrictions.gt("id", minExclusiveId)); } if (maxResults != null) { criteria.setMaxResults(maxResults); } return (List<MessageProgramEnrollment>) criteria.addOrder(Order.asc("id")).list(); }
From source file:org.motechproject.server.model.db.hibernate.HibernateMotechDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ExpectedObs> getExpectedObs(Patient patient, Facility facility, String[] groups, Date minDueDate, Date maxDueDate, Date maxLateDate, Date minMaxDate, Integer maxResults) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(ExpectedObs.class); if (patient != null) { criteria.add(Restrictions.eq("patient", patient)); }/*w w w . j a v a 2 s. c om*/ if (groups != null && groups.length != 0) { criteria.add(Restrictions.in("group", groups)); } if (minDueDate != null) { criteria.add(Restrictions.ge("dueObsDatetime", minDueDate)); } if (maxDueDate != null) { criteria.add(Restrictions.le("dueObsDatetime", maxDueDate)); } if (maxLateDate != null) { criteria.add(Restrictions.le("lateObsDatetime", maxLateDate)); } if (minMaxDate != null) { criteria.add(Restrictions.or(Restrictions.isNull("maxObsDatetime"), Restrictions.gt("maxObsDatetime", minMaxDate))); } if (facility != null) { criteria.add(Restrictions.sqlRestriction( "exists (select f.id from motechmodule_facility f " + "inner join motechmodule_facility_patient fp " + "on f.id = fp.facility_id " + "where f.facility_id = ? and fp.patient_id = {alias}.patient_id)", facility.getFacilityId(), Hibernate.INTEGER)); } criteria.add(Restrictions.eq("voided", false)); criteria.addOrder(Order.asc("dueObsDatetime")); if (maxResults != null) { criteria.setMaxResults(maxResults); } return criteria.list(); }
From source file:org.motechproject.server.model.db.hibernate.HibernateMotechDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ExpectedEncounter> getExpectedEncounter(Patient patient, Facility facility, String[] groups, Date minDueDate, Date maxDueDate, Date maxLateDate, Date minMaxDate, Integer maxResults) { Session session = sessionFactory.getCurrentSession(); Criteria criteria = session.createCriteria(ExpectedEncounter.class); if (patient != null) { criteria.add(Restrictions.eq("patient", patient)); }//from www. j av a 2 s . c o m if (groups != null && groups.length != 0) { criteria.add(Restrictions.in("group", groups)); } if (minDueDate != null) { criteria.add(Restrictions.ge("dueEncounterDatetime", minDueDate)); } if (maxDueDate != null) { criteria.add(Restrictions.le("dueEncounterDatetime", maxDueDate)); } if (maxLateDate != null) { criteria.add(Restrictions.le("lateEncounterDatetime", maxLateDate)); } if (minMaxDate != null) { criteria.add(Restrictions.or(Restrictions.isNull("maxEncounterDatetime"), Restrictions.gt("maxEncounterDatetime", minMaxDate))); } if (facility != null) { criteria.add(Restrictions.sqlRestriction( "exists (select f.id from motechmodule_facility f " + "inner join motechmodule_facility_patient fp " + "on f.id = fp.facility_id " + "where f.facility_id = ? and fp.patient_id = {alias}.patient_id)", facility.getFacilityId(), Hibernate.INTEGER)); } criteria.add(Restrictions.eq("voided", false)); criteria.addOrder(Order.asc("dueEncounterDatetime")); if (maxResults != null) { criteria.setMaxResults(maxResults); } return criteria.list(); }
From source file:org.n52.sos.ds.hibernate.util.TemporalRestriction.java
License:Open Source License
/** * Creates a <tt>Criterion</tt> for the specified property. Used to easily * swap > and ≥./* w ww .j ava 2 s .c o m*/ * * @param property * the property name * @param value * the compared value * * @return the <tt>Criterion</tt> */ protected Criterion greater(String property, Date value) { return ALLOW_EQUALITY ? Restrictions.ge(property, value) : Restrictions.gt(property, value); }
From source file:org.nema.medical.mint.server.domain.ChangeDAO.java
License:Apache License
@SuppressWarnings("unchecked") public List<Change> findChanges(final Date since, int first, int max) { if (since != null) { final DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Change.class); detachedCriteria.add(Restrictions.gt("dateTime", since)); detachedCriteria.addOrder(Order.desc("dateTime")); final List<Change> list = getHibernateTemplate().findByCriteria(detachedCriteria, first, max); return list; }//from w w w .j a v a2 s . c om return null; }
From source file:org.obiba.onyx.jade.core.service.impl.hibernate.ExperimentalConditionServiceHibernateImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ExperimentalCondition> getNonInstrumentRelatedConditionsRecordedAfter(String workstationId, Date date) {/*from w w w. j av a 2s . c o m*/ Criteria criteria = getSession().createCriteria(ExperimentalCondition.class) .add(Restrictions.eq("workstation", workstationId)).add(Restrictions.gt("time", date)) .addOrder(Order.asc("time")); List<ExperimentalCondition> results = criteria.list(); return extractNonInstrumentRelatedConditions(results); }
From source file:org.obiba.onyx.jade.core.service.impl.hibernate.ExperimentalConditionServiceHibernateImpl.java
License:Open Source License
@SuppressWarnings("unchecked") public List<ExperimentalCondition> getInstrumentCalibrationsRecordedAfter(String instrumentBarcode, Date date) { Criteria criteria = getSession().createCriteria(ExperimentalCondition.class) .add(Restrictions.gt("time", date)).addOrder(Order.asc("time")) .createCriteria("experimentalConditionValues") .add(Restrictions.eq("attributeName", ExperimentalConditionService.INSTRUMENT_BARCODE)) .add(Restrictions.eq("textValue", instrumentBarcode)); List<ExperimentalCondition> results = criteria.list(); return extractInstrumentCalibrations(results); }
From source file:org.openbp.server.persistence.hibernate.HibernatePersistenceContext.java
License:Apache License
/** * Returns a list of the objects of a particular type that match the given criterion. * * @param query Query to run/*from w w w.j a v a2s . co m*/ * @return The list or null * @throws PersistenceException On error */ public Collection runQuery(final PersistenceQuery query) throws PersistenceException { TransactionGuard tg = new TransactionGuard(this); try { Class cls = getMappedObjectClass(query.getObjectClass(), false); Criteria hc = getHibernateSession().createCriteria(cls); if (query.getMaxResults() > 0) { hc.setMaxResults(query.getMaxResults()); } for (Iterator it = query.getOrderings(); it.hasNext();) { PersistenceOrdering ordering = (PersistenceOrdering) it.next(); Order ho = ordering.isAscending() ? Order.asc(ordering.getPropertyName()) : Order.desc(ordering.getPropertyName()); hc.addOrder(ho); } for (Iterator it = query.getCriterions(); it.hasNext();) { PersistenceCriterion criterion = (PersistenceCriterion) it.next(); String property = criterion.getProperty(); String operator = criterion.getOperator(); Object value = criterion.getOperand(); if (PersistenceCriterion.OPERATOR_EQ.equals(operator)) { hc = hc.add(Restrictions.eq(property, value)); } else if (PersistenceCriterion.OPERATOR_EQ_OR_NULL.equals(operator)) { hc = hc.add(Restrictions.disjunction().add(Restrictions.isNull(property)) .add(Restrictions.eq(property, value))); } else if (PersistenceCriterion.OPERATOR_NEQ.equals(operator)) { hc = hc.add(Restrictions.ne(property, value)); } else if (PersistenceCriterion.OPERATOR_GT.equals(operator)) { hc = hc.add(Restrictions.gt(property, value)); } else if (PersistenceCriterion.OPERATOR_GTE.equals(operator)) { hc = hc.add(Restrictions.ge(property, value)); } else if (PersistenceCriterion.OPERATOR_LT.equals(operator)) { hc = hc.add(Restrictions.lt(property, value)); } else if (PersistenceCriterion.OPERATOR_LTE.equals(operator)) { hc = hc.add(Restrictions.le(property, value)); } else if (PersistenceCriterion.OPERATOR_LIKE.equals(operator)) { hc = hc.add(Restrictions.gt(property, value)); } else if (PersistenceCriterion.OPERATOR_NULL.equals(operator)) { hc = hc.add(Restrictions.isNull(property)); } else if (PersistenceCriterion.OPERATOR_ALIAS.equals(operator)) { hc = hc.createAlias(property, (String) value); } } // Run query and wrap result list into a collection that calls onLoad for each element that is being accessed. Collection root = hc.list(); return new DeferedOnLoadCollection(root, this); } catch (HibernateException e) { tg.doCatch(); throw createLoggedException(e); } finally { tg.doFinally(); } }
From source file:org.openbravo.advpaymentmngt.ad_reports.ReportReconciliation.java
License:Open Source License
/** * Calculates the sum of all the transactions in a higher date than the end date of the given * reconciliation./*from w w w . j a v a2s . co m*/ * * @param recon * Reconciliation. * @return Sum of all the transactions in a higher date than the end date of the given * reconciliation. */ private BigDecimal getTransactionsTotalAfterReconciliationEndDate(FIN_Reconciliation recon) { BigDecimal balance = BigDecimal.ZERO; OBContext.setAdminMode(true); try { OBCriteria<FIN_FinaccTransaction> obcTrans = OBDal.getInstance() .createCriteria(FIN_FinaccTransaction.class); obcTrans.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_ACCOUNT, recon.getAccount())); obcTrans.add(Restrictions.eq(FIN_FinaccTransaction.PROPERTY_PROCESSED, true)); obcTrans.add(Restrictions.gt(FIN_FinaccTransaction.PROPERTY_TRANSACTIONDATE, recon.getEndingDate())); ProjectionList projections = Projections.projectionList(); projections.add(Projections.sum(FIN_FinaccTransaction.PROPERTY_PAYMENTAMOUNT)); projections.add(Projections.sum(FIN_FinaccTransaction.PROPERTY_DEPOSITAMOUNT)); obcTrans.setProjection(projections); if (obcTrans.list() != null && obcTrans.list().size() > 0) { @SuppressWarnings("rawtypes") List o = obcTrans.list(); Object[] resultSet = (Object[]) o.get(0); BigDecimal paymentAmt = (resultSet[0] != null) ? (BigDecimal) resultSet[0] : BigDecimal.ZERO; BigDecimal depositAmt = (resultSet[1] != null) ? (BigDecimal) resultSet[1] : BigDecimal.ZERO; balance = depositAmt.subtract(paymentAmt); } } finally { OBContext.restorePreviousMode(); } return balance; }