agave-systems/systems-core/src/main/java/org/iplantc/service/systems/dao/BatchQueueDao.java
/**
     * Searches for {@link BatchQueue}s by the given system who matches the
     * given set of parameters. Permissions are honored in this query.
     *
     * @param systemId
     * @param searchCriteria
     * @param offset
     * @param limit
     * @return
     * @throws SystemException
     */
Searches for  BatchQueues by the given system who matches the
given set of parameters. Permissions are honored in this query.


Searches for BatchQueues by the given system who matches the given set of parameters . Permissions are honored in this query .
@SuppressWarnings("unchecked")
    public List<BatchQueue> findMatching(Long systemId, Map<SearchTerm, Object> searchCriteria, int limit, int offset)
    throws SystemException {
        try 
        {
			Map<String, Class> searchTypeMappings = new BatchQueueSearchFilter().getSearchTypeMappings();
			Session session = getSession();
            session.clear();
            String hql = "SELECT q \n"
                       + "FROM BatchQueue q \n"
                       + "    left join q.executionSystem executionSystem \n"
                       + "WHERE executionSystem.id = :systemId \n";
            for (SearchTerm searchTerm : searchCriteria.keySet()) {
                if (searchCriteria.get(searchTerm) == null 
                        || StringUtils.equalsIgnoreCase(searchCriteria.get(searchTerm).toString(), "null")) 
                {
                    if (searchTerm.getOperator() == SearchTerm.Operator.NEQ ) {
                        hql += "\n       AND       " + String.format(searchTerm.getMappedField(), searchTerm.getPrefix()) + " is not null ";
                    } else if (searchTerm.getOperator() == SearchTerm.Operator.EQ ) {
                        hql += "\n       AND       " + String.format(searchTerm.getMappedField(), searchTerm.getPrefix()) + " is null ";
                    } else {
                        hql += "\n       AND       " + searchTerm.getExpression();
                    }
                } else {
                    hql += "\n       AND       " + searchTerm.getExpression();
                }
            }
            hql += " ORDER BY q.lastUpdated DESC\n";
            String q = hql;
            Query query = session.createQuery(hql)
                                 .setLong("systemId", systemId);
            q = q.replace(":systemId", systemId.toString());
            for (SearchTerm searchTerm : searchCriteria.keySet()) {
                if (searchTerm.getOperator() == SearchTerm.Operator.BETWEEN || searchTerm.getOperator() == SearchTerm.Operator.ON) {
                    List<String> formattedDates = (List<String>)searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm));
                    for(int i=0;i<formattedDates.size(); i++) {
                        query.setString(searchTerm.getSafeSearchField()+i, formattedDates.get(i));
                        q = q.replaceAll(":" + searchTerm.getSafeSearchField(), "'" + formattedDates.get(i) + "'");
                    }
                }
                else if (searchTerm.getOperator().isSetOperator()) 
                {
                    query.setParameterList(searchTerm.getSafeSearchField(), (List<Object>)searchCriteria.get(searchTerm));
                    q = q.replaceAll(":" + searchTerm.getSafeSearchField(), "('" + StringUtils.join((List<String>)searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)), "','") + "')" );
                }
                else if (searchCriteria.get(searchTerm) == null 
                        || StringUtils.equalsIgnoreCase(searchCriteria.get(searchTerm).toString(), "null")
                        && (searchTerm.getOperator() == SearchTerm.Operator.NEQ || searchTerm.getOperator() == SearchTerm.Operator.EQ )) {
                }
                else if (searchTypeMappings.get(searchTerm.getSafeSearchField()) == Date.class ) {
					query.setDate(searchTerm.getSafeSearchField(), (java.util.Date)searchCriteria.get(searchTerm));
					q = q.replaceAll(":" + searchTerm.getSafeSearchField(),
							"'" + searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)) + "'");
				}
				else if (searchTypeMappings.get(searchTerm.getSafeSearchField()) == Integer.class) {
					query.setInteger(searchTerm.getSafeSearchField(), (Integer)searchCriteria.get(searchTerm));
					q = q.replaceAll(":" + searchTerm.getSafeSearchField(),
							"'" + searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)) + "'");
				}
                else 
                {
                    query.setParameter(searchTerm.getSafeSearchField(), 
                            searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)));
                    q = StringUtils.replace(q, ":" + searchTerm.getSafeSearchField(), 
                            Pattern.quote("'" + searchTerm.getOperator().applyWildcards(searchCriteria.get(searchTerm)) + "'"));
                }
            }
            log.debug(q);
            List<BatchQueue> queues = query.setFirstResult(offset).setMaxResults(limit).list();
            session.flush();
            return queues;
        } catch (Throwable ex) {
            throw new SystemException(ex);
        } finally {
            try {
                HibernateUtil.commitTransaction();
            } catch (Exception ignored) {
            }
        }
    }
@ SuppressWarnings ( "unchecked" ) public List < BatchQueue > findMatching ( Long systemId , Map < SearchTerm , Object > searchCriteria , int limit , int offset ) throws SystemException { try { Map < String , Class > searchTypeMappings = new BatchQueueSearchFilter ( ) . getSearchTypeMappings ( ) ; Session session = getSession ( ) ; session . clear ( ) ; String hql = "SELECT q \n" + "FROM BatchQueue q \n" + "    left join q.executionSystem executionSystem \n" + "WHERE executionSystem.id = :systemId \n" ; for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { if ( searchCriteria . get ( searchTerm ) == null || StringUtils . equalsIgnoreCase ( searchCriteria . get ( searchTerm ) . toString ( ) , "null" ) ) { if ( searchTerm . getOperator ( ) == SearchTerm . Operator . NEQ ) { hql += "\n       AND       " + String . format ( searchTerm . getMappedField ( ) , searchTerm . getPrefix ( ) ) + " is not null " ; } else if ( searchTerm . getOperator ( ) == SearchTerm . Operator . EQ ) { hql += "\n       AND       " + String . format ( searchTerm . getMappedField ( ) , searchTerm . getPrefix ( ) ) + " is null " ; } else { hql += "\n       AND       " + searchTerm . getExpression ( ) ; } } else { hql += "\n       AND       " + searchTerm . getExpression ( ) ; } } hql += " ORDER BY q.lastUpdated DESC\n" ; String q = hql ; Query query = session . createQuery ( hql ) . setLong ( "systemId" , systemId ) ; q = q . replace ( ":systemId" , systemId . toString ( ) ) ; for ( SearchTerm searchTerm : searchCriteria . keySet ( ) ) { if ( searchTerm . getOperator ( ) == SearchTerm . Operator . BETWEEN || searchTerm . getOperator ( ) == SearchTerm . Operator . ON ) { List < String > formattedDates = ( List < String > ) searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ; for ( int i = 0 ; i < formattedDates . size ( ) ; i ++ ) { query . setString ( searchTerm . getSafeSearchField ( ) + i , formattedDates . get ( i ) ) ; q = q . replaceAll ( ":" + searchTerm . getSafeSearchField ( ) , "'" + formattedDates . get ( i ) + "'" ) ; } } else if ( searchTerm . getOperator ( ) . isSetOperator ( ) ) { query . setParameterList ( searchTerm . getSafeSearchField ( ) , ( List < Object > ) searchCriteria . get ( searchTerm ) ) ; q = q . replaceAll ( ":" + searchTerm . getSafeSearchField ( ) , "('" + StringUtils . join ( ( List < String > ) searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) , "','" ) + "')" ) ; } else if ( searchCriteria . get ( searchTerm ) == null || StringUtils . equalsIgnoreCase ( searchCriteria . get ( searchTerm ) . toString ( ) , "null" ) && ( searchTerm . getOperator ( ) == SearchTerm . Operator . NEQ || searchTerm . getOperator ( ) == SearchTerm . Operator . EQ ) ) { } else if ( searchTypeMappings . get ( searchTerm . getSafeSearchField ( ) ) == Date . class ) { query . setDate ( searchTerm . getSafeSearchField ( ) , ( java . util . Date ) searchCriteria . get ( searchTerm ) ) ; q = q . replaceAll ( ":" + searchTerm . getSafeSearchField ( ) , "'" + searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) + "'" ) ; } else if ( searchTypeMappings . get ( searchTerm . getSafeSearchField ( ) ) == Integer . class ) { query . setInteger ( searchTerm . getSafeSearchField ( ) , ( Integer ) searchCriteria . get ( searchTerm ) ) ; q = q . replaceAll ( ":" + searchTerm . getSafeSearchField ( ) , "'" + searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) + "'" ) ; } else { query . setParameter ( searchTerm . getSafeSearchField ( ) , searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) ) ; q = StringUtils . replace ( q , ":" + searchTerm . getSafeSearchField ( ) , Pattern . quote ( "'" + searchTerm . getOperator ( ) . applyWildcards ( searchCriteria . get ( searchTerm ) ) + "'" ) ) ; } } log . debug ( q ) ; List < BatchQueue > queues = query . setFirstResult ( offset ) . setMaxResults ( limit ) . list ( ) ; session . flush ( ) ; return queues ; } catch ( Throwable ex ) { throw new SystemException ( ex ) ; } finally { try { HibernateUtil . commitTransaction ( ) ; } catch ( Exception ignored ) { } } }
Searches for {@link BatchQueue}s by the given system who matches the
 given set of parameters.
Searches for { @link BatchQueue } s by the given system who matches the given set of parameters .
// this was explicitly set to 'is null' or 'is not null'