01 package trail.entity.query;
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 QueryCalculator implements Calculator {
11
12 @PersistenceContext
13 protected EntityManager em;
14
15 public Collection <Fund> getFunds () {
16 return em.createQuery("from Fund f").getResultList();
17 }
18 public Collection <Investor> getInvestors () {
19 return em.createQuery("from Investor p").getResultList();
20 }
21 public Collection <TimedRecord> getRecords () {
22 return em.createQuery("from TimedRecord r order by r.id desc").getResultList();
23 }
24 public Collection <TimedRecord> filterRecords (double low, double high) {
25 return em.createQuery(
26 "from TimedRecord r where r.result > :low AND r.result < :high")
27 .setParameter ("low", new Double (low))
28 .setParameter ("high", new Double (high))
29 .getResultList();
30 }
31
32 }
|