com.google.inject.persist
Class PersistFilter

java.lang.Object
  extended by com.google.inject.persist.PersistFilter
All Implemented Interfaces:
javax.servlet.Filter

public final class PersistFilter
extends Object
implements javax.servlet.Filter

Apply this filter to enable the HTTP Request unit of work and to have guice-persist manage the lifecycle of active units of work. The filter automatically starts and stops the relevant PersistService upon Filter.init(javax.servlet.FilterConfig) and Filter.destroy() respectively.

To be able to use the open session-in-view pattern (i.e. work per request), register this filter once in your Guice ServletModule. It is important that you register this filter before any other filter. For multiple providers, you should register this filter once per provider, inside a private module for each persist module installed (this must be the same private module where the specific persist module is itself installed).

Example configuration:

public class MyModule extends ServletModule {
    public void configureServlets() {
      filter("/*").through(PersistFilter.class);

      serve("/index.html").with(MyHtmlServlet.class);
      // Etc.
    }
  }
 

This filter is thread safe and allows you to create injectors concurrently and deploy multiple guice-persist modules within the same injector, or even multiple injectors with persist modules withing the same JVM or web app.

This filter requires the Guice Servlet extension.

Author:
Dhanji R. Prasanna (dhanji@gmail.com)

Constructor Summary
PersistFilter(UnitOfWork unitOfWork, PersistService persistService)
           
 
Method Summary
 void destroy()
           
 void doFilter(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse, javax.servlet.FilterChain filterChain)
           
 void init(javax.servlet.FilterConfig filterConfig)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistFilter

@Inject
public PersistFilter(UnitOfWork unitOfWork,
                            PersistService persistService)
Method Detail

init

public void init(javax.servlet.FilterConfig filterConfig)
          throws javax.servlet.ServletException
Specified by:
init in interface javax.servlet.Filter
Throws:
javax.servlet.ServletException

destroy

public void destroy()
Specified by:
destroy in interface javax.servlet.Filter

doFilter

public void doFilter(javax.servlet.ServletRequest servletRequest,
                     javax.servlet.ServletResponse servletResponse,
                     javax.servlet.FilterChain filterChain)
              throws IOException,
                     javax.servlet.ServletException
Specified by:
doFilter in interface javax.servlet.Filter
Throws:
IOException
javax.servlet.ServletException


Copyright © 2006-2011 Google, Inc.. All Rights Reserved.