ORBroker transactions in LiftWeb

15 views
Skip to first unread message

Cristian Vrabie

unread,
Aug 2, 2012, 11:28:40 AM8/2/12
to orbr...@googlegroups.com
In a webapp you usually want to wrap the whole request in a transaction. So in a LiftWeb application I used a LoanWrapper to wrap the whole request in a transaction, then placed the session in a RequestVar (basically a threadlocal) so it's easily accesible in the response handling code: https://gist.github.com/3237865  (see ORBrokerHelper)
I'd like to know if you think it's a good approach and if you know of any improvements that can be done.
Thanks!
Cristian

Nils Kilden-Pedersen

unread,
Aug 2, 2012, 12:10:34 PM8/2/12
to orbr...@googlegroups.com
I'm not sure I understand the purpose of the implementation. However for external transaction management, the idea is to use Broker.transactional(java.sql.Connection), which leaves commit and rollback to any external transaction manager.

Cristian Vrabie

unread,
Aug 2, 2012, 1:47:13 PM8/2/12
to orbr...@googlegroups.com
Ignoring any external transaction management done by the container, I kept seeing recommendations that in the majority of cases when handling a http request (like in a REST API) the transaction should be started before you actually start to handle the request and committed just after you finish handling the request. 

In LiftWeb wrapping a request is done with S.addAround. In fact Lift uses it to wrap the Mapper operations in a transaction. Squeryl does the same thing.
The (naive) implementation i showed is about the same thing for ORBroker. The nice thing is that then you don't have to nest yourself the code in a transactional and can just use the session in your code.

However, it seems to me that in some cases the transaction is opened much longer than would be actually required. That's why I was looking for other opinions if we should in fact use this.

Cristian

On Thursday, 2 August 2012 17:10:34 UTC+1, Nils Kilden-Pedersen wrote:
I'm not sure I understand the purpose of the implementation. However for external transaction management, the idea is to use Broker.transactional(java.sql.Connection), which leaves commit and rollback to any external transaction manager.

Nils Kilden-Pedersen

unread,
Aug 2, 2012, 2:13:25 PM8/2/12
to orbr...@googlegroups.com
Yes, I understand. And it will probably work if you have no 2PC or needs to access JDBC outside of O/R Broker.

However you should probably remove the session in the finally block.
Reply all
Reply to author
Forward
0 new messages