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

您没有登录

» Java开发网 » Architecture & Framework  

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


话题树型展开
人气 标题 作者 字数 发贴时间
25010 [精华] J2EE交流贴 Jove 129 2004-06-15 16:11
21276 Re:J2EE交流贴 jfml 15 2004-06-15 16:16
21141 Re:J2EE交流贴 floater 3646 2004-06-16 22:39
21140 Re:J2EE交流贴 hitaco 1731 2004-06-16 23:17
21269 Re:J2EE交流贴 jigsaw 573 2004-06-17 09:36
21137 Re:J2EE交流贴 hitaco 1161 2004-06-17 10:13
21195 Re:J2EE交流贴 jigsaw 335 2004-06-17 09:44
21198 Re:J2EE交流贴 floater 322 2004-06-17 10:00
21188 Re:J2EE交流贴 floater 69 2004-06-17 10:13
21180 Re:J2EE交流贴 chenyajun5 21 2004-06-17 11:16
21166 Re:J2EE交流贴 zyzhang 1828 2004-06-17 22:04
21148 Re:J2EE交流贴 floater 460 2004-06-18 09:22
21244 Re:J2EE交流贴 Jove 617 2004-06-18 10:24
21087 Re:J2EE交流贴 floater 1158 2004-06-18 13:50
21147 Re:J2EE交流贴 Jove 308 2004-06-18 14:48
21219 Re:J2EE交流贴 nothing 4 2004-06-15 16:34
21094 Re:J2EE交流贴 floater 431 2004-06-18 21:32
20991 Re:J2EE交流贴 zyzhang 3887 2004-06-22 01:48
22611 Re:J2EE交流贴 zhbk 10 2004-07-30 14:58
21051 Re:J2EE交流贴 winconcom 23 2004-09-09 11:45
21429 Re:J2EE交流贴 jigsaw 55 2004-06-15 16:57
21369 Re:J2EE交流贴 wes109 0 2004-06-15 17:21
21319 Re:J2EE交流贴 wes109 25 2004-06-15 17:34
21320 Re:J2EE交流贴 zyzhang 412 2004-06-15 18:14
21974 Re:J2EE交流贴 floater 3201 2004-06-16 03:05
21214 Re:J2EE交流贴 jigsaw 4037 2004-06-16 13:45
21089 Re:J2EE交流贴 zyzhang 5937 2004-06-16 19:44
21297 Re:J2EE交流贴 Jove 357 2004-06-16 14:31
21214 Re:J2EE交流贴 Jove 136 2004-06-17 10:04
21234 Re:J2EE交流贴(2nd rar) Jove 58 2004-06-17 10:06

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