Changeset 1515 for raptor-client


Ignore:
Timestamp:
06/06/13 10:39:03 (7 years ago)
Author:
philsmart
Message:

additions to the db access dao classes to allow unique values to be returned.

Location:
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store
Files:
4 edited

Legend:

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

    r1200 r1515  
    7070    public Object queryUnique(String query, Object[] parameters); 
    7171 
     72    /** 
     73     * Runs the query <code>query</code> with the parameters <code>parameters</code> and returns a single unique result. 
     74     * Only the first result is taken even if the query would return more than one result. Concrete implementations of 
     75     * the interface may require the query in a specific, specified, language e.g. HQL or JPQL. 
     76     *  
     77     * @param query the query to run. 
     78     * @param parameters the parameters to substitute into the query string <code>query</code> 
     79     * @return 
     80     */ 
     81    public Object queryForceUnique(String query, Object[] object); 
     82 
    7283} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/DefaultDataConnection.java

    r1445 r1515  
    5454 
    5555    @Override 
    56     public void saveAll(@SuppressWarnings("rawtypes") Collection collection) 
    57             throws DataAccessException { 
     56    public void saveAll(@SuppressWarnings("rawtypes") Collection collection) throws DataAccessException { 
    5857        hibernateTemplate.saveOrUpdateAll(collection); 
    5958    } 
     
    7271    @Override 
    7372    @SuppressWarnings("rawtypes") 
    74     public List runQuery(String query, Object[] parameters, int maxResultSize) 
    75             throws DataAccessException { 
     73    public List runQuery(String query, Object[] parameters, int maxResultSize) throws DataAccessException { 
    7674        hibernateTemplate.setMaxResults(maxResultSize); 
    7775        List result = hibernateTemplate.find(query, parameters); 
     
    9088     */ 
    9189    @SuppressWarnings("rawtypes") 
    92     public List 
    93             runQueryPaged(final String query, final int pageSize, final int pageNumber) 
    94                     throws DataAccessException { 
     90    public List runQueryPaged(final String query, final int pageSize, final int pageNumber) throws DataAccessException { 
    9591        HibernateTemplate template = getHibernateTemplate(); 
    9692        return template.executeFind(new HibernateCallback() { 
    9793            @Override 
    98             public Object doInHibernate(Session session) throws HibernateException, 
    99                     SQLException { 
     94            public Object doInHibernate(Session session) throws HibernateException, SQLException { 
    10095                Query queryToRun = session.createQuery(query); 
    10196                queryToRun.setMaxResults(pageSize); 
     
    106101    } 
    107102 
     103    @SuppressWarnings("unchecked") 
    108104    @Override 
    109     public Object runQueryUnique(String query, Object[] parameters) 
    110             throws DataAccessException { 
     105    public Object runQueryForceUnique(final String query, final Object[] parameters) { 
    111106        if (parameters != null) { 
    112             log.trace("Query to database, {}, with params [{}]", query, 
    113                     Arrays.asList(parameters)); 
     107            log.trace("Query to database, {}, with params [{}]", query, Arrays.asList(parameters)); 
    114108        } else { 
    115109            log.trace("Query to database, {}]", query); 
    116110        } 
    117         Object object = 
    118                 DataAccessUtils.uniqueResult(getHibernateTemplate().find(query, 
    119                         parameters)); 
     111        HibernateTemplate template = getHibernateTemplate(); 
     112        return template.execute(new HibernateCallback() { 
     113            @Override 
     114            public Object doInHibernate(Session session) throws HibernateException, SQLException { 
     115                Query queryToRun = session.createQuery(query); 
     116                queryToRun.setMaxResults(1); 
     117                return queryToRun.uniqueResult(); 
     118            } 
     119        }); 
     120    } 
     121 
     122    @SuppressWarnings("unchecked") 
     123    @Override 
     124    public Object runQueryUnique(String query, Object[] parameters) throws DataAccessException { 
     125        if (parameters != null) { 
     126            log.trace("Query to database, {}, with params [{}]", query, Arrays.asList(parameters)); 
     127        } else { 
     128            log.trace("Query to database, {}]", query); 
     129        } 
     130        Object object = DataAccessUtils.uniqueResult(getHibernateTemplate().find(query, parameters)); 
    120131        return object; 
    121132    } 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/dao/RaptorDataConnection.java

    r1188 r1515  
    101101    public void runUpdate(String query, Object[] parameters) throws DataAccessException; 
    102102 
     103    /** 
     104     * Runs the query <code>query</code> with the parameters <code>parameters</code> and returns a single unique result. 
     105     * Only the first result is taken even if the query would return more than one result. Concrete implementations of 
     106     * the interface may require the query in a specific, specified, language e.g. HQL or JPQL. 
     107     *  
     108     * @param query the query to run. 
     109     * @param parameters the parameters to substitute into the query string <code>query</code> 
     110     * @return 
     111     */ 
     112    public Object runQueryForceUnique(String query, Object[] parameters); 
     113 
    103114} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEventHandler.java

    r1424 r1515  
    5353     * duplicate values 
    5454     */ 
    55     private Set<Event> persistQueue; 
     55    private final Set<Event> persistQueue; 
    5656 
    5757    /** 
     
    7676     * Initialises the entry handler. 
    7777     */ 
     78    @Override 
    7879    public void initialise() { 
    7980        log.info("Persistant entry handler [{}] initialising", this); 
     
    9293    } 
    9394 
     95    @Override 
    9496    public List query(String query, Object[] parameters) { 
    9597        if (parameters != null) { 
     
    101103    } 
    102104 
     105    @Override 
    103106    public Object queryUnique(String query, Object[] parameters) { 
    104107        return dataConnection.runQueryUnique(query, parameters); 
    105108    } 
    106109 
     110    @Override 
     111    public Object queryForceUnique(String query, Object[] parameters) { 
     112        return dataConnection.runQueryForceUnique(query, parameters); 
     113    } 
     114 
     115    @Override 
    107116    public void update(String query, Object[] parameters) throws StorageException { 
    108117        try { 
     
    113122    } 
    114123 
     124    @Override 
    115125    public List query(String query, Object[] parameters, int maxNoResults) { 
    116126        log.debug("Running query [{}]", query); 
     
    118128    } 
    119129 
     130    @Override 
    120131    public void save(Event event) throws StorageException { 
    121132        try { 
     
    126137    } 
    127138 
     139    @Override 
    128140    public void saveAll(Collection object) throws StorageException { 
    129141        try { 
     
    145157     * @throws 
    146158     */ 
     159    @Override 
    147160    public void addEvents(final List<Event> entries) throws StorageException { 
    148161        log.info("Persistent Entry Handler has {} entries, with {} new entries inputted, and {} exist in the queue", 
     
    174187    } 
    175188 
     189    @Override 
    176190    public boolean addEvent(final Event event) { 
    177191 
     
    191205    } 
    192206 
     207    @Override 
    193208    public List<Event> getEvents() { 
    194209        List<Event> runQuery = dataConnection.runQuery("from Event", null); 
     
    196211    } 
    197212 
     213    @Override 
    198214    public void removeAllEvents() { 
    199215        // no-op method 
     
    215231     * where table joins are required to sum all subclasses of Event. 
    216232     */ 
     233    @Override 
    217234    public long getNumberOfEvents() { 
    218235        if (optimiseCountQueries == true) { 
     
    236253    } 
    237254 
     255    @Override 
    238256    public DateTime getLatestEventTime() { 
    239257        return (DateTime) dataConnection.runQueryUnique("select max(eventTime) from Event", null); 
     
    271289     * This is a no-op method for this event handler 
    272290     */ 
     291    @Override 
    273292    public void removeEventsBefore(DateTime earliestReleaseTime, Set<Integer> latestEqualEntries) { 
    274293        // no op method. 
Note: See TracChangeset for help on using the changeset viewer.