001 /** ===================================================================== 002 * 003 * File Name : $Id: DBCPoolingListener.java,v 1.3 2008/01/15 11:08:15 cb Exp $ 004 * 005 * Description 006 * ----------- 007 * 008 * See javadoc comment 009 * 010 * ===================================================================== 011 * 012 * @Author : Craige Bevil 013 * Control Software Group 014 * Isaac Newton Group of Telescopes 015 * 016 * ===================================================================== 017 * 018 * Modification Log 019 * 020 * Vers Date Author Reason 021 * ---- ---- ------ ------ 022 * 1 9 May 2007 C.Bevil First Release 023 * 024 * Commissioning Notes 025 * ------------------- 026 * 027 * None 028 * 029 * ===================================================================== 030 * 031 * @Version : $Id: DBCPoolingListener.java,v 1.3 2008/01/15 11:08:15 cb Exp $ 032 * 033 * @Author : $Author: cb $ 034 * 035 * Header : $Header: /opt/INGsrc/src/CVS/softproj/FaultDatabase/src/FaultDatabase/FaultDatabase/src/GWTApplication/server/DBCPoolingListener.java,v 1.3 2008/01/15 11:08:15 cb Exp $ 036 * 037 * Log : $Log: DBCPoolingListener.java,v $ 038 * Log : Revision 1.3 2008/01/15 11:08:15 cb 039 * Log : Ran through PMD and sorted out the javadoc so that we could export the 040 * Log : javadoc to the javadoc repository. 041 * Log : 042 * Log : Revision 1.2 2007/08/01 13:00:03 cb 043 * Log : First prototype after import 044 * Log : 045 * Log : Revision 1.1.1.1 2007/06/01 08:33:25 cb 046 * Log : Imported using TkCVS 047 * Log : 048 * 049 * =====================================================================*/ 050 051 package GWTApplication.server; 052 053 import javax.servlet.*; 054 import javax.naming.*; 055 import javax.sql.DataSource; 056 057 /** 058 * This is a class which will be called by Tomcat when the servlet for 059 * the fault database is loaded by the container and will result in 060 * the database connection pool being initialised. The servlet when 061 * connecting to the database will use a connection from the database 062 * pool so as to accelerate the database access. 063 * @author Craige Bevil 064 * @version $Id: DBCPoolingListener.java,v 1.3 2008/01/15 11:08:15 cb Exp $ 065 */ 066 067 public class DBCPoolingListener implements ServletContextListener { 068 069 /** 070 * This is called when the fault database context is created in 071 * the servlet and serves to initialise the database pool intended 072 * to be used by the fault management system in the tomcat 073 * servlet. It looks up the data source in the tomcat container 074 * which will provide the handle through which we will get 075 * database connections. 076 *<P> 077 * The configuration data for the pool (pertinent to the fault management system) is stored within the tomcat configuration data. 078 * @param sce This is the details of the servlet context event. 079 */ 080 081 public void contextInitialized (ServletContextEvent sce) { 082 083 try { 084 085 // Obtain our environment naming context 086 087 Context envCtx = (Context) new InitialContext().lookup("java:comp/env"); 088 089 // Look up our data source which is a connection to the 090 // postgres database 091 092 DataSource ds = (DataSource) envCtx.lookup("jdbc/faultDBAccess"); 093 094 sce.getServletContext().setAttribute("DBCPool", ds); 095 096 } catch(NamingException e){ 097 e.printStackTrace(); 098 } 099 } 100 101 public void contextDestroyed(ServletContextEvent sce){ 102 } 103 }