KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > jpetstore > dao > ibatis > SqlMapAccountDao


1 package org.springframework.samples.jpetstore.dao.ibatis;
2
3 import java.util.List JavaDoc;
4
5 import org.springframework.dao.DataAccessException;
6 import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
7 import org.springframework.samples.jpetstore.dao.AccountDao;
8 import org.springframework.samples.jpetstore.domain.Account;
9
10 /**
11  * In this and other DAOs in this package, a DataSource property
12  * is inherited from the SqlMapClientDaoSupport convenience superclass
13  * supplied by Spring. DAOs don't need to extend such superclasses,
14  * but it saves coding in many cases. There are analogous superclasses
15  * for JDBC (JdbcDaoSupport), Hibernate (HibernateDaoSupport),
16  * JDO (JdoDaoSupport) etc.
17  *
18  * <p>This and other DAOs are configured using Dependency Injection.
19  * This means, for example, that Spring can source the DataSource
20  * from a local class, such as the Commons DBCP BasicDataSource,
21  * or from JNDI, concealing the JNDI lookup from application code.
22  *
23  * @author Juergen Hoeller
24  * @author Colin Sampaleanu
25  */

26 public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
27
28   public Account getAccount(String JavaDoc username) throws DataAccessException {
29     return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsername", username);
30   }
31
32   public Account getAccount(String JavaDoc username, String JavaDoc password) throws DataAccessException {
33     Account account = new Account();
34     account.setUsername(username);
35     account.setPassword(password);
36     return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsernameAndPassword", account);
37   }
38
39   public void insertAccount(Account account) throws DataAccessException {
40     getSqlMapClientTemplate().insert("insertAccount", account);
41     getSqlMapClientTemplate().insert("insertProfile", account);
42     getSqlMapClientTemplate().insert("insertSignon", account);
43   }
44
45   public void updateAccount(Account account) throws DataAccessException {
46     getSqlMapClientTemplate().update("updateAccount", account, 1);
47     getSqlMapClientTemplate().update("updateProfile", account, 1);
48     if (account.getPassword() != null && account.getPassword().length() > 0) {
49       getSqlMapClientTemplate().update("updateSignon", account, 1);
50     }
51   }
52  
53     public List JavaDoc getUsernameList() throws DataAccessException {
54         return getSqlMapClientTemplate().queryForList("getUsernameList", null);
55     }
56
57 }
58
Popular Tags