KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > johnmammen > betterpetshop > service > dao > hibernate > CustomerDAO


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

16 package johnmammen.betterpetshop.service.dao.hibernate;
17
18 import java.util.List JavaDoc;
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 /**
30  * @author admin
31  *
32  */

33 public class CustomerDAO extends HibernateDaoSupport implements ICustomerDAO {
34
35     public CustomerDAO() {
36         super();
37
38     }
39
40     /*
41      * (non-Javadoc)
42      *
43      * @see johnmammen.betterpetshop.service.dao.ICustomerDAO#login()
44      */

45     public ICustomer login(String JavaDoc username, String JavaDoc password) {
46         // ICustomer cust = (ICustomer) this.getHibernateTemplate().load(
47
// Useraccount.class, username);
48
// if (cust != null)
49
// this.logger.debug("Got customer " + cust.getEmail());
50
// else
51
// logger.debug("Customer is null ");
52
ICustomer cust = null;
53         List JavaDoc custList = getHibernateTemplate().find(
54                 "from Useraccount u where u.userid=? and u.pwd=?",
55                 new Object JavaDoc[] { 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     /*
67      * (non-Javadoc)
68      *
69      * @see johnmammen.betterpetshop.service.dao.ICustomerDAO#accountInfo(java.lang.String)
70      */

71     public ICustomer accountInfo(String JavaDoc userID) {
72
73         ICustomer c = null;
74         c = (ICustomer) this.getHibernateTemplate().load(Useraccount.class,
75                 userID);
76
77         return c;
78     }
79
80     /*
81      * (non-Javadoc)
82      *
83      * @see johnmammen.betterpetshop.service.dao.ICustomerDAO#add(org.apache.tapestry.pets.domain.model.ICustomer,
84      * org.apache.tapestry.pets.domain.model.IUserLogin)
85      */

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 JavaDoc e) {
94             isAdded = false;
95         }
96
97         return isAdded;
98
99     }
100
101     public void updateAccount(ICustomer customer) {
102         //String sql = SQLStrings.getString("upAccountUpdate");
103
//upAccountUpdate=UPDATE useraccount SET email = ?, firstname = ?,
104
// lastname = ?, addr1 = ?, addr2 = ?, city = ?, state = ?, zip = ?,
105
// country = ?, phone = ? , langpref = ?, favcategory = ?, mylistopt =
106
// ?, banneropt = ? WHERE (userid = ?);
107
}
108
109 }
Popular Tags