1 package ejava.examples.cdiconfig.ejb;
2
3 import javax.annotation.PostConstruct;
4 import javax.ejb.Remote;
5 import javax.ejb.Stateless;
6 import javax.persistence.EntityManager;
7 import javax.persistence.PersistenceContext;
8
9 import ejava.examples.cdiconfig.bo.Task;
10 import ejava.examples.cdiconfig.dao.TasksDao;
11 import ejava.examples.cdiconfig.dao.TasksDaoImpl;
12
13 @Stateless
14 @Remote(TasksMgmtRemote.class)
15 public class TasksMgmtEJB implements TasksMgmtRemote {
16 @PersistenceContext(unitName="cdi-config")
17 private EntityManager em;
18
19 private TasksDao taskDao;
20
21 @PostConstruct
22 public void init() {
23 taskDao = new TasksDaoImpl();
24 ((TasksDaoImpl)taskDao).setEntityManager(em);
25 }
26
27 @Override
28 public int createTask(Task task) {
29 taskDao.create(task);
30 return task.getId();
31 }
32 }