1 package org.jbpm.webapp.filter; 2 3 import java.io.IOException ; 4 5 import javax.servlet.Filter ; 6 import javax.servlet.FilterChain ; 7 import javax.servlet.FilterConfig ; 8 import javax.servlet.ServletException ; 9 import javax.servlet.ServletRequest ; 10 import javax.servlet.ServletResponse ; 11 12 import org.jbpm.webapp.context.Context; 13 import org.jbpm.webapp.context.PersistenceContext; 14 15 public class PersistenceFilter implements Filter { 16 17 public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException , ServletException { 18 boolean exceptionOccurred = true; 20 21 PersistenceContext persistenceContext = Context.getPersistenceContext(); 23 try { 24 persistenceContext.beginTransaction(); 26 27 filterChain.doFilter(servletRequest, servletResponse); 29 30 exceptionOccurred = false; 32 33 } finally { 34 if (exceptionOccurred) { 36 persistenceContext.setRollbackOnly(); 38 } 39 persistenceContext.endTransaction(); 41 } 42 } 43 44 public void init(FilterConfig filterConfig) throws ServletException { 45 } 46 47 public void destroy() { 48 } 49 50 } 52 | Popular Tags |