We've added a TransactionRequestCycleListener (extends
AbstractRequestCycleListener). This class handles transactions mainly like
this:

@Override
public void onRequestHandlerResolved(final RequestCycle cycle, final
IRequestHandler handler)
{
        LOGGER.debug( "start transaction ---" +
cycle.getRequest().getUrl().toString() + "---" );
        Main.model.startTransaction(applicationName);
}

@Override
public void onRequestHandlerExecuted(final RequestCycle cycle, final
IRequestHandler handler)
{
        if(handler instanceof FooExceptionRequestHandler)
        {
                LOGGER.warn( "rollback transaction ---" +
cycle.getRequest().getUrl().toString() + "---" );
                Main.model.rollbackIfNotCommitted();
        }
        else
        {
                if( Main.model.hasCurrentTransaction() )
                {
                        LOGGER.debug( "commit transaction ---" +
cycle.getRequest().getUrl().toString() + "---" );
                        Main.model.commit();
                }
                else
                {
                        LOGGER.debug( "no transaction to commit ---" +
cycle.getRequest().getUrl().toString() + "---" );
                }
        }
}


The Model#currentTransaction() just returns the current transaction for this
thread and looks like:

/**
* Returns the transaction for this model,
* that is bound to the currently running thread.
* @throws IllegalStateException if there is no cope transaction bound to
current thread
 * @see Thread#currentThread()
 */
public Transaction currentTransaction()
{
        final Transaction result = transactions.currentIfBound();
        if(result==null)
                throw new IllegalStateException("there is no transaction bound 
to this
thread, see Model#startTransaction");
        return result;
}

We use our own persistence framework to handle transactions to the
underlying database. No magic all about.




--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/WICKET-5083-and-Page-isPageStateless-tp4660166p4660220.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to