agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/dao/JobEventDao.java
/**
	 * Searches for {@link JobEvent} by the given user who matches the given set of 
	 * parameters. Permissions are honored in this query.
	 *
	 * @param jobid
	 * @param searchCriteria
	 * @param offset
	 * @param limit
	 * @return
	 * @throws JobException
	 */
Searches for  JobEvent by the given user who matches the given set of
parameters. Permissions are honored in this query.


Searches for JobEvent by the given user who matches the given set of parameters . Permissions are honored in this query .
@SuppressWarnings("unchecked")
	public static List<JobEvent> findMatching(Long jobId,
			Map<SearchTerm, Object> searchCriteria,
			int offset, int limit, AgaveResourceResultOrdering order, SearchTerm orderBy) throws JobException
	{
		if (order == null) {
			order = AgaveResourceResultOrdering.ASCENDING;
		}
		if (orderBy == null) {
			orderBy = new JobEventSearchFilter().filterAttributeName("id");
		}
		try
		{
			Session session = getSession();
			session.clear();
			String hql = "SELECT * \n" +
					" FROM jobevents e \n" +
					" WHERE e.job_id = :jobid \n" +
					"       AND e.tenant_id = :tenantid \n "; 
			for (SearchTerm searchTerm: searchCriteria.keySet()) 
			{
				hql += "\n       AND " + searchTerm.getExpression();
			}
			hql +=	"\n ORDER BY " + String.format(orderBy.getMappedField(), orderBy.getPrefix()) + " " + order + " \n";
			String q = hql;
			SQLQuery query = session.createSQLQuery(hql);
			query.setLong("jobid", jobId)
				 .setString("tenantid", TenancyHelper.getCurrentTenantId());
			q = StringUtils.replace(q, ":jobid", String.valueOf(jobId));
			q = StringUtils.replace(q, ":tenantid", "'" + TenancyHelper.getCurrentTenantId() + "'");
			for (SearchTerm searchTerm: searchCriteria.keySet()) 
			{
			    if (searchTerm.getOperator() == SearchTerm.Operator.BETWEEN) {
			        List<String> formattedDates = (List<String>)searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm));
			        for(int i=0;i<formattedDates.size(); i++) {
			            query.setDate(searchTerm.getSearchField()+i, new DateTime(formattedDates.get(i)).toDate());
			            q = StringUtils.replace(q, ":" + searchTerm.getSearchField() + i, "'" + formattedDates.get(i) + "'");
			        }
			    }
			    else if (searchTerm.getOperator().isSetOperator()) 
				{
					query.setParameterList(searchTerm.getSearchField(), (List<Object>)searchCriteria.get(searchTerm));
					q = StringUtils.replace(q, ":" + searchTerm.getSearchField(), "('" + StringUtils.join((List<String>)searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)), "','") + "')" );
				}
			    else 
				{
					query.setParameter(searchTerm.getSearchField(), 
							searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)));
					q = StringUtils.replace(q, ":" + searchTerm.getSearchField(), "'" + searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)) + "'");
				}
			}
			List<JobEvent> events = query
					.addEntity(JobEvent.class)
					.setFirstResult(offset)
					.setMaxResults(limit)
					.setCacheable(false)
					.setCacheMode(CacheMode.IGNORE)
					.list();
			session.flush();
			return events;
		}
		catch (Throwable ex)
		{
			throw new JobException(ex);
		}
		finally {
			try { HibernateUtil.commitTransaction();} catch (Exception e) {}
		}
	}
@ SuppressWarnings ( "unchecked" ) public static List < JobEvent > findMatching ( Long jobId , Map < SearchTerm , Object > searchCriteria , int offset , int limit , AgaveResourceResultOrdering order , SearchTerm orderBy ) throws JobException { if ( order == null ) { order = AgaveResourceResultOrdering . ASCENDING ; } if ( orderBy == null ) { orderBy = new JobEventSearchFilter ( ) . filterAttributeName ( "id" ) ; } try { Session session = getSession ( ) ; session . clear ( ) ; String hql = "SELECT * \n" + " FROM jobevents e \n" + " WHERE e.job_id = :jobid \n" + "       AND e.tenant_id = :tenantid \n " ; for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { hql += "\n       AND " + searchTerm . getExpression ( ) ; } hql += "\n ORDER BY " + String . format ( orderBy . getMappedField ( ) , orderBy . getPrefix ( ) ) + " " + order + " \n" ; String q = hql ; SQLQuery query = session . createSQLQuery ( hql ) ; query . setLong ( "jobid" , jobId ) . setString ( "tenantid" , TenancyHelper . getCurrentTenantId ( ) ) ; q = StringUtils . replace ( q , ":jobid" , String . valueOf ( jobId ) ) ; q = StringUtils . replace ( q , ":tenantid" , "'" + TenancyHelper . getCurrentTenantId ( ) + "'" ) ; for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { if ( searchTerm . getOperator ( ) == SearchTerm . Operator . BETWEEN ) { List < String > formattedDates = ( List < String > ) searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ; for ( int i = 0 ; i < formattedDates . size ( ) ; i ++ ) { query . setDate ( searchTerm . getSearchField ( ) + i , new DateTime ( formattedDates . get ( i ) ) . toDate ( ) ) ; q = StringUtils . replace ( q , ":" + searchTerm . getSearchField ( ) + i , "'" + formattedDates . get ( i ) + "'" ) ; } } else if ( searchTerm . getOperator ( ) . isSetOperator ( ) ) { query . setParameterList ( searchTerm . getSearchField ( ) , ( List < Object > ) searchCriteria . get ( searchTerm ) ) ; q = StringUtils . replace ( q , ":" + searchTerm . getSearchField ( ) , "('" + StringUtils . join ( ( List < String > ) searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) , "','" ) + "')" ) ; } else { query . setParameter ( searchTerm . getSearchField ( ) , searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ) ; q = StringUtils . replace ( q , ":" + searchTerm . getSearchField ( ) , "'" + searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) + "'" ) ; } } List < JobEvent > events = query . addEntity ( JobEvent . class ) . setFirstResult ( offset ) . setMaxResults ( limit ) . setCacheable ( false ) . setCacheMode ( CacheMode . IGNORE ) . list ( ) ; session . flush ( ) ; return events ; } catch ( Throwable ex ) { throw new JobException ( ex ) ; } finally { try { HibernateUtil . commitTransaction ( ) ; } catch ( Exception e ) { } } }
Searches for {@link JobEvent} by the given user who matches the given set of
 parameters.
Searches for { @link JobEvent } by the given user who matches the given set of parameters .
//log.debug(q); //			log.debug(q);