KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > merge > bean > CustomerDAOBean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.merge.bean;
8
9 import java.util.List JavaDoc;
10 import javax.ejb.Remote JavaDoc;
11 import javax.ejb.Stateless JavaDoc;
12 import javax.persistence.EntityManager;
13 import javax.persistence.PersistenceContext;
14
15 @Stateless JavaDoc
16 @Remote JavaDoc(CustomerDAO.class)
17 public class CustomerDAOBean implements CustomerDAO
18 {
19    @PersistenceContext
20    private EntityManager manager;
21
22
23    public int create(String JavaDoc first, String JavaDoc last, String JavaDoc street, String JavaDoc city, String JavaDoc state, String JavaDoc zip)
24    {
25       Customer customer = new Customer(first, last, street, city, state, zip);
26       manager.persist(customer);
27       return customer.getId();
28    }
29
30    public Customer find(int id)
31    {
32       return manager.find(Customer.class, id);
33    }
34
35    public List JavaDoc findByLastName(String JavaDoc name)
36    {
37       return manager.createQuery("from Customer c where c.last = :name").setParameter("name", name).getResultList();
38    }
39
40    public void merge(Customer c)
41    {
42       manager.merge(c);
43    }
44 }
45
Popular Tags