`UpdateCalculator.java`
`01 package trail.entity.update; 02 03 import trail.entity.beans.*; 04 import javax.ejb.*; 05 import javax.persistence.*; 06 import javax.annotation.Resource; 07 import java.util.*; 08 09 @Stateless 10 public class UpdateCalculator implements Calculator { 11 12 @PersistenceContext 13 protected EntityManager em; 14 15 public Collection <TimedRecord> getRecords () { 16 return em.createQuery("from TimedRecord r order by r.id desc").getResultList(); 17 } 18 19 public void updateExchangeRate (double newrate) { 20 Collection <TimedRecord> rc = em.createQuery("from TimedRecord r").getResultList(); 21 for (Iterator iter = rc.iterator(); iter.hasNext();) { 22 TimedRecord r = (TimedRecord) iter.next(); 23 r.setSaving(r.getSaving() * newrate); 24 r.setResult(r.getResult() * newrate); 25 } 26 // em.flush(); 27 } 28 }`