Changeset 677 for raptor-client


Ignore:
Timestamp:
04/12/11 23:35:04 (9 years ago)
Author:
philsmart
Message:
 
File:
1 edited

Legend:

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

    r673 r677  
    2121import java.util.ArrayList; 
    2222import java.util.Arrays; 
     23import java.util.HashSet; 
    2324import java.util.LinkedHashSet; 
    2425import java.util.List; 
     
    6768         * resilience if events can not be immediately stored, for example 
    6869         * failure of the underlying persistent store */ 
    69         private Set<Event> storeQueue; 
     70        private Set<Event> persistQueue; 
    7071 
    7172        public PersistantEntryHandler(RaptorDataConnection dataConnection) { 
    7273                this.setDataConnection(dataConnection); 
     74                persistQueue = new HashSet<Event>(); 
    7375 
    7476        } 
     
    9395                log.info("Loading entries from main datastore"); 
    9496                List<Event> entriesAsList = dataConnection.runQuery("from Event", null); 
    95                 log.info("MUA has loaded " + entriesAsList.size() + " entries from main datastore"); 
     97                log.info("MUA has loaded {} entries from main datastore",entriesAsList.size()); 
    9698                entries = new LinkedHashSet<Event>(entriesAsList); 
    9799        } 
     
    112114 
    113115        /** 
    114          * 
     116         * The <code>entries</code> are stored in the <code>persistQueue</code> until they are persisted. If an exception is thrown before 
     117         * they are persisted, they remain in the <code>persistQueue</code>.  
    115118         * 
    116119         * @param entries the list of events that are to be stored 
     
    118121         */ 
    119122        public void addEntries(List<Event> entries) throws StorageException{ 
    120                 log.info("Persistent Entry Handler has {} entries, with {} new entries inputted", this.getNumberOfEntries(), entries.size()); 
     123                log.info("Persistent Entry Handler has {} entries, with {} new entries inputted, and {} exist in the queue", 
     124                                new Object[]{this.getNumberOfEntries(), entries.size(),persistQueue.size()}); 
     125                 
    121126                int duplicates = 0; 
     127                persistQueue.addAll(entries); 
    122128                List<Event> persist = new ArrayList<Event>(); 
    123                 for (Event event : entries) { 
     129                 
     130                for (Event event : persistQueue) { 
    124131                        int hashcode = 0; 
    125132                        try { 
     
    129136                            continue; 
    130137                        } 
    131                         //int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + event.getClass().getSimpleName() 
    132                         //              + " where eventTime = '" + event.getEventTime() + "' and hashCode ='" + hashcode + "'", null)).intValue(); 
    133                         Object[] parameters= new Object[]{hashcode}; 
    134                         log.debug("Values: "+Arrays.toString(parameters)); 
    135                         int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique("select count(*) from " + event.getClass().getSimpleName()+" where eventTime = '" + event.getEventTime() + "'"+ 
    136                                         "and hashCode =?", parameters)).intValue(); 
     138                        String query ="select count(*) from "+event.getClass().getSimpleName()+" where eventTime = ? and hashCode =?"; 
     139                        Object[] parameters= new Object[]{event.getEventTime().toDate(),hashcode}; 
     140                        int numberOfDuplicates = ((Integer) dataConnection.runQueryUnique(query, parameters)).intValue(); 
    137141 
    138142                        if (numberOfDuplicates == 0){ 
     
    143147                        } 
    144148                } 
     149                 
    145150                try{ 
    146151                    dataConnection.saveAll(persist); 
     
    149154                    throw new StorageException("Could not persist events",e); 
    150155                } 
    151  
     156                persistQueue.clear(); 
    152157                log.info("Total No. of Entries after addition = {}, finding {} duplicates", this.getNumberOfEntries(), duplicates); 
    153158        } 
Note: See TracChangeset for help on using the changeset viewer.