Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » 技术文章库  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:JDBC revisit [Re:floater]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2003-09-21 11:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Recently, Why introduced us this nice framework:
http://www.cjsdn.com/post/view?bid=21&id=48838

I took a look at the source code and gave out some comments in the above post.

In this post, let's see how to fix the problems I mentioned. Basically, we are taking a refactoring approach, the bottom line is that if the code is too long(I use the rule: every class file shouldn't go beyond 500 lines, and I haven't seen exceptions in application development).

1. The connection pool should be out, in a seperate package. What we pass into here should be just a connection because that's all it's related. In fact, the connection pool and datasource should have its own package, independent of everything else. So we pass the Connection object to the constructor.
2. Transaction handling is also connection related, so we leave that out in a seperate class.
3. The error handling is kind of wicky. It has a bunch of functions to check what the root cause is. Comm'n, I don't want to go through each call to know exactly what's wrong, just tell me what it is, I am a lazy guy. Besides, if we know the error, we won't be able to do anything in the code(with if statements). So we change it to a simple msg.
4. Continue in error handling, we really don't need subclasses to translate any specific db error code. We could, instead, use a properties file to map the error codes to messages. This saves users from programming. So we add a file name to the constructor.
5. If we take a bird view of the main class, it has a big chunk of code for SQL parameter settings. We could move them out of here. There is another big chunk of code dealing with converting from primitive typs to objects, so let's move this piece out too.
6. The SQLResult class is mixed with implemention interface with user interface, so we should seperate them too(input/output).

Having done these, we have something like this file tree:
(ignore the files with names starting with Test..., they are for testing purpose).


why edited on 2003-10-26 10:33

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code

话题树型展开
人气 标题 作者 字数 发贴时间
16697 JDBC revisit floater 7109 2003-07-01 02:50
14908 Re:JDBC revisit floater 2005 2003-09-21 11:47
13931 Re:JDBC revisit floater 112 2003-09-28 04:49
17885 Re:JDBC revisit floater 291 2003-09-28 04:54
14004 Re:JDBC revisit floater 2176 2003-09-21 12:10
13947 Re:JDBC revisit floater 1046 2003-09-21 12:22
14102 Re:JDBC revisit mazalet 6 2003-09-21 12:43
14089 Re:JDBC revisit Johnny 39 2003-09-22 09:44
13890 Re:JDBC revisit floater 48 2003-09-22 10:03
14023 Re:JDBC revisit Johnny 589 2003-09-24 09:40
13840 Re:JDBC revisit floater 82 2003-09-24 10:06
13975 Re:JDBC revisit Johnny 57 2003-09-25 10:50
13804 Re:JDBC revisit floater 131 2003-09-25 11:15

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923