01: package org.makumba.commons.attributes;
02:
03: import javax.servlet.FilterConfig;
04: import javax.servlet.ServletRequest;
05: import javax.servlet.ServletResponse;
06: import javax.servlet.http.HttpServletRequest;
07:
08: import org.makumba.commons.ControllerHandler;
09: import org.makumba.commons.DbConnectionProvider;
10:
11: public class DatabaseConnectionControllerHandler extends
12: ControllerHandler {
13:
14: private DbConnectionProvider dbcp;
15:
16: @Override
17: public boolean beforeFilter(ServletRequest request,
18: ServletResponse response, FilterConfig conf)
19: throws Exception {
20: // initalises a database pool (one connection per database) needed for the response (BL execution) and the attributes (BL attribute lookup)
21: dbcp = RequestAttributes
22: .getConnectionProvider((HttpServletRequest) request);
23: return true;
24: }
25:
26: @Override
27: public void afterBeforeFilter(ServletRequest request,
28: ServletResponse response, FilterConfig conf) {
29: dbcp.close();
30: }
31:
32: @Override
33: public void finalize(ServletRequest request,
34: ServletResponse response) {
35: dbcp.close();
36:
37: }
38:
39: }
|