1 16 package johnmammen.betterpetshop.service.dao.hibernate; 17 18 import java.sql.SQLException ; 19 import java.util.List ; 20 import java.util.Set ; 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 37 public class ProductDAO extends HibernateDaoSupport implements IProductDAO { 38 39 42 public ProductDAO() { 43 super(); 44 45 } 46 47 52 public IProduct[] getProducts() throws SQLException { 53 return null; 55 } 56 57 62 public IItem[] getItemsByProduct(String prodid) { 63 IItem[] items = null; 64 65 List itmelist = getHibernateTemplate().find("from Item i where i.product.productid =?",prodid); 66 items = new IItem[itmelist.size()]; 67 Object tempObj[]= itmelist.toArray(); 68 for(int i=0; i< tempObj.length;i++) { 69 items[i] = (IItem) tempObj[i]; 71 } 72 73 return items; 74 } 75 76 81 public IItem getItem(String itemID) { 82 IItem item = (IItem) getHibernateTemplate().load( 83 Item.class, itemID); 84 return item; 85 } 86 87 92 public IProduct[] findByCategory(String catid) throws DataAccessException { 93 IProduct[] products = null; 94 97 Categorydetail cat = (Categorydetail) getHibernateTemplate().load( 98 Categorydetail.class, catid); 99 Set prodlist = cat.getProducts(); 100 if (prodlist != null && !prodlist.isEmpty()) { 101 products = new IProduct[prodlist.size()]; 102 Object tempObj[]= prodlist.toArray(); 103 for(int i=0; i< tempObj.length;i++) { 104 products[i] = (IProduct) tempObj[i]; 106 } 107 } 108 return products; 109 } 110 111 116 public IProduct[] findBySearchCriteria(String searchText) { 117 searchText = "%" + searchText + "%"; 118 IProduct[] products = null; 119 List 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 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 142 public IInventory[] getInventory(String csvItemList) { 143 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 |