Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

As this code is heavily dependent on Spring and Hibernate, you shouldn't expect to see it packaged with a WebWork distribution. It does, however, serve as a useful example of extending the ExecuteAndWaitInterceptor ExecuteAndWait Interceptor

Code Block
titleOpenSessionExecuteAndWaitInterceptor.java
borderStylesolid
import net.sf.hibernate.SessionFactory;

import com.opensymphony.webwork.interceptor.BackgroundProcess;
import com.opensymphony.webwork.interceptor.ExecuteAndWaitInterceptor;
import com.opensymphony.xwork.ActionInvocation;


/**
 * The OpenSessionExecuteAndWaitInterceptor will obtain a Hibernate
 * Session Factory from a Spring.
 * 
 * The session factory will then be passed to the BackgroundProcess,
 * to open a session, enable Spring's transaction management 
 * capabilities, and bind the Session to the background thread.
 * 
 */
public class OpenSessionExecuteAndWaitInterceptor extends ExecuteAndWaitInterceptor {
       
    SessionFactory sessionFactory;

    
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}


	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	protected BackgroundProcess getNewBackgroundProcess(String arg0, ActionInvocation arg1, int arg2) {
		return new OpenSessionBackgroundProcess(arg0, arg1, arg2, sessionFactory);
	}

}

...