KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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