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

您没有登录

» Java开发网 » Architecture & Framework  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
话题被移动
该话题已被移动 - floater , 2004-06-16 01:58
如果您尚不清楚该话题被移动的原因,请参考论坛规则以及本版公告或者联系本版版主。
作者 J2EE交流贴 [精华]
Jove



CJSDN高级会员


发贴: 1228
积分: 194
于 2004-06-15 16:11 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
前段时间工作变动赋闲在家,终于有时间把过往的一些经验和教训总结总结,并结合最近看得几本书,写了点东西出来
小弟才疏学浅,贴在这里希望得到大家的意见和指正。

另祝贺CJSDN建站两周年,我最喜欢的Java论坛。过去的一年多在这里得到了不少帮助,一并谢!

J2EE交流文档.pdf (563.96k)



作者 Re:J2EE交流贴 [Re:Jove]
jfml





发贴: 708
积分: 30
于 2004-06-15 16:16 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
第一个拜读大作,真是三生有幸啊


作者 Re:J2EE交流贴 [Re:Jove]
nothing

天外飞仙.....

CJSDN高级会员


发贴: 1636
积分: 131
于 2004-06-15 16:34 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
2nd.



躲得过的怪物,躲不过的刺激

作者 Re:J2EE交流贴 [Re:Jove]
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2004-06-15 16:57 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
3rd
gg应该做培训去 或者有空做做国外大作的翻译。
即使是熟悉的知识,要复述的有条理,也是不容易的。



No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:J2EE交流贴 [Re:Jove]
wes109

以梦为马

CJSDN高级会员


发贴: 857
积分: 60
于 2004-06-15 17:21 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





作者 Re:J2EE交流贴 [Re:Jove]
wes109

以梦为马

CJSDN高级会员


发贴: 857
积分: 60
于 2004-06-15 17:34 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
大体看了一下
写的很不错
严重期待第二版 Cool




作者 Re:J2EE交流贴 [Re:Jove]
zyzhang

Explorer



发贴: 155
积分: 30
于 2004-06-15 18:14 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
I really appreciate your effort on the documentation and open spirit behind it.
This is a precious virtue, and can make this site more attractive and more helpful.

If you have an apple and I have an apple and we exchange these apples then you and I will still each have one apple.

But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas.


zyzhang edited on 2004-06-15 18:16

作者 Re:J2EE交流贴 [Re:Jove]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-06-16 03:05 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
I moved this post to here for further discussion. I just contribute some of my thoughts here too:

1. Page 3, VOs should be replaced with interfaces. We should *not* pass objects between layers, but interfaces. Each layer could have its own implementation of the interfaces. The interfaces should belong to the business layer(why???)
2. Page 4, add/remove/update methods should have parameter user, not integer. Don't expose implementation. What if one day we need to change this id to 36 digit guid? Changing from 3-digit to 4 caused an earthquake in my working company, what if more than that?
3. Page 4, yes, normally we shouldn't care about db shifting in business applications, unless we are doing some middleware or like, e.g., forums/jive.
4. Page 6, yes, start from db side, get schema done first, then use middlegen hibernate to generate hbm files, then use tools to generate java classes(be careful here when you go hbm-->java, if you have inheritance, you have to read in parent hbms first before you read in child hbms). One more note: After we settle the business layer, the schema could be derived in several ways, read scott ambler's articles for 4 ways to do this.
5. Page 7, JDBCTemplates etc could be done better in the following:
a. queryForObject/Long/Int should be improved to return a uniform object, like in SQLExecutor interface. Same as input. SQLExecutor's interface is nices to api callers.
b. not sure about callbacks and inner classes, seems we just do what SQLExecutor does, it will be good enough.
6. Page 10, on datasource. The settings for different layers should be in seperate files(although we may read all of them into the context) so each layer is independent of others. Sample code constantly misleads this. And I don't like to read settings from resources from classpath because the collision is uncontrollable.
7. Page 11, web layer.
General speaking, there are 3 kinds of presentation tools:
a. velocity: scripting based
b. xml: xslt, xml based
c. tapestry: object based
jsp based is somewhere in the middle. Others are faces, tiles, portlets.
MVC model(well, not really mvc) - reads professional jsp chapter 7(new version) or 12(old version) for models, especially model 2 and 2x.
Hell to struts and hail to spring, Tounge.
What's wrong with spring's mvc? abuse of templates! This abuse breaks the workflow's logic(This workflow is to send output to browsers). The usage pattern is more like swing applications. You have to do things in a certain way, certain order. BUT the underlying is doing right, so still the best one so far.
page 14. spring bean package: doesn't have a way to write back to files. Swing applications need this feature, like firewall settings, etc. Once users config'd, they want to save them.
page 15. AOP, not sure about this. If we combine AOP and python, that's going to be something. Check Thinking in java's author's website on python.
BTW, there is a Jython out there too.
Others:
Transactions.

questions:
Why do we use spring transactions rather than Connection's autocommit or jta/jts?
Why do we use spring web mvc rather than struts?
What's the difference between beanfactory and applicationcontext?



"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
作者 Re:J2EE交流贴 [Re:Jove]
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2004-06-16 13:45 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
1. Page 3, VOs should be replaced with interfaces. We should *not* pass objects between layers, but interfaces. Each layer could have its own implementation of the interfaces. The interfaces should belong to the business layer(why???)

>>> Will it be a overkill to replace VO w/ interface? IMHO, most small projects dont have to hide vo's implementation between layers.

2. Page 4, add/remove/update methods should have parameter user, not integer. Don't expose implementation. What if one day we need to change this id to 36 digit guid? Changing from 3-digit to 4 caused an earthquake in my working company, what if more than that?

>>> yes sure. Command pattern.

3. Page 4, yes, normally we shouldn't care about db shifting in business applications, unless we are doing some middleware or like, e.g., forums/jive.
>>> agree w/ u.

4. Page 6, yes, start from db side, get schema done first, then use middlegen hibernate to generate hbm files, then use tools to generate java classes(be careful here when you go hbm-->java, if you have inheritance, you have to read in parent hbms first before you read in child hbms). One more note: After we settle the business layer, the schema could be derived in several ways, read scott ambler's articles for 4 ways to do this.
>>> is there any class generator for ibatis? i hate to do it by hand.

5. Page 7, JDBCTemplates etc could be done better in the following:
a. queryForObject/Long/Int should be improved to return a uniform object, like in SQLExecutor interface. Same as input. SQLExecutor's interface is nices to api callers.
>>> i dont see a reason to queryForLong/Int...casting can be done out of jdbc layer w/o pain.

b. not sure about callbacks and inner classes, seems we just do what SQLExecutor does, it will be good enough.
>>> callback and inner classes seem to be more elegant as i think..hehe

6. Page 10, on datasource. The settings for different layers should be in seperate files(although we may read all of them into the context) so each layer is independent of others. Sample code constantly misleads this. And I don't like to read settings from resources from classpath because the collision is uncontrollable.
>>> err..dont catch ur meaning...if settings are not read from res in classpath, where do they locate?

7. Page 11, web layer.
General speaking, there are 3 kinds of presentation tools:
a. velocity: scripting based
b. xml: xslt, xml based
c. tapestry: object based
jsp based is somewhere in the middle. Others are faces, tiles, portlets.
MVC model(well, not really mvc) - reads professional jsp chapter 7(new version) or 12(old version) for models, especially model 2 and 2x.
Hell to struts and hail to spring, .
What's wrong with spring's mvc? abuse of templates! This abuse breaks the workflow's logic(This workflow is to send output to browsers). The usage pattern is more like swing applications. You have to do things in a certain way, certain order. BUT the underlying is doing right, so still the best one so far.
>>> err...=( i dont have experienced other view technologies than jsp...

page 14. spring bean package: doesn't have a way to write back to files. Swing applications need this feature, like firewall settings, etc. Once users config'd, they want to save them.
>>> we are talking abt web app, aren't we?

page 15. AOP, not sure about this. If we combine AOP and python, that's going to be something. Check Thinking in java's author's website on python.
BTW, there is a Jython out there too.
>>> aop...never tried that b4...=P

Others:
Transactions.

questions:
Why do we use spring transactions rather than Connection's autocommit or jta/jts?
>>> I have the same question. IMO CMT is enough.

Why do we use spring web mvc rather than struts?
>>> have no chances to use spring web mvc...

What's the difference between beanfactory and applicationcontext?
>>> err...=P...never thought of that...


jigsaw edited on 2004-06-16 13:50

No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:J2EE交流贴 [Re:Jove]
Jove



CJSDN高级会员


发贴: 1228
积分: 194
于 2004-06-16 14:31 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
很高兴看到两位的对此的讨论
老实说对于J2EE有些部分确实没有掌握好,所以更希望能得到各位的指点

至于floater提出的三个问题,其中第三个问题在Spring自带的文档中说的比较清楚
至于为什么使用Spring的事务管理,我觉得他的好处主要是提供透明的事务支持
无论是底层使用Connection's autocommit or jta/jts,都提供统一的接口。
而Spring的WebMVC我觉得灵活也比较大

在第二部分的实例部分,有两个接近实际需求的假想项目
其中的第4页谈到了基于AOP的事务管理,以及使用MVC的Web开发方式
希望能继续得到各位的指正

(floater能不能把附件的上限放开? Smile200K实在比较局促。第二份文档有650K,得分好几个包 //bow)



作者 Re:J2EE交流贴 [Re:jigsaw]
zyzhang

Explorer



发贴: 155
积分: 30
于 2004-06-16 19:44 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
jigsaw wrote:; zyzhang wrote:
1. Page 3, VOs should be replaced with interfaces. We should *not* pass objects between layers, but interfaces. Each layer could have its own implementation of the interfaces. The interfaces should belong to the business layer(why???)

>>> Will it be a overkill to replace VO w/ interface? IMHO, most small projects dont have to hide vo's implementation between layers.

>>>> Value Object (Named "Transfer Object" in J2EE Design Pattern), is widely used as a way to pass object between layers(for example, from integration tier or business tier to web tier). Generally, it's plain java object.

2. Page 4, add/remove/update methods should have parameter user, not integer. Don't expose implementation. What if one day we need to change this id to 36 digit guid? Changing from 3-digit to 4 caused an earthquake in my working company, what if more than that?

>>> yes sure. Command pattern.

>>>>I always forget this point,and end up with a lot of tedious work when new change comes up. I am trying to use refactoring to improve the code.

3. Page 4, yes, normally we shouldn't care about db shifting in business applications, unless we are doing some middleware or like, e.g., forums/jive.
>>> agree w/ u.

>>>> I have a big headache on the db shifting problem.The application needs to deploy in differenct app servers and databases, we configure the db selection in the property file. but in data access layer, we 've been using vendor specific JDBC extension API(like CachedPrepareStatement,CachedResultSet, etc), and even worse, the data access layer isnot got good abstract(like DAO). We really need to get a elegant way to solve this problem.

4. Page 6, yes, start from db side, get schema done first, then use middlegen hibernate to generate hbm files, then use tools to generate java classes(be careful here when you go hbm-->java, if you have inheritance, you have to read in parent hbms first before you read in child hbms). One more note: After we settle the business layer, the schema could be derived in several ways, read scott ambler's articles for 4 ways to do this.
>>> is there any class generator for ibatis? i hate to do it by hand.

>>>>where's scott ambler's artichles?

5. Page 7, JDBCTemplates etc could be done better in the following:
a. queryForObject/Long/Int should be improved to return a uniform object, like in SQLExecutor interface. Same as input. SQLExecutor's interface is nices to api callers.
>>> i dont see a reason to queryForLong/Int...casting can be done out of jdbc layer w/o pain.

>>>> I 've noticed that this kind of interface(specific for different data type) are in a lot of API design. There could be other reason why not returning a uniform object.

b. not sure about callbacks and inner classes, seems we just do what SQLExecutor does, it will be good enough.
>>> callback and inner classes seem to be more elegant as i think..hehe

>>>> In some situation, the callback handler can provide an elegant way to do pre and post processing ,extensing,or plug-in support.

6. Page 10, on datasource. The settings for different layers should be in seperate files(although we may read all of them into the context) so each layer is independent of others. Sample code constantly misleads this. And I don't like to read settings from resources from classpath because the collision is uncontrollable.
>>> err..dont catch ur meaning...if settings are not read from res in classpath, where do they locate?

7. Page 11, web layer.
General speaking, there are 3 kinds of presentation tools:
a. velocity: scripting based
b. xml: xslt, xml based
c. tapestry: object based
jsp based is somewhere in the middle. Others are faces, tiles, portlets.
MVC model(well, not really mvc) - reads professional jsp chapter 7(new version) or 12(old version) for models, especially model 2 and 2x.
Hell to struts and hail to spring, .
What's wrong with spring's mvc? abuse of templates! This abuse breaks the workflow's logic(This workflow is to send output to browsers). The usage pattern is more like swing applications. You have to do things in a certain way, certain order. BUT the underlying is doing right, so still the best one so far.
>>> err...=( i dont have experienced other view technologies than jsp...

page 14. spring bean package: doesn't have a way to write back to files. Swing applications need this feature, like firewall settings, etc. Once users config'd, they want to save them.
>>> we are talking abt web app, aren't we?

page 15. AOP, not sure about this. If we combine AOP and python, that's going to be something. Check Thinking in java's author's website on python.
BTW, there is a Jython out there too.
>>> aop...never tried that b4...=P

Others:
Transactions.

questions:
Why do we use spring transactions rather than Connection's autocommit or jta/jts?
>>> I have the same question. IMO CMT is enough.

>>> I have transaction context propogate problem with POJO(with jdbc ,jta) from business tier(session bean).it seems Spring address this problem,and give good solution on this.
Why do we use spring web mvc rather than struts?
>>> have no chances to use spring web mvc...

What's the difference between beanfactory and applicationcontext?
>>> err...=P...never thought of that...

Page9: Encapsulate SQLException
I do agree the way spring handle the SQLException. Actually, runtime and checked exception sometimes are not easy to decide and choose. There are some debate, guidelines and best practice on the java exception handling in the onjava web site. Logging also need to pay more attention, Maybe AOP can give elegant solution on them.



zyzhang edited on 2004-06-16 22:32

作者 Re:J2EE交流贴 [Re:Jove]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-06-16 22:39 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
1. I am just an moderator, not admin, so I don't have permission to lift the file limit for uploading.
2. VO point: In a small scale, sure there is convenient to pass VOs between layers. However, I found that this would invalid the layer seperation and cause severe consequence in practice(I mean in business application development because expansion is almost a sure thing). On the other hand, the interfaces(belonging to the business layer, i.e., setting the business layer packages, this is very important) could benefit greatly. For example, I have a swing(off web a little) panel with this interface, a plain java bean from dao with this interface, a plain java bean from nao(network/internet) layer with this interface, when I get the updated info from gui, I don't need to wrap the panel again, just pass it directly to the dao to update the new info. However, the drawback is sometimes I still need to copy objects, but this is still less work than plain VOs.
3. ambler's site: http://www.agiledata.org/. I don't have the e-copies somehow. Two articles:
a. chapter 14 of his book: the fundamentals of mapping objects to RDB.
This is talking about options we have
b. The design of a robust persistence layer
This is talking about his version of best practice.
c. There is some implementation based on b somewhere.
4. I have no hand-on exp on ibatis, sorry can't help on this.
5. Callbacks/inner classes, in my view, is always the *last* way to resolve something if we can't go straight. It's ok if the logic flow is easy to grasp, but it's horrible if not easy. I think it's ok for jdbctemplate etc, but it can be improved by removing callbacks. To expand my reasoning further, any APIs would have the same problem, like spring web controller api and swing api. The learn curve is nontrivial because we have to call them in a very careful fashion, even the java docs are good.
6. settings should be loaded from configurations because by definition they are settings. Classpath loading is uncontrollable. For example, spring uses commons-logging. If a log4j.properties is found in the classpath, it will use it, otherwise, use jdk logging. Now, say I have a spring web app on an app server and I want to use jdk logging, so I don't put log4j.properties in the classpath. However, some other app setting on the same app server wants to use log4j and put a log4j.properties there. Now what happens?
7. Good point from zyzhang, exceptions AND logging, we need to pay attention to them.
8. My questions are not really questions, but the reasons why we have them, spring tx, mvc, etc. If we know what problems these solves, we could have a better understanding. I just did examples, we should throw in more questions like these to help us better comprehension(as well as logging the aspects of subjects).
9. I don't see the code from Jove, did you hide it somewhere, Tounge?
10. I am working on a project using spring mvc and dao. I could write some document on these two later. It seems some of you folks have exp on other areas, aop, tx, if you could get something, maybe we could combine them together. I would think a startup demo, key technical points/benefits, problems solved, comparing to other similar things, limitation. A general explanation is not good enough, a code-level demonstration would be great.
To go further, since I am not an expert on editing, I start to think about/learning editing. I like the wrox style, a lot of stuff on one page, I hate Yan's java and pattern style, waste of paper. code highlight would be great, code explanation in "* in action" books would be great. Any suggestion would be helpful.



"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
作者 Re:J2EE交流贴 [Re:Jove]
hitaco





发贴: 432
积分: 31
于 2004-06-16 23:17 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
page 4, User-->VO
I guess in some situations User may represent Business object/Domain object, for example, in hibernate architecheture, object can be detached, we do not need VO just holding data for business object.

page 6: ResultSet/Paging/ResultSet::absolute()
Some JDBC driver will not skip the data.
Suppose we have 10000 records in the query result and we are interested only in the 9999th row.
rs.abolute(9999) is not good concerning the performance, it will not be more efficient than looping the resultset from the very begining, which will cost much more time than rownum approach. (BTW: I have tested this in oracle driver)

page 9: query by inner class, anonymous inner class are good when used as strategy objects, but most developers will be confused with the syntax,
my opinion about inner class is: do not put too much code in the inner class, in some situations, we can create a helper method which will be invoked from the inner class.

String[] getAllUsername() {
final ArrayList list = new ArrayList();

return (String[]) jdbcTemplate.query("select name from user", new RowCallbackHandler() {
  public void processRow(ResultSet rs) throws SQLException {
   list.add(rs.getString("name"));
  }
})

return ......
}

about RuntimeException/Checked Exception:
I have seem many applications just try/Catch SQLException in DAO and wrap as app-specific exception, rethrown it, and let session bean layer to catch it and call SessionContext::setRollbackOnly(), it's not good, I prefer touse RuntimeException and let EJB Container automatically rollback the transaction, BTW, I do not know how hibernate deal with transaction when RuntimeException occurs.



作者 Re:J2EE交流贴 [Re:Jove]
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2004-06-17 09:36 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
to hitaco abt exceptions:
no matter DAO/EJB throws RuntimeException or checked exception,
client class is expected to catche them, since exceptions are return from method.
However SQLException contains not enought infos abt wot's happening,
so we have to wrap it w/ app-spec exception to tell client class wot's
going on there.
if a wrapper of low level exception is not able to tell in a non-ambiguous way, it should be defined as a runtime exception which means client dont have to catch it, just let CMT to rollback and display a common error message to end user.



No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:J2EE交流贴 [Re:Jove]
jigsaw

KK

CJSDN高级会员


发贴: 3666
积分: 93
于 2004-06-17 09:44 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
to floater:
code itself is more accurate than any other words, hence i think
it could be better to publish code w/ javadoc. it's enough. =)

comments can make it easy to go through the code. if there's
sth. not easy to understand, comments would be helpful.

to obey the common java coding style is all that we need on editing.



No one knows except both of us.
909090909090909090909090909090909090909090b8533ce76c8d6c241868968a0408c338b4ffbf
ISO/IEC 9899:1999
作者 Re:J2EE交流贴 [Re:Jove]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-06-17 10:00 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
In term of rapid development, src code and java doc are not enough. With several options around, we should come up with some best practices(although it's not always possible to find such things). It's true sometimes we need to look through docs and possibly src code to check something, but digging should not be the norm.


"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
作者 Re:J2EE交流贴 [Re:Jove]
Jove



CJSDN高级会员


发贴: 1228
积分: 194
于 2004-06-17 10:04 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
Jove wrote:
在第二部分的实例部分,有两个接近实际需求的假想项目
其中的第4页谈到了基于AOP的事务管理,以及使用MVC的Web开发方式
希望能继续得到各位的指正

继续抛砖引玉,以下为文档第二部分和示意代码

part2.part1.rar (190.0k)



作者 Re:J2EE交流贴(2nd rar) [Re:Jove]
Jove



CJSDN高级会员


发贴: 1228
积分: 194
于 2004-06-17 10:06 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
Jove wrote:
继续抛砖引玉,以下为文档第二部分和示意代码


part2.part2.rar (182.24k)



作者 Re:J2EE交流贴 [Re:jigsaw]
hitaco





发贴: 432
积分: 31
于 2004-06-17 10:13 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
I am afraid most applications(at least in my company), will not do anything other than a friendly UI when SQLExceptino occur, so, there is no need to wrap/rethrow the SQLException. Something like exception handler in Struts or declarative exception configuration in web.xml is enough, that means, we can use generic means to catch/handle exception rather than duplicating the "try/catch/forward to error page" logic everywhere in the source code.

Of course, what kind of exception to use should be taken into consideration in serious project.

jigsaw wrote:
to hitaco abt exceptions:
no matter DAO/EJB throws RuntimeException or checked exception,
client class is expected to catche them, since exceptions are return from method.
However SQLException contains not enought infos abt wot's happening,
so we have to wrap it w/ app-spec exception to tell client class wot's
going on there.
if a wrapper of low level exception is not able to tell in a non-ambiguous way, it should be defined as a runtime exception which means client dont have to catch it, just let CMT to rollback and display a common error message to end user.



作者 Re:J2EE交流贴 [Re:Jove]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-06-17 10:13 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
Hehe, sorry, I even forgot to add credit to you, darn. Thanks, why!!!


"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
作者 Re:J2EE交流贴 [Re:Jove]
chenyajun5

一日不倒,每天都打

CJSDN高级会员


发贴: 643
积分: 90
于 2004-06-17 11:16 user profilesend a private message to usersend email to chenyajun5search all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
强烈建议写长,,,go on please


想干的人找一个方法,不想干的人找一个借口。
作者 Re:J2EE交流贴 [Re:Jove]
zyzhang

Explorer



发贴: 155
积分: 30
于 2004-06-17 22:04 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
In part2...

Transaction:
It's indeed an elegant solution combining Hibernate+Spring(AOP) and using declarative management to address the transaction management. The property of "PROPAGATION_REQUIRED" is the key to propagate the transaction context.
In the application i am working on, there are very limited transaction operations, so we decide to using programmatic transaction management using JTA, instead of CMT. Also, most of the online operations(long-term transaction) are handled well by using optimistic locking.The problem we are facing is that we have tried to propagate transaction context from session facade to DAO implementation object(POJO), the transactions are nested transaction in nature.the implemation have to consider a lot of restriction enforced by EJB Container. Spring AOP really give a good solution to this problem.

Validation:
I ever suffered managing the validation codes scattering around. The validation codes tend to change frequently. So, we try to seperate them from the main codes, define Validation interface, register the implementation and plug into the application. This really benefits us a lot. Here, the validation codes are mainly application specifics.
Spring seems adding some features on the data binding(from user input data to domain model). In web tier, we use Struts Validation to do most of the validation work. I have no clear idea on the difference between the two.

Meta data and code generation:
We are using xdoclet, and our own home-made code generation tool (From rational rose model as the base) to do code generation.I think this's also an interesting topic worth to talking about. How the code generation can fit in Spring framework.


zyzhang edited on 2004-06-17 23:41

作者 Re:J2EE交流贴 [Re:Jove]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-06-18 09:22 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
Jove,

Somewhere in your controller code, you didn't call the errors.getModel(), just create your Map and pass it the ModelAndView. This will create exception in you jsp, right? Because you didn't pass the errors's model, so in jsp the spring:bind would blow up.

I might be wrong, but at least this is my exp and others in the spring forum.

I don't have time to go through it today since I need to finish a doc today. But will comment more definitely.



"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
作者 Re:J2EE交流贴 [Re:floater]
Jove



CJSDN高级会员


发贴: 1228
积分: 194
于 2004-06-18 10:24 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
floater wrote:
Jove,
Somewhere in your controller code, you didn't call the errors.getModel(), just create your Map and pass it the ModelAndView. This will create exception in you jsp, right? Because you didn't pass the errors's model, so in jsp the spring:bind would blow up.
...

demo中很少的几个地方用到了FormController(如用户的注册和信息修改)

由于配置了Validator,所以在onSubmit(req,resp,cmd,errors)中的对象是通过了验证的,否则会直接返回formView显示相应错误
而在onSubmit中,我做额外的检查和操作,如果有误则放到errors中,并调用showForm(request, response, errors)
而AbstractFormController的重载的showForm会最终调用errors.getModel()

我对Spring的Form也把握不大,至少从目前来看,我这样做还是可以用的 Smile



作者 Re:J2EE交流贴 [Re:Jove]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-06-18 13:50 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
Hmm, I just couldn't find where I saw that piece of code, sorry.

I still can't get it up and running in jb.
I rule out all the errors there, finally hit the db. Since I don't have db file
I have to set the auto to create to let hibernate to generate the tables for me. However, for some reason, table name got trancated to relationsh0_ and this:
01:40:22 INFO [SchemaExport] Running hbm2ddl schema export
01:40:22 INFO [SchemaExport] exporting generated schema to database
01:40:22 INFO [ConnectionProviderFactory] Initializing connection provider: org.springframework.orm.hibernate.LocalDataSourceConnectionProvider
java.lang.NullPointerException
  at java.util.Hashtable.put(Hashtable.java:393)

I would think if we could break the big piece into smaller ones, i.e., web part, db part, etc; rather than a big chunk.

I have a small test program just on the web part with some dummy/mock backend. I'll recap that and send here.

It would be nice to send the db files here, that would be a help.
If you could recap your code to seperate out just the backend part(without web, jsp/velocity), it would be great since we seperate concerns.



"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
作者 Re:J2EE交流贴 [Re:floater]
Jove



CJSDN高级会员


发贴: 1228
积分: 194
于 2004-06-18 14:48 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
hehe, 这个例子才刚刚起步,很多地方是借鉴SpringFramework自带的几个sample
我把它和文档放在一起,本意是提供一个代码参考,没有打算做成一个完整的应用
因为我觉得Spring自带的几个例子已经挺不错的了

anyway,如果你要运行它看看效果,就把下面的压缩包解开,在lib目录补上所有的jar (详见list.txt)
然后修改db目录的startHsql.bat,启动数据库。然后执行ant,令其打包并部署,你可以自己注册用户

注意服务器需要Tomcat5, 因为用到了EL

抱歉,原本没打算这份源码示人,所以没多少文档和注释,更有些地方写的不堪入门,贻笑大方了 Embaressed

code.rar (95.54k)



作者 Re:J2EE交流贴 [Re:Jove]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2004-06-18 21:32 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
No, no, no, in fact, I agree with a lot of your writing. When I see something good, I enjoy the reading.

I noticed some codes are from Spring samples(I went through all the samples), but why not?

Spring's samples are good, but I am planning to break them into pieces in order to see all the options and best practices. Just don't have enough time, my boss asked for one document per day, *sigh*.

I'll try when I get home.



"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
作者 Re:J2EE交流贴 [Re:Jove]
zyzhang

Explorer



发贴: 155
积分: 30
于 2004-06-22 01:48 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
Transaction using JTA and POJO (jdbc )as DAO implementation in traditional way:

JDBC transactions are not always suitable for some enterprise applications needs. If the transactions span multiple DAOs or multiple databases (or external resources), the transactions sometimes have to be demarcated with JTA and is seperated from DAO. The caller is responsible for demarcating the transaction, and the DAO participates in a global transaction.

The transaction managements in these cases are distributed in nature. The underlying transaction managements (resource manager) have to coordinate together to satisfy the transaction boundary you defined in the application.

The application we are developing need to support concurrently conecting to different databases using different DAO implementations and external applications using JCA. One big problem we are facing is transaction propagation. We also want to fine-grained control some transaction operations.

The development context is that we have session beans,mdb plus POJO (jdbc) as dao implementation. cause, jdbc using connection object to define the transaction, but we define the transaction boundaries in session bean. So, we need the ejb container transaction manager coordinates with jdbc counterpart. The solution for this is that we define XA data source and using txconnection object in jdbc codes ,instead of general jdbc connection object. DO NOT DEFINE any transaction boundaries or commit, rollback inside jdbc codes.

We've tried to another approach to pass Transaction Context as parameter to POJO DAO, but it's too complex and lot of low level coding and control(Thread Save), Also there are too many restrictions, and we eventually gave up.

Some codes examples for the simple and practical solution on this problem:

public void createOrderWithDAO_JTA() {

Exception caught = null;

/*
* This DAO expects the caller to demarcate the transaction using JTA. This DAO access database1.
*/
WarehouseDAO dao1 = MyDAOFactory.getWarehouseJTA_DAO();

/*
* This DAO expects the caller to demarcate the transaction using JTA. This DAO access database2.
*/
OrderDAO dao2 = MyDAOFactory.getOrderJTA_DAO();

/*
* This publisher publishes messages to a JMS Topic and expects the caller to demarcate the transaction.
* When creating session, make sure it is transacted.
*/
MessagePublisher publisher = null;

UserTransaction utx = ResourceManager.getUserTransaction();

try {
/*
* Execute the transaction.
* This transaction accesses three resources:
* 1) a JMS Topic.
* 2) two different JDBC DataSources.
*/

utx.begin();

dao2.createOrder(....);

dao1.updateWareHouse(....);

publisher.publishTextMessage("Order Confirm Message....");

utx.commit();

} catch (Exception ex) {
log.error(ex);
caught = ex;
if (utx != null) {
try {
utx.rollback();
} catch (SystemException sysex) {
log.error(sysex);
}
}
} finally {
if (dao != null) {
dao.close();
dao = null;
}
if (publisher != null) {
publisher.close();
publisher = null;
}
if (caught != null) {
throw new DAORuntimeException(caught);
}
}
}

.....
In dao implementation:
conn = DBUtil.getXADBConnection();
.....


I think this is a painful solution (especially for complex applications) and not attractive at all. but Spring address this kind of problem in an elegant way(like EJB CMT).From the codes as jove shown, i can sense the advantage of Spring framework, though it seems Spring currently does not support multiple database or external resource (distributed) transaction at the moment.


why edited on 2004-07-02 09:36

作者 Re:J2EE交流贴 [Re:Jove]
zhbk





发贴: 10
积分: 0
于 2004-07-30 14:58 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
very good!


作者 Re:J2EE交流贴 [Re:Jove]
winconcom





发贴: 4
积分: 0
于 2004-09-09 11:45 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
不错的文档,但是始终在怀疑中使用,ejb的东西


winson

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