1 4 package xpetstore.web.webwork.action.product; 5 6 import java.util.ArrayList ; 7 import java.util.Collection ; 8 9 import cirrus.hibernate.Session; 10 11 import xpetstore.domain.Product; 12 13 import xpetstore.web.webwork.action.BaseAction; 14 15 16 23 public class SearchAction 24 extends BaseAction 25 { 26 28 private String _keyword = ""; 29 private Collection _products = new ArrayList ( ); 30 31 33 36 protected String doExecute( ) 37 throws Exception 38 { 39 if ( ( _keyword == null ) || ( _keyword.length( ) == 0 ) ) 40 { 41 return SUCCESS; 42 } 43 44 Session s = getHibernateSession( ); 45 try 46 { 47 String 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 61 public String getKeyword( ) 62 { 63 return _keyword; 64 } 65 66 69 public Collection getProducts( ) 70 { 71 return _products; 72 } 73 74 78 public void setKeyword( String keyword ) 79 { 80 _keyword = keyword; 81 } 82 83 87 public void setProducts( Collection products ) 88 { 89 _products = products; 90 } 91 } 92 | Popular Tags |