今天看了一天原来他们写的代码,越看越郁闷,主要是没有设计文档,而且里面很多被舍弃的功能,但是代码没有去掉,而且也没有写注释,不知道干什么用的,也许是我太菜了吧?
简单分析一下这个模块的代码吧
模块名称叫“信息简报 ”,功能包括五个部分:信息接受,信息发送,分类管理,组管理,权限配置。
其中用户部分会用到公共模块,日志部分就是直接使用System.out.pring通过JBOSS输出(JBOSS还不了解,应该是可以配置日志重定向的),异常处理暂时还没有具体深入(没有看到有什么特殊的处理,直接TYR,然后写日志)。模块结构比较简单,就是JSP+JavaBean+JDBC+Oracle。其中JavaBean部分就是业务逻辑部分,采用DAO模式把数据库访问逻辑和业务逻辑分开。
JavaBean部分一共分为3个包:dao(具体类),vo(实体类),util(工具类)
先说说数据库访问部分吧,采用的是DAO模式,DAO模式是标准的J2EE设计模式之一.开发人员使用这个模式把底层的数据访问操作和上层的商务逻辑分开.一个典型的DAO实现有下列几个组件:
1. 一个DAO工厂类;
2. 一个DAO接口;
3. 一个实现DAO接口的具体类;
4. 数据传递对象(有些时候叫做值对象).
我的这个模块可能太简单了,没有采用工厂模式,直接使用具体类,看了看其它模块都写了一个简单工厂。具体类有5个GroupDAOImpl,InfoDAOImpl,RightDAOImpl,TypeDaoImpl,adduser。实体类有4个:GroupVO,PubInfoRightVO,PubInfoVO,TypeVO。下面就是GroupVO和GroupDAOImpl两个类:
1
public class GroupVO
2

{
3
4
public int id;
5
public int orgId;
6
public int creatorAccount;
7
public String groupUser;
8
public String groupName;
9
public String groupDesc;
10
11
public GroupVO()
12
{
13
orgId = -1;
14
creatorAccount = -1;
15
}
16
}
1
public class GroupDAOImpl
2

{
3
4
protected transient DataSource dbDataSource;
5
protected transient Connection dbConnection;
6
7
public GroupDAOImpl()
8
{
9
dbDataSource = null;
10
dbConnection = null;
11
}
12
13
public int create(GroupVO newsinfovo)
14
throws NamingException, DAOException, SQLException
15
{
16
PreparedStatement preparedstatement = null;
17
boolean flag = true;
18
int l = 0;
19
try
20
{
21
getDBConnection();
22
boolean flag1 = dbConnection.getAutoCommit();
23
dbConnection.setAutoCommit(false);
24
int i = UUIDGenerator.nextSeqNum(dbConnection, "DIGEST_GROUP_ID");
25
Date date = new Date();
26
String s = String.valueOf(String.valueOf((new StringBuffer("INSERT INTO ")).append(DatabaseNames.DIGEST_GROUP_TABLE).append("(group_id,orgid,creator_account,group_name,group_desc,group_user) VALUES(?,?,?,?,?,?)")));
27
preparedstatement = dbConnection.prepareStatement(s);
28
int k = 1;
29
preparedstatement.setInt(k++, i);
30
preparedstatement.setInt(k++, newsinfovo.orgId);
31
preparedstatement.setInt(k++, newsinfovo.creatorAccount);
32
preparedstatement.setString(k++, newsinfovo.groupName);
33
preparedstatement.setString(k++, newsinfovo.groupDesc);
34
InputStream tmpStream = new ByteArrayInputStream(newsinfovo.groupUser.getBytes("GBK"));
35
preparedstatement.setBinaryStream(k++, tmpStream, tmpStream.available());
36
int j = preparedstatement.executeUpdate();
37
dbConnection.commit();
38
dbConnection.setAutoCommit(flag1);
39
if(j != 1)
40
throw new DAOException(String.valueOf(String.valueOf((new StringBuffer("Failed inserting into table ")).append(DatabaseNames.DIGEST_GROUP_TABLE).append(".\n"))));
41
newsinfovo.id = i;
42
l = i;
43
}
44
catch(Exception e)
45
{
46
System.out.println(e.toString());
47
}
48
finally
49
{
50
closeStatement(preparedstatement);
51
closeConnection();
52
}
53
return l;
54
}
55
56
public GroupVO load(int i)
57
throws NamingException, DAOException, SQLException
58
{
59
60
}
61
62
public void remove(int i)
63
throws NamingException, DAOException, SQLException
64
{
65
66
}
67
68
public Vector getGroupVector(int start, int total)
69
throws NamingException, DAOException, SQLException
70
{
71
72
}
73
74
public Vector searchGroup(GroupVO vo, int start, int total)
75
throws DAOException, SQLException
76
{
77
78
}
79
80
public void store(GroupVO newsinfovo)
81
throws NamingException, DAOException, SQLException
82
{
83
84
}
85
86
protected void getDBConnection()
87
throws NamingException, DAOException
88
{
89
90
}
91
92
protected void closeConnection()
93
throws DAOException
94
{
95
96
}
97
98
protected void closeStatement(Statement statement)
99
throws DAOException
100
{
101
102
}
103
104
protected void closeResultSet(ResultSet resultset)
105
throws DAOException
106
{
107
108
}