I use another pool, but I have some context params, as I put below, and a pool servlet that instantiate all the pools and centralizes the connections. So you can see the connection state from a central point. If some is interested i can make it available. The only think you have to change is the pool creation.

This way, apps can share pools (I know that dbcp can do it too, it didn't exist at that time) and to add a new one, just change this file.
Beyond that, you have to put the jar with the lib in common lib, so every app will get the same pool manager.


Names of parameters are in portuguese, but i think you can get the idea.


<context-param> <param-name>alias1</param-name> <param-value>ca...</param-value> </context-param> <context-param> <param-name>host1</param-name> <param-value>hostvalue1</param-value> </context-param> <context-param> <param-name>senha1</param-name> <param-value>thepassword1</param-value> </context-param> <context-param> <param-name>sid1</param-name> <param-value>databasename1</param-value> </context-param> <context-param> <param-name>user1</param-name> <param-value>username</param-value> </context-param>


<context-param> <param-name>alias2</param-name> <param-value>descartaweb</param-value> </context-param> <context-param> <param-name>user2</param-name> <param-value>usename2</param-value> </context-param> <context-param> <param-name>senha2</param-name> <param-value>pass2</param-value> </context-param> <context-param> <param-name>host2</param-name> <param-value>hostname2</param-value> </context-param> <context-param> <param-name>sid2</param-name> <param-value>adm</param-value> </context-param>

SANTOS, DANIEL (SBCSI) wrote:
I use a method similar to this as well.  I don't use a servlet listener however.  I 
use a javax.servlet.ServletContextListener instead however.  I store the jdbd url in 
my web.xml also as a context-param (I just just cram it all into one paramater 
however) and put the pool as an attribute of the Context.  Here is the shorthand for 
that below:

public void contextInitialized(ServletContextEvent sce) {
    String dbUrl = sce.getServletContext().getInitParameter("dbUrl")
    OracleDataSource pool = new OracleDataSource();
    pool.setURL(dbUrl);
    sce.getServletContext().setAttribute("dbConnectionPool", pool);
}

and I have my classes12.zip (renamed to .jar) in my WEB-INF/lib folder
-----Original Message-----
From: David Short [mailto:[EMAIL PROTECTED]
Sent: Friday, July 02, 2004 12:40 PM
To: 'Tomcat Users List'
Subject: RE: How to use oracle pool instead of using DBCP pool?


I'm sure there's another way. This is how I use it. You can extract the connection pool logic and embed in your framework.

-----Original Message-----
From: Claudio Carvalho [mailto:[EMAIL PROTECTED]
Sent: Friday, July 02, 2004 10:33 AM
To: Tomcat Users List; [EMAIL PROTECTED]
Subject: Re: How to use oracle pool instead of using DBCP pool?


Hi Davi,

Thanks, but I'm trying to solve this problem without changing my J2EE
framework... using JNDI,etc...
Do you know any other approach?

Claudio Carvalho.

----- Original Message -----
From: "David Short" <[EMAIL PROTECTED]>
To: "'Tomcat Users List'" <[EMAIL PROTECTED]>
Sent: Friday, July 02, 2004 1:55 PM
Subject: RE: How to use oracle pool instead of using DBCP pool?



Try this.

Here's how I do it using Struts on W2K. Modify names and paths to suit

your

needs.

Upon startup, a listener servlet (ResourceManagerListener) is called (See
<listener> tag in the included web.xml source).

The listener servlet will create the connection pool based on your web.xml
parameters (See ResourceManagerListener.java).  Once started, the listener
servlet initializes an application scope variable (appDataSource), which
when called from your servlets/JSPs will return a DB DataSource object (DB
connection).

--------------------------------------------------------------------------

--

---------------------------

In your main servlet:

try
 {
 DataSource ds = (DataSource)
getServlet().getServletContext().getAttribute("appDataSource");
 xxxProcess = new xxxProcessBean();
 xxxInfo = new xxxInfoBean();
 xxxProcess.setDataSource(ds);
 xxxInfo = xxxProcess.getUser(userName, customerId);
 }

In your process bean:

public class xxxProcessBean implements Serializable
 {
 private DataSource dataSource;

 /**
  * Sets the dataSource property value.
  */
 public void setDataSource(DataSource dataSource)
   {
   this.dataSource = dataSource;
   }


public xxxInfoBean getUser(String userName, String customerId) throws SQLException { // Get the user info from the database Connection conn = dataSource.getConnection(); xxxInfoBean xxxResult = null;

   try
     {
     xxxResult = getUserName(userName, customerId, conn);  // Execute
actual SQL statement.
     }

   finally
     {
     try
       {
       conn.close();
       conn = null;
       }

   catch (SQLException e)
     {} // Ignore

   return xxxResult;

--------------------------------------------------------------------------

--

---------------------------

Change MachineNameHere to your machine name.
Change OracleSIDHere to your DB SID.
Change DBUserNameHere to your DB username.
Change DBPasswordHere to your DB password
Change ApplicationNameHere to a meaningful application designator.
Change xxx to your object name.

Copy Oracle's classes12.zip and nls_charset12.zip files (should live in
C:\OraHome\jdbc\lib) to C:\Tomcat\common\lib.  Depending on the version of
Tomcat, you may need to rename the .zip files to .jar.


I'll let you read/learn about Struts on your own.

Hoe this helps.

Dave

--------------------------------------------------------------------------

--

---------------------------
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
 PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com//dtd/web-app_2_3.dtd";>

<web-app>
 <!-- Used by the JSTL I18N actions -->
 <context-param>
   <param-name>javax.servlet.jsp.jstl.fmt.fallbackLocale</param-name>
   <param-value>en</param-value>
 </context-param>

 <!-- Context parameters for application -->

 <!-- Oracle thin JDBC driver -->
 <!--



<param-value>jdbc:oracle:thin:@MachineNameHere:1521:OracleSIDHere</param-val

ue>
 -->
 <context-param>
   <param-name>jdbcURL</param-name>
   <!-- Oracle OCI JDBC driver -->
   <param-value>jdbc:oracle:oci8:@OracleSIDHere</param-value>
 </context-param>

 <context-param>
   <param-name>user</param-name>
   <param-value>DBUserNameHere</param-value>
 </context-param>

 <context-param>
   <param-name>password</param-name>
   <param-value>DBPasswordHere</param-value>
 </context-param>

 <context-param>
   <param-name>maxLimit</param-name>
   <param-value>50</param-value>
 </context-param>

 <!--
   will create 10 pooled connections.
 -->
 <context-param>
   <param-name>minLimit</param-name>
   <param-value>10</param-value>
 </context-param>

 <!-- Filter and listener configurations -->
 <filter>
   <filter-name>accessControl</filter-name>
   <filter-class>
     com.ApplicationNameHere.servlets.AccessControlFilter
   </filter-class>
   <init-param>
     <param-name>loginPage</param-name>
     <param-value>/jsp/login.jsp</param-value>
   </init-param>
 </filter>

 <filter-mapping>
   <filter-name>accessControl</filter-name>
   <url-pattern>/protected/*</url-pattern>
 </filter-mapping>

 <listener>
   <listener-class>
     com.ApplicationNameHere.servlets.ResourceManagerListener
   </listener-class>
 </listener>

 <!-- Struts Controller servlet -->
 <servlet>
   <servlet-name>action</servlet-name>
   <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
 </servlet>

 <!-- Servlet for handling both servlet and JSP errors -->
 <servlet>
   <servlet-name>errorDispatcher</servlet-name>


<servlet-class>com.ApplicationNameHere.servlets.ErrorDispatcherServlet</serv

let-class>
   <init-param>
     <param-name>errorPage</param-name>
     <param-value>/jsp/error/errorpage.jsp?debug=log</param-value>
   </init-param>
 </servlet>

 <!-- Struts Controller servlet mapping -->
 <servlet-mapping>
   <servlet-name>action</servlet-name>
   <url-pattern>*.do</url-pattern>
 </servlet-mapping>

 <servlet-mapping>
   <servlet-name>errorDispatcher</servlet-name>
   <url-pattern>/errorDispatcher</url-pattern>
 </servlet-mapping>

 <!-- Session timeout value (in minutes) -->
 <session-config>
   <session-timeout>1</session-timeout>
 </session-config>

 <!--
   Uncomment if you want all exceptions and 500 status codes to
   be handled by the customized error page.
 -->
 <error-page>
   <exception-type>java.lang.Throwable</exception-type>
   <location>/errorDispatcher</location>
 </error-page>

 <error-page>
   <error-code>500</error-code>
   <location>/errorDispatcher</location>
 </error-page>

 <error-page>
   <exception-type>java.sql.SQLException</exception-type>
   <location>/errorDispatcher</location>
 </error-page>

 <resource-ref>
   <res-ref-name>jdbc/ApplicationNameHere</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
 </resource-ref>

</web-app>

--------------------------------------------------------------------------

--

---------------------------
ResourceManagerListener.java
package com.ApplicationNameHere.servlets;

import javax.servlet.*;
import javax.servlet.http.*;

import oracle.jdbc.pool.*;

import javax.naming.*;
import javax.sql.*;

import java.sql.*;
import java.math.*;
import java.util.*;

/**
* This class manages the DataSource resource for an 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 David Short, Relational Concepts, Inc.
* @version David Short     01/10/2004     initial release.
*/
public class ResourceManagerListener implements ServletContextListener
 {
 private OracleConnectionCacheImpl ds = null;
 private Context ctx = null;

 public void contextInitialized(ServletContextEvent sce)
   {
   ServletContext application  = sce.getServletContext();

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

   try
     {
     ds = new OracleConnectionCacheImpl();
     ds.setURL(jdbcURL);
     ds.setUser(user);
     ds.setPassword(password);
     ds.setMinLimit(Integer.parseInt(minLimit));
     ds.setMaxLimit(Integer.parseInt(maxLimit));
     }
   catch (Exception e)
     {
     application.log("Failed to create data source: " + e.getMessage());
     }

   /*
     Initialize the database connection pool.
   */
   try
     {
     ctx = new InitialContext();
     ctx.lookup("java:comp/env/jdbc/ApplicationNameHere");
     }
   catch (Exception e)
     {
     application.log("Failed to create database connection pool: " +
e.getMessage());
     }

   application.setAttribute("appDataSource", ds);
   }

 public void contextDestroyed(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;
   }
 }

-----Original Message-----
From: Tim Funk [mailto:[EMAIL PROTECTED]
Sent: Friday, July 02, 2004 8:36 AM
To: Tomcat Users List
Subject: Re: How to use oracle pool instead of using DBCP pool?


Nope. (Oracle's technical support /bulletin boards might be of more help)

-Tim

Claudio Carvalho wrote:


Hi Tim,

I'm looking for an alternative directly on the application server,

something

like putting an "oracle-pool" jar into tomcat/common/lib directory, have

you

heard anything like that?

Claudio Carvalho.

----- Original Message -----
From: "Tim Funk" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Friday, July 02, 2004 10:52 AM
Subject: Re: How to use oracle pool instead of using DBCP pool?




An alternative is to look at the DBCP java-docs. Cast your Connection to

a

DBCP's ppoled connection class (or approrpiate). That class has a method
called getDelegate() which returns the real connection from Oracle. Then

cast


that to the appropriate Oracle class.

-Tim

Claudio Carvalho wrote:



Cláudio CarvalhoHi,

I'm trying to get the CLOB working in my application and I'm having

problems


with the Connection, so, does anybody knows how to use in Tomcat 5 the
oracle pool instead of using the DBCP pool?


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Emerson Cargnin
Analista de Sistemas - Gerente Regional - Tubarão
Setor de Desenvolvimento de Sistemas - TRE-SC
tel : (048) - 251-3700 - Ramal 3181

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to