1 package org.springframework.samples.jpetstore.dao.ibatis; 2 3 import java.util.List ; 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 26 public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao { 27 28 public Account getAccount(String username) throws DataAccessException { 29 return (Account) getSqlMapClientTemplate().queryForObject("getAccountByUsername", username); 30 } 31 32 public Account getAccount(String username, String 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 getUsernameList() throws DataAccessException { 54 return getSqlMapClientTemplate().queryForList("getUsernameList", null); 55 } 56 57 } 58 | Popular Tags |