今天看了一天原來他們寫的代碼,越看越郁悶,主要是沒有設計文檔,而且里面很多被舍棄的功能,但是代碼沒有去掉,而且也沒有寫注釋,不知道干什么用的,也許是我太菜了吧?
簡單分析一下這個模塊的代碼吧
模塊名稱叫“信息簡報 ”,功能包括五個部分:信息接受,信息發送,分類管理,組管理,權限配置。
其中用戶部分會用到公共模塊,日志部分就是直接使用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
}