1 package ejava.examples.cdiconfig.dao;
2
3 import java.util.List;
4
5 import javax.persistence.EntityManager;
6 import javax.persistence.TypedQuery;
7
8 import ejava.examples.cdiconfig.bo.Job;
9
10 public class JobsDaoImpl implements JobsDao {
11 private EntityManager em;
12
13 public void setEntityManager(EntityManager em) {
14 this.em = em;
15 }
16
17 @Override
18 public void create(Job job) {
19 em.persist(job);
20 }
21
22 @Override
23 public Job getJob(int id) {
24 return em.find(Job.class, id);
25 }
26
27 @Override
28 public List<Job> getJobs(int offset, int limit) {
29 TypedQuery<Job> query = em.createQuery("select t from Job t", Job.class);
30 if (offset>0) { query.setFirstResult(offset); }
31 if (limit>0) { query.setMaxResults(limit); }
32 return query.getResultList();
33 }
34
35 @Override
36 public void delete(Job job) {
37 em.remove(job);
38 }
39
40 }