List of usage examples for org.hibernate.criterion Restrictions lt
public static SimpleExpression lt(String propertyName, Object value)
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) {/* w ww. j av a 2 s. c om*/ 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.exclusion.dao.HibernateExclusionServiceDao.java
License:BSD License
/** * Identifies a batch (List of Ids) of housekeepable items * * @return List of ids/*w ww . j a va 2 s.c o m*/ */ @SuppressWarnings("unchecked") private List<String> getHousekeepableBatch() { return (List<String>) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { List<String> ids = new ArrayList<String>(); Criteria criteria = session.createCriteria(ExclusionEvent.class); criteria.add(Restrictions.lt("expiry", System.currentTimeMillis())); criteria.setMaxResults(housekeepingBatchSize); for (Object exclusionEventObj : criteria.list()) { ExclusionEvent exclusionEvent = (ExclusionEvent) exclusionEventObj; ids.add(exclusionEvent.getIdentifier()); } return ids; } }); }
From source file:org.ikasan.exclusion.dao.HibernateExclusionServiceDao.java
License:BSD License
private boolean housekeepablesExist() { return (Boolean) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Criteria criteria = session.createCriteria(ExclusionEvent.class); criteria.add(Restrictions.lt("expiry", System.currentTimeMillis())); criteria.setProjection(Projections.rowCount()); Long rowCount = new Long(0); List<Long> rowCountList = criteria.list(); if (!rowCountList.isEmpty()) { rowCount = rowCountList.get(0); }//from w w w . j a va 2 s . com return new Boolean(rowCount > 0); } }); }
From source file:org.ikasan.filter.duplicate.dao.HibernateFilteredMessageDaoImpl.java
License:BSD License
/** * Find expired entries//from w w w . j ava 2s .com * @return List of max 100 expired filter entries */ @SuppressWarnings("unchecked") private List<FilterEntry> findExpiredMessages() { List<FilterEntry> foundMessages = (List<FilterEntry>) this.getHibernateTemplate() .execute(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { Criteria criteria = session.createCriteria(FilterEntry.class); criteria.add(Restrictions.lt(FilterEntry.EXPRIY_PROP_KEY, System.currentTimeMillis())); criteria.setMaxResults(batchSize); return criteria.list(); } }); if (foundMessages == null || foundMessages.isEmpty()) { return null; } else { return foundMessages; } }
From source file:org.ikasan.hospital.dao.HibernateHospitalDao.java
License:BSD License
@SuppressWarnings("unchecked") @Override/*from w ww . j ava 2 s . com*/ 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); }/*from www . j ava2s. c o m*/ 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; } }); }
From source file:org.ikasan.systemevent.dao.HibernateSystemEventDao.java
License:BSD License
/** * Identifies a batch (List of Ids) of housekeepable items * //from ww w .j a v a 2 s. c o m * @return List of ids for SystemFlowEvents */ @SuppressWarnings("unchecked") private List<Long> getHousekeepableBatch() { return (List<Long>) getHibernateTemplate().execute(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { List<Long> ids = new ArrayList<Long>(); Criteria criteria = session.createCriteria(SystemEvent.class); criteria.add(Restrictions.lt("expiry", new Date())); criteria.setMaxResults(housekeepingBatchSize); for (Object systemEventObj : criteria.list()) { SystemEvent systemFlowEvent = (SystemEvent) systemEventObj; ids.add(systemFlowEvent.getId()); } return ids; } }); }
From source file:org.ikasan.systemevent.dao.HibernateSystemEventDao.java
License:BSD License
/** * Checks if there are housekeepable items in existance, ie expired * SystemFlowEvents// w w w . j av a2s. c o m * * @return true if there is at least 1 expired SystemFlowEvent */ private boolean housekeepablesExist() { return (Boolean) getHibernateTemplate().execute(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { Criteria criteria = session.createCriteria(SystemEvent.class); criteria.add(Restrictions.lt("expiry", new Date())); criteria.setProjection(Projections.rowCount()); Long rowCount = new Long(0); List<Long> rowCountList = criteria.list(); if (!rowCountList.isEmpty()) { rowCount = rowCountList.get(0); } logger.info(rowCount + ", housekeepables exist"); return new Boolean(rowCount > 0); } }); }
From source file:org.ikasan.wiretap.dao.HibernateWiretapDao.java
License:BSD License
/** * Perform a paged search for <code>WiretapFlowEvent</code>s * // w w w . j a va 2s. co m * @param pageNo - The page number to retrieve * @param pageSize - The size of the page * @param orderBy - order by field * @param orderAscending - ascending flag * @param moduleNames - The list of module names * @param moduleFlow - The name of Flow internal to the Module * @param componentName - The component name * @param eventId - The event id * @param payloadId - The payload id * @param fromDate - The from date * @param untilDate - The to date * @param payloadContent - The payload content * * @return PagedSearchResult */ @SuppressWarnings("unchecked") public PagedSearchResult<WiretapEvent> findWiretapEvents(final int pageNo, final int pageSize, final String orderBy, final boolean orderAscending, final Set<String> moduleNames, final String moduleFlow, final String componentName, final String eventId, final String payloadId, final Date fromDate, final Date untilDate, final String payloadContent) { return (PagedSearchResult) getHibernateTemplate().execute(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { Criteria dataCriteria = getCriteria(session); dataCriteria.setMaxResults(pageSize); int firstResult = pageNo * pageSize; dataCriteria.setFirstResult(firstResult); if (orderBy != null) { if (orderAscending) { dataCriteria.addOrder(Order.asc(orderBy)); } else { dataCriteria.addOrder(Order.desc(orderBy)); } } List<WiretapEvent> wiretapResults = dataCriteria.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); } return new ArrayListPagedSearchResult<WiretapEvent>(wiretapResults, firstResult, rowCount); } /** * Create a criteria instance for each invocation of data or metadata queries. * @param session * @return */ private Criteria getCriteria(Session session) { Criteria criteria = session.createCriteria(WiretapEvent.class); if (restrictionExists(moduleNames)) { criteria.add(Restrictions.in("moduleName", moduleNames)); } if (restrictionExists(moduleFlow)) { criteria.add(Restrictions.eq("flowName", moduleFlow)); } if (restrictionExists(componentName)) { criteria.add(Restrictions.eq("componentName", componentName)); } if (restrictionExists(eventId)) { criteria.add(Restrictions.eq("eventId", eventId)); } // if (restrictionExists(payloadId)) // { // criteria.add(Restrictions.eq("payloadId", payloadId)); // } if (restrictionExists(payloadContent)) { criteria.add(Restrictions.like("event", payloadContent, MatchMode.ANYWHERE)); } if (restrictionExists(fromDate)) { criteria.add(Restrictions.gt("timestamp", fromDate.getTime())); } if (restrictionExists(untilDate)) { criteria.add(Restrictions.lt("timestamp", untilDate.getTime())); } return criteria; } }); }
From source file:org.ikasan.wiretap.dao.HibernateWiretapDao.java
License:BSD License
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//from w ww .ja v a 2s . c om public PagedSearchResult<WiretapEvent> findWiretapEvents(final int pageNo, final int pageSize, final String orderBy, final boolean orderAscending, final Set<String> moduleNames, final Set<String> moduleFlows, final Set<String> componentNames, final String eventId, final String payloadId, final Date fromDate, final Date untilDate, final String payloadContent) { return (PagedSearchResult) getHibernateTemplate().execute(new HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { Criteria dataCriteria = getCriteria(session); dataCriteria.setMaxResults(pageSize); int firstResult = pageNo * pageSize; dataCriteria.setFirstResult(firstResult); if (orderBy != null) { if (orderAscending) { dataCriteria.addOrder(Order.asc(orderBy)); } else { dataCriteria.addOrder(Order.desc(orderBy)); } } List<WiretapEvent> wiretapResults = dataCriteria.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); } return new ArrayListPagedSearchResult<WiretapEvent>(wiretapResults, firstResult, rowCount); } /** * Create a criteria instance for each invocation of data or metadata queries. * @param session * @return */ private Criteria getCriteria(Session session) { Criteria criteria = session.createCriteria(WiretapEvent.class); if (restrictionExists(moduleNames)) { criteria.add(Restrictions.in("moduleName", moduleNames)); } if (restrictionExists(moduleFlows)) { criteria.add(Restrictions.in("flowName", moduleFlows)); } if (restrictionExists(componentNames)) { criteria.add(Restrictions.in("componentName", componentNames)); } if (restrictionExists(eventId)) { criteria.add(Restrictions.eq("eventId", eventId)); } if (restrictionExists(payloadContent)) { criteria.add(Restrictions.like("event", payloadContent, MatchMode.ANYWHERE)); } if (restrictionExists(fromDate)) { criteria.add(Restrictions.gt("timestamp", fromDate.getTime())); } if (restrictionExists(untilDate)) { criteria.add(Restrictions.lt("timestamp", untilDate.getTime())); } return criteria; } }); }