1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 /***
17 * User: Clinton Begin
18 * Date: Jul 13, 2003
19 * Time: 7:20:54 PM
20 */
21 package com.ibatis.jpetstore.persistence.sqlmapdao;
22
23 import com.ibatis.common.util.PaginatedList;
24 import com.ibatis.dao.client.DaoManager;
25 import com.ibatis.jpetstore.domain.Product;
26 import com.ibatis.jpetstore.persistence.iface.ProductDao;
27
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.StringTokenizer;
31
32 public class ProductSqlMapDao extends BaseSqlMapDao implements ProductDao {
33
34 public ProductSqlMapDao(DaoManager daoManager) {
35 super(daoManager);
36 }
37
38 public PaginatedList getProductListByCategory(String categoryId) {
39 return queryForPaginatedList("getProductListByCategory", categoryId, PAGE_SIZE);
40 }
41
42 public Product getProduct(String productId) {
43 return (Product) queryForObject("getProduct", productId);
44 }
45
46 public PaginatedList searchProductList(String keywords) {
47 Object parameterObject = new ProductSearch(keywords);
48 return queryForPaginatedList("searchProductList", parameterObject, PAGE_SIZE);
49 }
50
51
52
53 public static class ProductSearch {
54 private List keywordList = new ArrayList();
55
56 public ProductSearch(String keywords) {
57 StringTokenizer splitter = new StringTokenizer(keywords, " ", false);
58 while (splitter.hasMoreTokens()) {
59 keywordList.add("%" + splitter.nextToken() + "%");
60 }
61 }
62
63 public List getKeywordList() {
64 return keywordList;
65 }
66 }
67
68 }