FileDocCategorySizeDatePackage
ResourceManagerListener2.javaAPI DocExample1899Tue Feb 28 11:34:06 GMT 2006com.ora.jsp.servlets

ResourceManagerListener2

public class ResourceManagerListener2 extends Object implements ServletContextListener
This class manages the DataSource resource for a fictious application, creating an Oracle DataSource with pooling capabilities and makes it available when the application starts and removes it when the application is shut down.
author
Hans Bergsten, Gefion software
version
1.0

Fields Summary
private OracleConnectionCacheImpl
ds
Constructors Summary
Methods Summary
public voidcontextDestroyed(javax.servlet.ServletContextEvent sce)

        ServletContext application  = sce.getServletContext();
        application.removeAttribute("appDataSource");
        // Close the connections in the DataSource
        try {
            ds.close();
        }
        catch (java.sql.SQLException e) {}
	ds = null;
    
public voidcontextInitialized(javax.servlet.ServletContextEvent sce)


        

        ServletContext application  = sce.getServletContext();

        /*
         * Get the JDBC URL, user, password and limit from the web.xml
         * context init parameters
         */
        String jdbcURL = application.getInitParameter("jdbcURL");
        String user = application.getInitParameter("user");
        String password = application.getInitParameter("password");
        String maxLimit = application.getInitParameter("maxLimit");

        try {
            ds = new OracleConnectionCacheImpl();
            ds.setURL(jdbcURL);
            ds.setMaxLimit(Integer.parseInt(maxLimit));
            ds.setUser("scott");
            ds.setPassword("tiger");
        }
        catch (Exception e) {
            application.log("Failed to create data source: " + e.getMessage());
        }
        application.setAttribute("appDataSource", ds);