sf logo

sf.qof.session
Class DefaultSessionRunner<T>

java.lang.Object
  extended by sf.qof.session.BaseSessionRunner<T>
      extended by sf.qof.session.DefaultSessionRunner<T>
Type Parameters:
T - the type of the result of the TransactionRunnable. If no result is returned this type should be Void
All Implemented Interfaces:
SessionRunner<T>

public class DefaultSessionRunner<T>
extends BaseSessionRunner<T>

DefaultSessionRunner is the default implementation that runs a TransactionRunnable in a session context. Calling execute starts a new session, calls the run method of the TransactionRunnable and commits or rolls back the transaction on success or failure.

Typical usage is like this:

 List<Person> personList = ...
 PersonUpdaterRunnable runnable = new PersonUpdaterRunnable();
 Integer numberOfUpdates = 
   new DefaultSessionRunner<Integer>(runnable, "MY_CONTEXT_NAME").execute(personList);
 

See Also:
SessionRunner

Field Summary
 
Fields inherited from class sf.qof.session.BaseSessionRunner
sessionContext
 
Constructor Summary
DefaultSessionRunner(TransactionRunnable<T> runnable)
          Creates a DefaultSessionRunner that creates a session from the default session context.
DefaultSessionRunner(TransactionRunnable<T> runnable, String contextName)
          Creates a DefaultSessionRunner that creates a session from the session context with the given name.
 
Method Summary
protected  T run(Connection connection, Object... arguments)
          This method is called once during the call to execute.
 
Methods inherited from class sf.qof.session.BaseSessionRunner
execute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSessionRunner

public DefaultSessionRunner(TransactionRunnable<T> runnable)
Creates a DefaultSessionRunner that creates a session from the default session context.

Parameters:
runnable - a TransactionRunnable

DefaultSessionRunner

public DefaultSessionRunner(TransactionRunnable<T> runnable,
                            String contextName)
Creates a DefaultSessionRunner that creates a session from the session context with the given name.

Parameters:
runnable - a TransactionRunnable
contextName - the context name
Method Detail

run

protected T run(Connection connection,
                Object... arguments)
         throws SQLException
Description copied from class: BaseSessionRunner
This method is called once during the call to execute. It must be overridden and should contain the code that needs to be run in a transaction context.

Specified by:
run in class BaseSessionRunner<T>
Parameters:
connection - the thread's current database connection
arguments - arguments passed to the execute method
Returns:
a result
Throws:
SQLException - throw this if an error occured. This will cause a rollback of the current transaction.

sf logo

Copyright © 2007 brunella ltd. All Rights Reserved.