View Javadoc

1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of 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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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    /* Inner Classes */
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  }