I wouldn't advice you to do it in the requestcycle for the reasons you
already describe yourself:
- Too cumbersome
- All request are then in a Transaction (might no be a problem though).
- How to detect that a rollback is needed.
You could still use Spring transaction though: This could be a possible
implementation, but I don't know if this is rock solid especially the
rollback I am not sure about. This approach will enable nested transaction
IHMO since it still uses the spring configured transactions.
class TransactionalRequestCycle extends WebRequestCycle {
@SpringBean private TransactionManager txManager
private TransactionStatus status;
public TransactionRequestCycle() {
// this will inject the txManager from the spring context.
InjectorHolder.getInjector().inject(this);
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setPropagationBehavior(...);
}
protected void onBeginRequest() {
status = txManager.getTransaction(def);
}
protected void onEndRequest() {
txManager.commit(status);
}
protected void onRuntimeException() {
if(status != null)
txManager.rollback(status);
}
}
On Thu, Apr 24, 2008 at 1:18 PM, Stefan Selariu <[EMAIL PROTECTED]>
wrote:
> Thanks for your answer, but sadly this is not possible.
> I cannot group the beans in one service because the beans are invoked
> from different wicket components.
> I need the request cycle to be transactional because on the submit event
> one component calls the required transactional service and at render
> time the page components sometimes need to invoke other transactional
> beans to complete the rendering.
>
> If I quit using spring's transactions support I could use onBeginRequest
> and onEndRequest to start and close the transaction. This approach is
> very limited (no nested transactions, very complicated transaction
> exceptions handling, the spring beans need to be aware of the
> transactions) and I don't like it :)
>
> Has anyone an idea why RequestCycle is a class and not an interface?
> This is a problem in my case :(
>
> Thanks again.
> Stefan
>
> On Thu, 2008-04-24 at 11:03 +0200, lars vonk wrote:
> > I would advice you to group the transactional beans in one Service,
> define
> > that service in Spring and make it transactional. By using the proper
> > Transaction Propagation levels the "wrapped" beans can use existing
> > transactions if there is one.
> >
> > See
> >
> http://static.springframework.org/spring/docs/2.5.x/reference/transaction.htmlfor
> > more info on Spring and Transactions.
> >
> > Lars
> >
> >
> > On Thu, Apr 24, 2008 at 10:01 AM, Stefan Selariu <
> [EMAIL PROTECTED]>
> > wrote:
> >
> > > Hi!
> > >
> > > I need to call inside a request cycle an unknown number of
> transactional
> > > spring beans. How can I call those beans within the same transaction?
> > >
> > > Thanks.
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>