📄 sqlmapaccountdao.java
字号:
/*
* Created on 2004-9-28
* Author: Xuefeng, Copyright (C) 2004, Xuefeng.
*/
package org.crystalblog.dao.ibatis;
import java.util.*;
import java.sql.SQLException;
import com.ibatis.sqlmap.client.*;
import org.crystalblog.dao.AccountDao;
import org.crystalblog.domain.Account;
import org.crystalblog.exception.*;
/**
* @author Xuefeng
*/
public class SqlMapAccountDao implements AccountDao {
private SqlMapClient sqlMap = SqlConfig.getSqlMapInstance();
public Account getAccount(String username) throws QueryException {
try {
return (Account)sqlMap.queryForObject("getAccountByUsername", username);
}
catch(SQLException sqle) {
throw new QueryException(sqle);
}
}
public Account getAccount(int accountId) throws QueryException {
try {
return (Account)sqlMap.queryForObject("getAccount", new Integer(accountId));
}
catch(SQLException sqle) {
throw new QueryException(sqle);
}
}
public List getRecentAccounts(int num) throws QueryException {
try {
return sqlMap.queryForList("getRecentAccounts", null, 0, num);
}
catch(SQLException sqle) {
throw new QueryException(sqle);
}
}
public Account getAccountByArticle(int articleId) throws QueryException {
try {
return (Account)sqlMap.queryForObject("getAccountByArticle", new Integer(articleId));
}
catch(SQLException sqle) {
throw new QueryException(sqle);
}
}
public Account getAccountByCategory(int categoryId) throws QueryException {
try {
return (Account)sqlMap.queryForObject("getAccountByCategory", new Integer(categoryId));
}
catch(SQLException sqle) {
throw new QueryException(sqle);
}
}
public void createAccount(Account account) throws CreateException {
try {
sqlMap.insert("createAccount", account);
}
catch(SQLException sqle) {
throw new CreateException(sqle);
}
}
public void updateAccount(Account account) throws UpdateException {
try {
sqlMap.update("updateAccount", account);
}
catch(SQLException sqle) {
throw new UpdateException(sqle);
}
}
public void deleteAccount(int accountId) throws DeleteException {
// TODO Auto-generated method stub
throw new RuntimeException("Code is not finished.");
}
public void lockAccount(int accountId) throws UpdateException {
// TODO Auto-generated method stub
throw new RuntimeException("Code is not finished.");
}
public void changePassword(int accountId, String password) throws UpdateException {
try {
Map map = new HashMap();
map.put("accountId", new Integer(accountId));
map.put("password", password);
sqlMap.update("changePassword", map);
}
catch(SQLException sqle) {
throw new RuntimeException("Change password failed: " + sqle);
}
}
public void sendMessage(int accountId, String sender, String address, String subject, String msg) {
// TODO Auto-generated method stub
throw new RuntimeException("Code is not finished.");
}
public int loginAccount(String username, String password) throws AuthorizationException {
Integer I;
try {
Map map = new HashMap();
map.put("username", username);
map.put("password", password);
I = (Integer)sqlMap.queryForObject("login", map);
if(I==null)
throw new AuthorizationException("Login failed: Invalid username or password.");
return I.intValue();
}
catch(SQLException sqle) {
throw new AuthorizationException("Login failed: " + sqle);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -