1 16 package johnmammen.betterpetshop.service.dao.hibernate; 17 18 import java.util.List ; 19 20 import johnmammen.betterpetshop.bo.Useraccount; 21 import johnmammen.betterpetshop.service.dao.ICustomerDAO; 22 import net.sf.hibernate.Hibernate; 23 import net.sf.hibernate.type.Type; 24 25 import org.apache.tapestry.pets.domain.model.ICustomer; 26 import org.apache.tapestry.pets.domain.model.IUserLogin; 27 import org.springframework.orm.hibernate.support.HibernateDaoSupport; 28 29 33 public class CustomerDAO extends HibernateDaoSupport implements ICustomerDAO { 34 35 public CustomerDAO() { 36 super(); 37 38 } 39 40 45 public ICustomer login(String username, String password) { 46 ICustomer cust = null; 53 List custList = getHibernateTemplate().find( 54 "from Useraccount u where u.userid=? and u.pwd=?", 55 new Object [] { username, password}, 56 new Type[] { Hibernate.STRING, Hibernate.STRING}); 57 if (custList != null && !custList.isEmpty()) { 58 cust = (ICustomer) custList.get(0); 59 60 } 61 62 return cust; 63 64 } 65 66 71 public ICustomer accountInfo(String userID) { 72 73 ICustomer c = null; 74 c = (ICustomer) this.getHibernateTemplate().load(Useraccount.class, 75 userID); 76 77 return c; 78 } 79 80 86 public boolean add(ICustomer newcustomer, IUserLogin userLogin) { 87 boolean isAdded = false; 88 try { 89 newcustomer.setPwd(userLogin.getPassword()); 90 this.getHibernateTemplate().save(newcustomer); 91 isAdded = true; 92 93 } catch (Exception e) { 94 isAdded = false; 95 } 96 97 return isAdded; 98 99 } 100 101 public void updateAccount(ICustomer customer) { 102 } 108 109 } | Popular Tags |