• Post Reply Bookmark Topic Watch Topic
  • New Topic

where to put J2EE transaction handling

 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I have a question about where to put the container managed transaction within the business tier patterns. For example, chapter 7 of "Core J2EE Patterns" explains the ApplicationService pattern. So, for example you can have:

SLSBFacade->ApplicationService-> DAO or Entity

Chapter 7 has said that an ApplicationService is a POJO. So where is the transaction method? SLSBFacade is too generic to put detailed transaction handling. Should the following be used instead?

SLSBFacade->SLSBApplicationService->ApplicationService-> DAO or Entity

Will this be too slow with 2 SLSB in the chain?

Thanks for you help.

-Saha
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

SLSBFacade is too generic to put detailed transaction handling

Your facade provides the public API for any client application, so it seems to me to be the sensible place to also start transactions. Why do you whink it is too generic?
 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for responding. According to "Core J2EE Patterns", the session facade should have little or no business logic. One of the ApplicationService POJOs that I have must: 1) execute a task, 2) then execute 2 more tasks within a transaction. If one of the last 2 tasks fail then they must be rolled back, and the task in 1) must be undone. The task in 1) is performed on a different system and cannot be in the same transaction context as the tasks in 2). I was thinking that the code to handle the transactions is too involved in the business logic to put in the session facade.

What do you think?

Thanks again.

-Saha
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It still sounds like you only have one transaction there - the transaction that wraps task 1 and task 2. When you say:

The task in 1) is performed on a different system and cannot be in the same transaction context as the tasks in 2).

what is it you are trying to do that makes you think this?
 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Paul,

I want to 1) call an external credit card service to pay for an order, 2) persist the order in a local database. If 2) fails, I want to 'unpay' for the order (i.e. 'rollback' 1)). I don't want 1) in the transaction...only 2). If 2) fails, it will get rolled back, and 1) will get unpaid.

My plan was for the facade to call a method in a POGO.

-Saha
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the external service transactional?
 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it is not transactional. Thanks for the reply.

-Saha
 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I don't know if its transactional. My interface to it is xml/URL.
 
gosi gosi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saha~If you're still not having a solution, then you may think of "Compensating Transaction" implementation.

Basically, your external credit card provider should have a "compensating scenario" implementation, which you'd use in case your txn(2) fails. For more see http://msdn.microsoft.com/msdnmag/issues/03/07/DesignPatterns/

Yes, this is a microsoft website.. :roll:
 
Saha Kumar
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gosi. This is a good idea. I'm planning to use it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!