KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > secondary > 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.secondary.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 import javax.persistence.PersistenceContext;
15
16 @Stateless JavaDoc
17 @Remote JavaDoc(CustomerDAO.class)
18 public class CustomerDAOBean implements CustomerDAO
19 {
20    @PersistenceContext
21    private EntityManager manager;
22
23
24    public int create(String JavaDoc first, String JavaDoc last, String JavaDoc street, String JavaDoc city, String JavaDoc state, String JavaDoc zip)
25    {
26       Customer customer = new Customer(first, last, street, city, state, zip);
27       manager.persist(customer);
28       return customer.getId();
29    }
30
31    public Customer find(int id)
32    {
33       return manager.find(Customer.class, id);
34    }
35
36    public List JavaDoc findByLastName(String JavaDoc name)
37    {
38       return manager.createQuery("from Customer c where c.last = :name").setParameter("name", name).getResultList();
39    }
40
41    public void merge(Customer c)
42    {
43       manager.merge(c);
44    }
45 }
46
Popular Tags