KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > jpetstore > domain > logic > PetStoreImpl


1 package org.springframework.samples.jpetstore.domain.logic;
2
3 import java.util.List JavaDoc;
4
5 import org.springframework.samples.jpetstore.dao.AccountDao;
6 import org.springframework.samples.jpetstore.dao.CategoryDao;
7 import org.springframework.samples.jpetstore.dao.ItemDao;
8 import org.springframework.samples.jpetstore.dao.OrderDao;
9 import org.springframework.samples.jpetstore.dao.ProductDao;
10 import org.springframework.samples.jpetstore.domain.Account;
11 import org.springframework.samples.jpetstore.domain.Category;
12 import org.springframework.samples.jpetstore.domain.Item;
13 import org.springframework.samples.jpetstore.domain.Order;
14 import org.springframework.samples.jpetstore.domain.Product;
15
16 /**
17  * JPetStore primary business object.
18  *
19  * <p>This object makes use of five DAO objects, decoupling it
20  * from the details of working with persistence APIs. Thus
21  * although this application uses iBATIS for data access,
22  * another persistence tool could be dropped in without
23  * breaking this class.
24  *
25  * <p>The DAOs are made available to the instance of this object
26  * using Dependency Injection. (The DAOs are in turn configured
27  * using Dependency Injection.) We use Setter Injection here,
28  * exposing JavaBean setter methods for each DAO. This means there is
29  * a JavaBean "property" for each DAO. In this case the properties
30  * are write-only: there is no getter method to accompany the
31  * setter methods. Getter methods are optional: implement them
32  * only if you want to expose access to the properties in your
33  * business object.
34  *
35  * <p>There is one instance of this class in the JPetStore application.
36  * In Spring terminology, it is a "singleton". This means a
37  * per-Application Context singleton. The factory creates a single
38  * instance; there is no need for a private constructor, static
39  * factory method etc as in the traditional implementation of
40  * the Singleton Design Pattern.
41  *
42  * <p>This is a POJO. It does not depend on any Spring APIs.
43  * It's usable outside a Spring container, and can be instantiated
44  * using new in a JUnit test. However, we can still apply declarative
45  * transaction management to it using Spring AOP.
46  *
47  * <p>This class defines a default transaction attribute for all methods.
48  * Note that this attribute definition is only necessary if using Commons
49  * Attributes auto-proxying (see the "attributes" directory under the root of
50  * JPetStore). No attributes are required with a TransactionFactoryProxyBean,
51  * as in the default applicationContext.xml in the war/WEB-INF directory.
52  *
53  * <p>The following attribute definition uses Commons Attributes attribute syntax.
54  * @@org.springframework.transaction.interceptor.DefaultTransactionAttribute()
55  *
56  * @author Juergen Hoeller
57  * @since 30.11.2003
58  */

59 public class PetStoreImpl implements PetStoreFacade, OrderService {
60
61     private AccountDao accountDao;
62
63     private CategoryDao categoryDao;
64
65     private ProductDao productDao;
66
67     private ItemDao itemDao;
68
69     private OrderDao orderDao;
70
71
72     //-------------------------------------------------------------------------
73
// Setter methods for dependency injection
74
//-------------------------------------------------------------------------
75

76     public void setAccountDao(AccountDao accountDao) {
77         this.accountDao = accountDao;
78     }
79
80     public void setCategoryDao(CategoryDao categoryDao) {
81         this.categoryDao = categoryDao;
82     }
83
84     public void setProductDao(ProductDao productDao) {
85         this.productDao = productDao;
86     }
87
88     public void setItemDao(ItemDao itemDao) {
89         this.itemDao = itemDao;
90     }
91
92     public void setOrderDao(OrderDao orderDao) {
93         this.orderDao = orderDao;
94     }
95
96
97     //-------------------------------------------------------------------------
98
// Operation methods, implementing the PetStoreFacade interface
99
//-------------------------------------------------------------------------
100

101     public Account getAccount(String JavaDoc username) {
102         return this.accountDao.getAccount(username);
103     }
104
105     public Account getAccount(String JavaDoc username, String JavaDoc password) {
106         return this.accountDao.getAccount(username, password);
107     }
108
109     public void insertAccount(Account account) {
110         this.accountDao.insertAccount(account);
111     }
112
113     public void updateAccount(Account account) {
114         this.accountDao.updateAccount(account);
115     }
116
117     public List JavaDoc getUsernameList() {
118         return this.accountDao.getUsernameList();
119     }
120
121     public List JavaDoc getCategoryList() {
122         return this.categoryDao.getCategoryList();
123     }
124
125     public Category getCategory(String JavaDoc categoryId) {
126         return this.categoryDao.getCategory(categoryId);
127     }
128
129     public List JavaDoc getProductListByCategory(String JavaDoc categoryId) {
130         return this.productDao.getProductListByCategory(categoryId);
131     }
132
133     public List JavaDoc searchProductList(String JavaDoc keywords) {
134         return this.productDao.searchProductList(keywords);
135     }
136
137     public Product getProduct(String JavaDoc productId) {
138         return this.productDao.getProduct(productId);
139     }
140
141     public List JavaDoc getItemListByProduct(String JavaDoc productId) {
142         return this.itemDao.getItemListByProduct(productId);
143     }
144
145     public Item getItem(String JavaDoc itemId) {
146         return this.itemDao.getItem(itemId);
147     }
148
149     public boolean isItemInStock(String JavaDoc itemId) {
150         return this.itemDao.isItemInStock(itemId);
151     }
152
153     public void insertOrder(Order order) {
154         this.orderDao.insertOrder(order);
155         this.itemDao.updateQuantity(order);
156     }
157
158     public Order getOrder(int orderId) {
159         return this.orderDao.getOrder(orderId);
160     }
161
162     public List JavaDoc getOrdersByUsername(String JavaDoc username) {
163         return this.orderDao.getOrdersByUsername(username);
164     }
165
166 }
167
Popular Tags