Hi,

Following up on this earlier discussion:
http://groups.google.com/group/google-guice/browse_frm/thread/7252f908ef00638a/9a59803c16a9583e?lnk=gst&q=clean+%40requestscoped#9a59803c16a9583e

What is the best way to clean up a @RequestScoped JDBC connection? Am
I supposed to register a second ServletFilter after GuiceFilter (shown
below) or is there an easier way?

public class ConnectionFilter implements Filter
{
        private ServletContext context;

        @Override
        public void init(FilterConfig filterConfig) throws ServletException
        {
                this.context = filterConfig.getServletContext();
        }

        @Override
        public void doFilter(ServletRequest servletRequest, ServletResponse
servletResponse,
                                                                                
         FilterChain chain)
                throws IOException, ServletException
        {
                Injector injector = (Injector)
context.getAttribute(Injector.class.getName());
                Connection connection = injector.getInstance(Connection.class);

                try
                {
                        chain.doFilter(servletRequest, servletResponse);
                }
                finally
                {
                        connection.close();
                }
        }

        @Override
        public void destroy()
        {
        }
}


Thanks,
Gili

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to