in many situations transactions span multiple web requests and i wanted a clean way to handle this.
my thought was to define a WebTransaction object which had a TX ID and a State object. The State is just a Map of objects representing the state during the lifetime of the transaction.
The HttpSession objects holds a Map called TransactionMap which is the Map of WebTransaction objects with Tx ID as key.
With every request, the Tx ID is passed and the appropriate WebTransaction object retrieved from the Map to get State.
The WebTransaction object is created when a transaction is initiated and destroyed(removed from the map) on commit or if an exception occurs at any point during the transaction.
I wanted the groups comments on whether this is a good enough solution or if there are better solutions that anybody is aware of.
anoher approach would be to use a statefull session bean like :
//place the order in a processing queue or write something in the database
//remove the bean because is no longer needed
//or if the users cancels the the shopping cart
1. you maintain the state in a more cleaner way that in a map stored in the session.
2. the container takes care of the timeout of the session cart.
3. you can make the shopping cart a remote EJB in order to ease the load off the web server.
1. maybe you don't have or don't need an EJB container.