Topic: J2EE交流贴

  Print this page

1.J2EE交流贴 Copy to clipboard
Posted by: Jove
Posted on: 2004-06-15 16:11

前段时间工作变动赋闲在家,终于有时间把过往的一些经验和教训总结总结,并结合最近看得几本书,写了点东西出来
小弟才疏学浅,贴在这里希望得到大家的意见和指正。

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

J2EE交流文档.pdf (563.96k)

2.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: jfml
Posted on: 2004-06-15 16:16

第一个拜读大作,真是三生有幸啊

3.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: nothing
Posted on: 2004-06-15 16:34

2nd.

4.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-06-15 16:57

3rd
gg应该做培训去 或者有空做做国外大作的翻译。
即使是熟悉的知识,要复述的有条理,也是不容易的。

5.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: wes109
Posted on: 2004-06-15 17:21



6.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: wes109
Posted on: 2004-06-15 17:34

大体看了一下
写的很不错
严重期待第二版 Cool

7.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: zyzhang
Posted on: 2004-06-15 18:14

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.

8.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: floater
Posted on: 2004-06-16 03:05

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?

9.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-06-16 13:45

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...

10.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: Jove
Posted on: 2004-06-16 14:31

很高兴看到两位的对此的讨论
老实说对于J2EE有些部分确实没有掌握好,所以更希望能得到各位的指点

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

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

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

11.Re:J2EE交流贴 [Re: jigsaw] Copy to clipboard
Posted by: zyzhang
Posted on: 2004-06-16 19:44

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.


12.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: floater
Posted on: 2004-06-16 22:39

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.

13.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: hitaco
Posted on: 2004-06-16 23:17

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.

14.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-06-17 09:36

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.

15.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-06-17 09:44

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.

16.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: floater
Posted on: 2004-06-17 10:00

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.

17.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: Jove
Posted on: 2004-06-17 10:04

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

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

part2.part1.rar (190.0k)

18.Re:J2EE交流贴(2nd rar) [Re: Jove] Copy to clipboard
Posted by: Jove
Posted on: 2004-06-17 10:06

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


part2.part2.rar (182.24k)

19.Re:J2EE交流贴 [Re: jigsaw] Copy to clipboard
Posted by: hitaco
Posted on: 2004-06-17 10:13

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.

20.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: floater
Posted on: 2004-06-17 10:13

Hehe, sorry, I even forgot to add credit to you, darn. Thanks, why!!!

21.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: chenyajun5
Posted on: 2004-06-17 11:16

强烈建议写长,,,go on please

22.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: zyzhang
Posted on: 2004-06-17 22:04

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.

23.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: floater
Posted on: 2004-06-18 09:22

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.

24.Re:J2EE交流贴 [Re: floater] Copy to clipboard
Posted by: Jove
Posted on: 2004-06-18 10:24

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

25.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: floater
Posted on: 2004-06-18 13:50

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.

26.Re:J2EE交流贴 [Re: floater] Copy to clipboard
Posted by: Jove
Posted on: 2004-06-18 14:48

hehe, 这个例子才刚刚起步,很多地方是借鉴SpringFramework自带的几个sample
我把它和文档放在一起,本意是提供一个代码参考,没有打算做成一个完整的应用
因为我觉得Spring自带的几个例子已经挺不错的了

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

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

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

code.rar (95.54k)

27.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: floater
Posted on: 2004-06-18 21:32

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.

28.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: zyzhang
Posted on: 2004-06-22 01:48

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.

29.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: zhbk
Posted on: 2004-07-30 14:58

very good!

30.Re:J2EE交流贴 [Re: Jove] Copy to clipboard
Posted by: winconcom
Posted on: 2004-09-09 11:45

不错的文档,但是始终在怀疑中使用,ejb的东西


   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