View Javadoc
1   package ejava.examples.ejbwar.inventory.rmi;
2   
3   import javax.ejb.Stateless;
4   import javax.inject.Inject;
5   
6   import org.slf4j.Logger;
7   import org.slf4j.LoggerFactory;
8   
9   import ejava.examples.ejbwar.inventory.bo.Categories;
10  import ejava.examples.ejbwar.inventory.bo.Category;
11  import ejava.examples.ejbwar.inventory.bo.Product;
12  import ejava.examples.ejbwar.inventory.bo.Products;
13  import ejava.examples.ejbwar.inventory.ejb.InventoryMgmtEJB;
14  
15  /**
16   * This EJB acts as a remote facade for the InventoryEJB business logic.
17   */
18  @Stateless
19  public class InventoryMgmtRMIEJB implements InventoryMgmtRemote {
20  	private static final Logger logger = LoggerFactory.getLogger(InventoryMgmtRMIEJB.class);
21  	
22  	@Inject
23  	private InventoryMgmtEJB ejb;
24  
25  	@Override
26  	public Categories findCategoryByName(String name, int offset, int limit) {
27  		logger.debug("findCategoryByName({})", name);
28  		return ejb.findCategoryByName(name, offset, limit);
29  	}
30  
31  	@Override
32  	public boolean deleteCategory(int id) {
33  		logger.debug("deleteCategory({})", id);
34  		ejb.deleteCategory(id);
35  		return true;
36  	}
37  
38  	@Override
39  	public Products findProductsByName(String name, int offset, int limit) {
40  		logger.debug("findProductByName({})", name);
41  		return ejb.findProductByName(name, offset, limit);
42  	}
43  
44  	@Override
45  	public boolean deleteProduct(int id) {
46  		logger.debug("deleteProduct({})", id);
47  		Product p = ejb.getProduct(id);
48  		if (p!=null) {
49  			ejb.deleteProduct(p);
50  		}
51  		return true;
52  	}
53  
54  	@Override
55  	public Product createProduct(Product product, String category) {
56  		logger.debug("createProduct({})", product);
57  		return ejb.addProduct(product, category);
58  	}
59  
60  	@Override
61  	public Product getProduct(int id) {
62  		logger.debug(String.format("getProduct(%d)", id));
63  		return ejb.getProduct(id);
64  	}
65  
66  	@Override
67  	public Category getCategory(int id) {
68  		logger.debug("getCategory({})", id);
69  		Category category = ejb.getCategory(id);
70  		//hydrate the object before returning
71  		category.getProducts().size();
72  		return category;
73  	}
74  
75  	@Override
76  	public Product updateProduct(Product product) {
77  		logger.debug("updateProduct({})", product);
78  		return ejb.updateProduct(product);
79  	}
80  }