List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:org.gluewine.persistence_jpa_hibernate.impl.HibernateTransactionalSessionImpl.java
License:Apache License
@Override public Criteria createCriteria(Class<?> cl, Filter filter) { Criteria cr = createCriteria(cl);/*from ww w. ja v a2 s.c om*/ for (FilterLine line : filter.getLines()) { switch (line.getOperator()) { case CONTAINS: cr.add(Restrictions.like(line.getFieldName(), "%" + line.getValue() + "%")); break; case DOES_NOT_CONTAIN: cr.add(Restrictions.not(Restrictions.like(line.getFieldName(), "%" + line.getValue() + "%"))); break; case DOES_NOT_ICONTAIN: cr.add(Restrictions.not(Restrictions.ilike(line.getFieldName(), "%" + line.getValue() + "%"))); break; case EQUALS: cr.add(Restrictions.eq(line.getFieldName(), line.getValue())); break; case GREATER_OR_EQUAL_THAN: cr.add(Restrictions.ge(line.getFieldName(), line.getValue())); break; case GREATER_THAN: cr.add(Restrictions.gt(line.getFieldName(), line.getValue())); break; case ICONTAINS: cr.add(Restrictions.ilike(line.getFieldName(), "%" + line.getValue() + "%")); break; case LESS_OR_EQUAL_THAN: cr.add(Restrictions.le(line.getFieldName(), line.getValue())); break; case LESS_THAN: cr.add(Restrictions.lt(line.getFieldName(), line.getValue())); break; case NOT_EQUALS: cr.add(Restrictions.ne(line.getFieldName(), line.getValue())); break; case ISNULL: cr.add(Restrictions.isNull(line.getFieldName())); break; case NOTNULL: cr.add(Restrictions.isNotNull(line.getFieldName())); break; default: break; } } for (SortLine sort : filter.getSortLines()) { if (sort.isAscending()) cr.addOrder(Property.forName(sort.getField()).asc()); else cr.addOrder(Property.forName(sort.getField()).desc()); } if (filter.getLimit() != 0) cr.setMaxResults(filter.getLimit()); if (filter.getOffset() != 0) cr.setFirstResult(filter.getOffset()); return cr; }
From source file:org.gridchem.service.dao.JobDao.java
License:Open Source License
@SuppressWarnings({ "unchecked" }) public static List<Job> getAfterDate(Calendar cal) { if (!ServiceUtil.isValid(cal)) return new ArrayList<Job>(); HibernateUtil.beginTransaction();// www . j ava2s . c om Session session = HibernateUtil.getSession(); List result = null; try { //java.sql.Date cutoffDate = new java.sql.Date(cal.getTimeInMillis()); result = session.createCriteria(Job.class).add(Restrictions.gt("created", cal.getTime())).list(); //Hibernate.initialize(result); } catch (HibernateException ex) { throw new JobException(ex); } catch (Exception e) { e.printStackTrace(); log.error(e); } return result; }
From source file:org.headsupdev.agile.storage.resource.ResourceManagerImpl.java
License:Open Source License
public List<DurationWorked> getDurationWorkedForUser(User user) { Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession(); Criteria c = session.createCriteria(DurationWorked.class); c.add(Restrictions.eq("user", user)); c.add(Restrictions.gt("worked.time", 0)); return c.list(); }
From source file:org.headsupdev.agile.storage.resource.ResourceManagerImpl.java
License:Open Source License
public List<DurationWorked> getDurationWorkedForUser(User user, Date start, Date end) { List<DurationWorked> workedList = new ArrayList<DurationWorked>(); Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession(); Criteria c = session.createCriteria(DurationWorked.class); c.add(Restrictions.eq("user", user)); c.add(Restrictions.gt("worked.time", 0)); c.add(Restrictions.between("day", start, end)); for (DurationWorked worked : (List<DurationWorked>) c.list()) { if (worked.getDay().before(start) || worked.getDay().after(end)) { continue; }//from w w w. j a va 2s . c o m workedList.add(worked); } return workedList; }
From source file:org.hsqldb.hibernate.geomajas.layer.hibernate.CriteriaVisitor.java
License:Open Source License
/** {@inheritDoc} */ 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.hyperic.hq.appdef.server.session.PlatformDAO.java
License:Open Source License
public Collection<Platform> findByCTime(long ctime) { return createCriteria().add(Restrictions.gt("creationTime", new Long(ctime))) .addOrder(Order.desc("creationTime")).list(); }
From source file:org.ikasan.error.reporting.dao.HibernateErrorReportingServiceDao.java
License:BSD License
@Override public List<ErrorOccurrence<byte[]>> find(List<String> moduleName, List<String> flowName, List<String> flowElementname, Date startDate, Date endDate) { DetachedCriteria criteria = DetachedCriteria.forClass(ErrorOccurrence.class); if (moduleName != null && moduleName.size() > 0) { criteria.add(Restrictions.in("moduleName", moduleName)); }/*ww w. j av a 2 s . c om*/ if (flowName != null && flowName.size() > 0) { criteria.add(Restrictions.in("flowName", flowName)); } if (flowElementname != null && flowElementname.size() > 0) { criteria.add(Restrictions.in("flowElementName", flowElementname)); } if (startDate != null) { criteria.add(Restrictions.gt("timestamp", startDate.getTime())); } if (endDate != null) { criteria.add(Restrictions.lt("timestamp", endDate.getTime())); } criteria.addOrder(Order.desc("expiry")); return (List<ErrorOccurrence<byte[]>>) this.getHibernateTemplate().findByCriteria(criteria); }
From source file:org.ikasan.exclusion.dao.HibernateExclusionEventDao.java
License:BSD License
@Override public List<ExclusionEvent> find(List<String> moduleName, List<String> flowName, Date startDate, Date endDate, String identifier) {// www . ja va2 s . co m DetachedCriteria criteria = DetachedCriteria.forClass(ExclusionEvent.class); if (moduleName != null && moduleName.size() > 0) { criteria.add(Restrictions.in("moduleName", moduleName)); } if (flowName != null && flowName.size() > 0) { criteria.add(Restrictions.in("flowName", flowName)); } if (identifier != null && identifier.length() > 0) { criteria.add(Restrictions.eq("identifier", identifier)); } if (startDate != null) { criteria.add(Restrictions.gt("timestamp", startDate.getTime())); } if (endDate != null) { criteria.add(Restrictions.lt("timestamp", endDate.getTime())); } criteria.addOrder(Order.desc("timestamp")); return (List<ExclusionEvent>) this.getHibernateTemplate().findByCriteria(criteria); }
From source file:org.ikasan.hospital.dao.HibernateHospitalDao.java
License:BSD License
@SuppressWarnings("unchecked") @Override//from w ww . j a v a 2 s .c o m public List<ExclusionEventAction> getActionedExclusions(List<String> moduleName, List<String> flowName, Date startDate, Date endDate) { DetachedCriteria criteria = DetachedCriteria.forClass(ExclusionEventAction.class); if (moduleName != null && moduleName.size() > 0) { criteria.add(Restrictions.in("moduleName", moduleName)); } if (flowName != null && flowName.size() > 0) { criteria.add(Restrictions.in("flowName", flowName)); } if (startDate != null) { criteria.add(Restrictions.gt("timestamp", startDate.getTime())); } if (endDate != null) { criteria.add(Restrictions.lt("timestamp", endDate.getTime())); } return (List<ExclusionEventAction>) this.getHibernateTemplate().findByCriteria(criteria); }
From source file:org.ikasan.systemevent.dao.HibernateSystemEventDao.java
License:BSD License
@SuppressWarnings("unchecked") public PagedSearchResult<SystemEvent> find(final int pageNo, final int pageSize, final String orderBy, final boolean orderAscending, final String subject, final String action, final Date timestampFrom, final Date timestampTo, final String actor) { return (PagedSearchResult<SystemEvent>) getHibernateTemplate().execute(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { Criteria resultCriteria = getCriteria(session); resultCriteria.setMaxResults(pageSize); int firstResult = (pageNo * pageSize); resultCriteria.setFirstResult(firstResult); resultCriteria.addOrder(Order.desc("id")); List<SystemEvent> systemEventResults = resultCriteria.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); }/* w w w. j a v a 2s .c om*/ return new ArrayListPagedSearchResult<SystemEvent>(systemEventResults, firstResult, rowCount); } /** * Create a consistent criteria instance for both result and metadata * @param session * @return */ private Criteria getCriteria(Session session) { Criteria criteria = session.createCriteria(SystemEvent.class, "event"); if (restrictionExists(subject)) { criteria.add(Restrictions.eq("subject", subject)); } if (restrictionExists(action)) { criteria.add(Restrictions.eq("action", action)); } if (restrictionExists(actor)) { criteria.add(Restrictions.eq("actor", actor)); } if (restrictionExists(timestampFrom)) { criteria.add(Restrictions.gt("timestamp", timestampFrom)); } if (restrictionExists(timestampTo)) { criteria.add(Restrictions.lt("timestamp", timestampTo)); } return criteria; } }); }