KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xpetstore > web > webwork > action > product > SearchAction


1 /*
2  * Created on Feb 27, 2003
3  */

4 package xpetstore.web.webwork.action.product;
5
6 import java.util.ArrayList JavaDoc;
7 import java.util.Collection JavaDoc;
8
9 import cirrus.hibernate.Session;
10
11 import xpetstore.domain.Product;
12
13 import xpetstore.web.webwork.action.BaseAction;
14
15
16 /**
17  * @author <a HREF="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
18  *
19  * @webwork.action
20  * name="search"
21  * success="search.vm"
22  */

23 public class SearchAction
24     extends BaseAction
25 {
26     //~ Instance fields --------------------------------------------------------
27

28     private String JavaDoc _keyword = "";
29     private Collection JavaDoc _products = new ArrayList JavaDoc( );
30
31     //~ Methods ----------------------------------------------------------------
32

33     /**
34      * @see webwork.action.ActionSupport#doExecute()
35      */

36     protected String JavaDoc doExecute( )
37         throws Exception JavaDoc
38     {
39         if ( ( _keyword == null ) || ( _keyword.length( ) == 0 ) )
40         {
41             return SUCCESS;
42         }
43
44         Session s = getHibernateSession( );
45         try
46         {
47             String JavaDoc oql = "FROM p IN CLASS " + Product.class + " WHERE" + " ( p.productId LIKE '%" + _keyword + "%' ) OR" + " ( p.name LIKE '%" + _keyword + "%' ) OR" + " ( p.description LIKE '%" + _keyword + "%' )";
48             _products = s.find( oql );
49
50             return SUCCESS;
51         }
52         finally
53         {
54             s.close( );
55         }
56     }
57
58     /**
59      * @return String
60      */

61     public String JavaDoc getKeyword( )
62     {
63         return _keyword;
64     }
65
66     /**
67      * @return Collection
68      */

69     public Collection JavaDoc getProducts( )
70     {
71         return _products;
72     }
73
74     /**
75      * Sets the keyword.
76      * @param keyword The keyword to set
77      */

78     public void setKeyword( String JavaDoc keyword )
79     {
80         _keyword = keyword;
81     }
82
83     /**
84      * Sets the products.
85      * @param products The products to set
86      */

87     public void setProducts( Collection JavaDoc products )
88     {
89         _products = products;
90     }
91 }
92
Popular Tags