KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > johnmammen > betterpetshop > service > dao > hibernate > ProductDAO


1 /*
2  * Copyright 2004 John S. Mammen
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package johnmammen.betterpetshop.service.dao.hibernate;
17
18 import java.sql.SQLException JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import johnmammen.betterpetshop.bo.Categorydetail;
23 import johnmammen.betterpetshop.bo.Item;
24 import johnmammen.betterpetshop.service.dao.IProductDAO;
25
26 import org.apache.tapestry.pets.domain.model.IInventory;
27 import org.apache.tapestry.pets.domain.model.IItem;
28 import org.apache.tapestry.pets.domain.model.IProduct;
29 import org.apache.tapestry.pets.domain.model.pojo.Inventory;
30 import org.springframework.dao.DataAccessException;
31 import org.springframework.orm.hibernate.support.HibernateDaoSupport;
32
33 /**
34  * @author admin
35  *
36  */

37 public class ProductDAO extends HibernateDaoSupport implements IProductDAO {
38
39     /**
40      *
41      */

42     public ProductDAO() {
43         super();
44
45     }
46
47     /*
48      * (non-Javadoc)
49      *
50      * @see johnmammen.betterpetshop.service.dao.IProductDAO#getProducts()
51      */

52     public IProduct[] getProducts() throws SQLException JavaDoc {
53        // (IProduct) getHibernateTemplate().loadAll(Product.class);
54
return null;
55     }
56
57     /*
58      * (non-Javadoc)
59      *
60      * @see johnmammen.betterpetshop.service.dao.IProductDAO#getItemsByProduct(java.lang.String)
61      */

62     public IItem[] getItemsByProduct(String JavaDoc prodid) {
63         IItem[] items = null;
64
65         List JavaDoc itmelist = getHibernateTemplate().find("from Item i where i.product.productid =?",prodid);
66         items = new IItem[itmelist.size()];
67         Object JavaDoc tempObj[]= itmelist.toArray();
68         for(int i=0; i< tempObj.length;i++) {
69             //System.out.println(";;;;;;;;;;;;;Getting categorey "+catid+ " ;;;;;"+prodlist.size());
70
items[i] = (IItem) tempObj[i];
71         }
72
73         return items;
74     }
75
76     /*
77      * (non-Javadoc)
78      *
79      * @see johnmammen.betterpetshop.service.dao.IProductDAO#getItem(java.lang.String)
80      */

81     public IItem getItem(String JavaDoc itemID) {
82         IItem item = (IItem) getHibernateTemplate().load(
83                 Item.class, itemID);
84         return item;
85     }
86
87     /*
88      * (non-Javadoc)
89      *
90      * @see johnmammen.betterpetshop.service.dao.IProductDAO#findByCategory(java.lang.String)
91      */

92     public IProduct[] findByCategory(String JavaDoc catid) throws DataAccessException {
93         IProduct[] products = null;
94         // List prodlist = this.getHibernateTemplate().find(
95
// "from Product product where product.categorydetail.catid=?", catid);
96

97         Categorydetail cat = (Categorydetail) getHibernateTemplate().load(
98                 Categorydetail.class, catid);
99         Set JavaDoc prodlist = cat.getProducts();
100         if (prodlist != null && !prodlist.isEmpty()) {
101             products = new IProduct[prodlist.size()];
102             Object JavaDoc tempObj[]= prodlist.toArray();
103             for(int i=0; i< tempObj.length;i++) {
104                 //System.out.println(";;;;;;;;;;;;;Getting categorey "+catid+ " ;;;;;"+prodlist.size());
105
products[i] = (IProduct) tempObj[i];
106             }
107         }
108         return products;
109     }
110
111     /*
112      * (non-Javadoc)
113      *
114      * @see johnmammen.betterpetshop.service.dao.IProductDAO#findBySearchCriteria(java.lang.String)
115      */

116     public IProduct[] findBySearchCriteria(String JavaDoc searchText) {
117         searchText = "%" + searchText + "%";
118         IProduct[] products = null;
119         List JavaDoc prodlist = getHibernateTemplate()
120                 .find(
121                         "from Product product where product.productdetail.name like ?",
122                         searchText);
123
124         if (prodlist != null && !prodlist.isEmpty()) {
125             products = new IProduct[prodlist.size()];
126             Object JavaDoc tempObj[]= prodlist.toArray();
127             for (int i = 0; i < prodlist.size(); i++) {
128                 products[i] = (IProduct) tempObj[i];
129
130             }
131
132         }
133
134         return products;
135     }
136
137     /*
138      * (non-Javadoc)
139      *
140      * @see johnmammen.betterpetshop.service.dao.IProductDAO#getInventory(java.lang.String)
141      */

142     public IInventory[] getInventory(String JavaDoc csvItemList) {
143         //TO-DO
144
IInventory[] inventory = new Inventory[1];
145         IInventory inv = new Inventory();
146         inv.setItemID("TEST");
147         inv.setQty(100);
148         inventory[0] = inv;
149
150         return inventory;
151     }
152
153 }
Popular Tags