View Javadoc
1   package ejava.examples.ejbwar.customer.ejb;
2   
3   import java.util.List;
4   
5   import javax.ejb.Stateless;
6   import javax.inject.Inject;
7   
8   import org.slf4j.Logger;
9   import org.slf4j.LoggerFactory;
10  
11  import ejava.examples.ejbwar.customer.bo.Customer;
12  import ejava.examples.ejbwar.customer.bo.Customers;
13  import ejava.examples.ejbwar.customer.dao.CustomerDAO;
14  
15  @Stateless
16  public class CustomerMgmtEJB implements CustomerMgmtLocal, CustomerMgmtRemote {
17  	private static final Logger log = LoggerFactory.getLogger(CustomerMgmtEJB.class);
18  	
19  	@Inject
20  	private CustomerDAO dao;
21  	
22  	@Override
23  	public Customer addCustomer(Customer customer) {
24  		log.debug("addCustomer({})", customer);
25  		dao.createCustomer(customer);
26  		return customer;
27  	}
28  
29  	@Override
30  	public Customers findCustomersByName(String firstName, String lastName,
31  			int offset, int limit) {
32  		log.debug("findCustomerByName({}, {}, {}, {})", 
33  				firstName, lastName, offset, limit);
34  		List<Customer> customers = dao.findCustomerByName(firstName, lastName, offset, limit);
35  		for (Customer c: customers) {
36  			//hydrate each instance
37  			c.toString();
38  		}
39  		return new Customers(customers, offset, limit);
40  	}
41  	
42  	@Override
43  	public Customer getCustomer(int id) {
44  		log.debug("getCustomer({})", id);
45  		return dao.getCustomer(id);
46  	}
47  
48  	@Override
49  	public void deleteCustomer(int id) {
50  		log.debug("deleteCustomer({})", id);
51  		Customer customer = dao.getCustomer(id);
52  		if (customer != null) {
53  			dao.deleteCustomer(customer);
54  		}
55  	}
56  
57  }