Hi Sripada
The getConnection method that I wrote in my CMP bean is taking the
connection from the pool created by the server (Weblogic in this case). So I
am not opening any extra connection -- and hence not violating the
connection pooling. If u see the getConnection method below u will get this

--------------------------------------------------------------------
    public Connection getConnection()
      throws SQLException
    {
          //return
DriverManager.getConnection("jdbc:weblogic:jts:oraclePool");
      InitialContext ctx = null;
      try {
        ctx = new InitialContext();
        DataSource ds = (javax.sql.DataSource)
          ctx.lookup("java:comp/env/jdbc/oraclePool");
        return ds.getConnection();
      } catch(NamingException ne) {
        ne.printStackTrace();
        return null;
      } finally {
        try {
          if(ctx != null) ctx.close();
        } catch(NamingException ne) {
          ne.printStackTrace();
          return null;
        }
      }
  }
----------------------------------------------------------------------------

See here ctx.lookup("java:comp/env/jdbc/oraclePool") actually looks up the
DataSource for the pool created by weblogic --- as per the
weblogic.properties file

----------------------------------------------------------------------------
--
weblogic.jdbc.connectionPool.oraclePool=\
       url=jdbc:oracle:thin:@jabberwock:1521:utcm01,\
       driver=oracle.jdbc.driver.OracleDriver,\
       loginDelaySecs=1,\
       initialCapacity=4,\
       maxCapacity=10,\
       capacityIncrement=2,\
       allowShrinking=true,\
       shrinkPeriodMins=15,\
       refreshMinutes=10,\
       testTable=dual,\
       props=user=jamaica;password=bigtime

weblogic.allow.reserve.weblogic.jdbc.connectionPool.oraclePool=everyone
weblogic.jdbc.TXDataSource.weblogic.jdbc.jts.oraclePool=oraclePool
----------------------------------------------------------------------------
---

Hence the way I did the sequence stuff is utilizing the pool.

------------------------------------------------------------------
    public CustomerPK ejbCreate(String custname, int age)
      throws CreateException,
             RemoteException
    {
      System.out.println(" In create of Cust");
      this.custcode = getSeqCode();
      this.custname = custname;
      this.age      = age;

          return null;
    }

    private int getSeqCode()
    {

          try
          {
                  Connection con = getConnection();
                  PreparedStatement ps = con.prepareStatement("select
testseq.nextval from dual");
                  ps.executeQuery();
                  ResultSet rs = ps.getResultSet();
                  int i = 0;
                  while (rs.next())
                  {
                        i = rs.getInt(1);
                  }
                  rs.close();
                  return i;
          }
          catch(Exception e)
          {
                  e.printStackTrace();
                  return 0;
          }
        }
----------------------------------------------------------------------------
---------------------------

What u can say that is not CMP like is I am writing this piece of SQL code
on my own.
HTH
Ana
-----Original Message-----
From: Sripada Srinivas [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 04, 2000 6:21 AM
To: [EMAIL PROTECTED]
Subject: Re: Primary Key - sequence from Oracle


Hi Shiv,

Thanks for your detailed reply.

What I wanted to drive home is that using this approach, you are limiting
your
application to Weblogic server only. Is there any standard way of doing
this, so
that it is portable across different servers??

--Sripada

Shiv Kumar wrote:

> Hi
>
> The answer is weblogic specific.
>
> Configure a database pool in weblogic.properties file.
>
>      weblogic.jdbc.connectionPool.testPool=\
>             url=...,\
>             driver=...,\
>             ....
>      # Add a TXDataSource for the connection pool:
>      weblogic.jdbc.TXDataSource.weblogic.jdbc.jts.testPool=testPool
>
> Add the following entry to ejb-jar.xml
>
>      <resource-ref>
>        <res-ref-name>jdbc/labPool</res-ref-name>
>        <res-type>javax.sql.DataSource</res-type>
>        <res-auth>Container</res-auth>
>      </resource-ref>
>
> and the following to weblogic-ejb-jar.xml
>
>      <reference-descriptor>
>        <resource-description>
>          <res-ref-name>jdbc/labPool</res-ref-name>
>          <jndi-name>weblogic.jdbc.jts.labPool</jndi-name>
>        </resource-description>
>      </reference-descriptor>
>
> Now, from the bean you can access the connection pool like this :-
>
>      Context ctx = new InitialContext();
>      DataSource ds = (javax.sql.DataSource)
>      ctx.lookup("java:comp/env/jdbc/labPool");
>      Connection conn = ds.getConnection();
>
> For accessing oracle's sequence, I have a stateless session bean which has
a
> nextValue() and currentValue() method :-
>
>      -- SequenceBean.java --
>
>      public int nextValue(String sequenceName) {
>        int nextval;
>        String query = "select " + sequenceName + ".nextval from dual";
>        Statement stmt = conn.createStatement();
>        Resultset rs = stmt.executeQuery(query);
>        ..
>        ..
>        return nextval;
>      }
>
> Hope it helps.
> --
> shiv
> [EMAIL PROTECTED]
>
> Sripada Srinivas wrote:
>
> > Hi Ana,
> >
> > If you open a connection like this for every user, then the whole
purpose of
> > connection pooling used by the EJB Server is lost I suppose. (In CMP).
> >
> > By the way, is there anyway, I can get access to the connection pools
used by
> > the EJB Servers?? Does any of the EJB servers provide API to access the
> > connections in their connection pool??
> >
> > Regards,
> > Sripada
> >
>
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff EJB-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to