基于J2EE Struts框架的课程设计实训项目《BBS论坛系统》——针对项目中用户信息的数据访问组件及单元测试

  • 格式:pdf
  • 大小:373.21 KB
  • 文档页数:50

杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料

杨教授大学堂,版权所有,盗版必究。 1/50页 基于J2EE Struts框架的课程设计实训项目——《BBS论坛系统》——

针对项目中用户信息的数据访问组件及单元测试

1.1.1 提供与用户信息相关的DAO组件

1、提供UserManageDAOInterface接口

(1)接口名称为UserManageDAOInterface,包名称为com.px1987.webbbs.dao

(2)设计该接口

package com.px1987.webbbs.dao;

import java.util.ArrayList;

import java.util.Map; 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料

杨教授大学堂,版权所有,盗版必究。 2/50页 import com.px1987.webbbs.exception.WebBBSException;

import com.px1987.webbbs.model.PageStateVO_Prototype;

public interface UserManageDAOInterface {

// 下面的方法是针对UserInfoBasePO类的

public ArrayList selectAllBaseUserInfo() throws

WebBBSException;

public ArrayList selectSomeBaseUserInfo(String HQLSelect)

throws WebBBSException;

//下面的方法是针对UserInfoPO类的

public ArrayList selectAllUserInfo() throws

WebBBSException;

public ArrayList selectSomeUserInfo(String HQLSelect) throws

WebBBSException;

public ArrayList selectAllRegisterUserNameInfo(String userName)

throws WebBBSException;

public UserInfoPO doGetMaxIDUserInfo() throws WebBBSException;

public UserInfoPO selectOneUserInfo(String registerUserID) throws

WebBBSException;

public UserInfoPO selectOneUserInfoByName(String userName) throws

WebBBSException;

public ArrayList selectOnePageUserInfo(String HQLSelect, int

firstResult,int maxResults) throws WebBBSException;

public ArrayList selectUserSomePropertyInfo(String HQLSelect)

throws WebBBSException;

public ArrayList selectSomeRegisterUserInfo(Map

registerUserInfos) throws WebBBSException;

public ArrayList

selectOnePageRegisterUserInfo(PageStateVO_Prototype

onePageStateVO_Prototype,Map registerUserInfos) throws WebBBSException;

public ArrayList 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料

杨教授大学堂,版权所有,盗版必究。 3/50页 selectOnePageVIPUserInfo(PageStateVO_Prototype onePageStateVO_Prototype,Map

vipUserInfos) throws WebBBSException;

public ArrayList

selectOnePageAllUserInfo(PageStateVO_Prototype onePageStateVO_Prototype) throws

WebBBSException;

public ArrayList selectSomeVIPUserInfo(Map vipUserInfos)

throws WebBBSException;

public UserInfoPO selectOneUserInfoData(String userName, String

userPassWord) throws WebBBSException;

public int selectTotalRegisterUserCounter() throws WebBBSException;

public int selectTotalGeneralRegisterUserCounter() throws

WebBBSException;

public int selectTotalVIPRegisterUserCounter() throws WebBBSException;

public int selectTotalGeneralRegisterUserCounter(Map registerUserInfos)

throws WebBBSException;

public int selectTotalVIPRegisterUserCounter(Map vipUserInfos) throws

WebBBSException;

public boolean insertOneUserInfo(UserInfoPO oneRegisterUserInfo) throws

WebBBSException;

public boolean updateOneUserInfo(UserInfoPO oneUpdatedRegisterUserInfo)

throws WebBBSException;

public boolean updateOneUserPassWord(String newPassWord, String

registerUserId) throws WebBBSException;

public boolean deleteOneUserInfo(String registerUserID) throws

WebBBSException;

public boolean batchDeleteUserInfo(ArrayList deletedUserIDs) throws

WebBBSException;

}

2、提供UserManageDAOInterface接口的实现类UserManageDAOJDBCImple

(1)新增加UserManageDAOJDBCImple类,包名称为com.px1987.webbbs.dao、并且继承杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料

杨教授大学堂,版权所有,盗版必究。 4/50页 Observable

(2)编程该实现类

package com.px1987.webbbs.dao;

import java.sql.*;

import java.util.*;

import org.hibernate.HibernateException;

import org.hibernate.Query;

import org.hibernate.Session;

import org.hibernate.Transaction; 杨教授大学堂 精心创作的优秀程序员 职业提升必读系列资料

杨教授大学堂,版权所有,盗版必究。 5/50页 import org.springframework.dao.DataAccessException;

import com.px1987.webbbs.config.ClassNameConfig;

import com.px1987.webbbs.exception.WebBBSException;

import com.px1987.webbbs.hibernatedao.HibernateUtil;

import com.px1987.webbbs.model.PageStateVO_Prototype;

import com.px1987.webbbs.util.ConnectDBFactory;

import com.px1987.webbbs.util.LogInfoFactory;

public class UserManageDAOJDBCImple extends Observable implements

UserManageDAOInterface {

Connection con=null;

ConnectDBInterface connectDBBean=null;

String connectDBBeanClassName=null;

/* 采用工厂方式实现时 */

public UserManageDAOJDBCImple() throws WebBBSException{

connectDBBeanClassName=

ClassNameConfig.getProperty("connectDBBean.className");

}

public Connection getConnection() throws WebBBSException {

connectDBBean=new

ConnectDBFactory().newConnectDBBean(connectDBBeanClassName);

con=connectDBBean.getConnection();

return con;

}

/* 利用 Spring IOC获得目标对象

public UserManageDAOJDBCImple() {

}

DataSource dataSource=null;

public DataSource getDataSource() {

return dataSource;

}