Changeset 1014 for raptor-client


Ignore:
Timestamp:
06/10/11 17:07:19 (9 years ago)
Author:
philsmart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/StorageEngine.java

    r1010 r1014  
    2222import java.util.List; 
    2323 
     24import org.hibernate.HibernateException; 
     25import org.hibernate.QueryException; 
    2426import org.joda.time.DateTime; 
    2527import org.slf4j.Logger; 
    2628import org.slf4j.LoggerFactory; 
     29import org.springframework.dao.DataAccessException; 
     30import org.springframework.orm.hibernate3.HibernateQueryException; 
    2731 
    2832import uk.ac.cardiff.model.event.Event; 
     33import uk.ac.cardiff.model.wsmodel.Suggestion; 
    2934import uk.ac.cardiff.raptor.store.EntryHandler; 
    3035import uk.ac.cardiff.raptor.store.dao.StorageException; 
     
    168173        return attributeAssociationEngine; 
    169174    } 
    170  
    171         public List<String> getKnownResourceIds() { 
    172                 List results = entryHandler.query("select resourceId from Event group by (resourceId)"); 
    173                 ArrayList<String> allResources = new ArrayList<String>();                
    174                 for (Object result : results){ 
    175                         if (result instanceof String){ 
    176                                 allResources.add((String)result); 
    177                         } 
    178                 } 
    179                 return allResources; 
    180                  
    181         } 
     175         
     176    /** 
     177     * Returns the possible values that each of the input field names can take 
     178     *  
     179     * @param possibleFieldNameValuesList 
     180     * @return 
     181     */ 
     182    public List<Suggestion> getPossibleValuesFor(List<String> possibleFieldNameValuesList) { 
     183        ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); 
     184         
     185        for (String fieldName : possibleFieldNameValuesList){ 
     186            try{ 
     187            List results = entryHandler.query("select "+fieldName+" from Event group by ("+fieldName+")"); 
     188            for (Object result : results){ 
     189                if (result instanceof String){ 
     190                        Suggestion suggestion = new Suggestion(); 
     191                        suggestion.setBase(fieldName); 
     192                        suggestion.setValue((String)result); 
     193                        suggestions.add(suggestion); 
     194                } 
     195            } 
     196            } 
     197            catch(RuntimeException e){ 
     198                log.warn("Caught a runtime exception. Error trying to find possible values for {}, probably nothing to worry about",fieldName); 
     199            } 
     200 
     201        } 
     202         
     203         
     204        return suggestions; 
     205    } 
    182206 
    183207 
Note: See TracChangeset for help on using the changeset viewer.