Hi,
made by Ijonas Kisselbach:

Step 1. You should have a getConnection() method that returns a
java.sql.Connection object, which is retrieved through Context.lookup(). We
use a base class with the following method:

  protected Connection getConnection() throws SQLException {
    Connection conn = null;
    Object o;

    String url = "java:comp/env/jdbc/MyDB";
    if (ds == null) {
      try {
        o =  ctx.lookup(url);
        ds = (javax.sql.DataSource) o;
      } catch (NamingException e) {
        throw new SQLException("Cannot find "+url+"\n"+e.getMessage());
      }
    }
    return ds.getConnection();
  }

Your ejb-jar.xml should look like this:

    <entity>
      <ejb-name>MyBean</ejb-name>
      <home>MyBeanHome</home>
      <remote>MyBean</remote>
      <ejb-class>MyBean</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      <reentrant>False</reentrant>
      <resource-ref>
         <res-ref-name>jdbc/MyDB</res-ref-name>
         <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
      </resource-ref>
    </entity>

The url used in getConnection() refes to the res-ref-name entry in your
ejb-jar.xml

The res-ref-name is then further used in your jboss.xml

     <resource-managers>
         <resource-manager
res-class="org.jboss.ejb.deployment.JDBCResource">
             <res-name>jdbc/access</res-name>
             <res-jndi-name>java:/MyDB</res-jndi-name>
         </resource-manager>
     </resource-managers>

    <enterprise-beans>
       <entity>
           <ejb-name>MyBean</ejb-name>
           <jndi-name>my/MyBeanHome</jndi-name>
           <configuration-name></configuration-name>
           <resource-ref>
               <res-ref-name>jdbc/MyDB</res-ref-name>
               <resource-name>jdbc/access</resource-name>
           </resource-ref>
      </entity>
        </enterprise-beans>

Eventually, we end up with the res-jndi-name in jboss.xml referring to the
connection pool name specified in jboss.jcml

  <mbean code="org.jboss.jdbc.XADataSourceLoader"
name="DefaultDomain:service=XADataSource,name=MyDB">
    <attribute name="PoolName">MyDB</attribute>
    <attribute
name="DataSourceClass">org.opentools.minerva.jdbc.xa.wrapper.XADataSourceImp
l</attribute>
    <attribute
name="Properties">URL=jdbc:oracle:thin:servsoft/servsoft@pluto:1521:servsoft
</attribute>
    <attribute name="URL">jdbc:oracle:thin:@pluto:1521:servsoft</attribute>
    <attribute name="JDBCUser">user</attribute>
    <attribute name="Password">pwd</attribute>
  </mbean>

Hope this helps. Let me know if you need more.

Regs,
Ijonas.

----- Original Message -----
From: "G.L. Grobe" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 19, 2001 7:02 AM
Subject: Re: [JBoss-user] dbase is acting way too slow


> I didn't know about having to do datasource's w/ app servers, but I can
see
> how the db pooling would not have been used. Thnxs, this looks like my
> problem.
>
> Now I'm trying to get a proper mapping w/ a resource manager and resource
> reference in jboss.xml. Currently w/ this config, I get an exception of
> 'jdbc not bound', but I'm sure it's not all correct.
>
> Chptr 6 talks about resource refs, but using jboss-web.xml, and I'm having
a
> hard enough time as it is w/ all these descriptors. Can someone verify my
> below configuration.
>
> --- MyServlet.java -------------------------
> (this all works and calls the session bean below correctly)
> ...
>   Object result = ctx.lookup("java:comp/env/ejb/DBaseListMaps");
> ...
>
> --- MySessionBean.java ---------------------
>    public Connection getConnection() throws SQLException {
>
>       if (dataSource == null) {
>          try {
>             Context context = new InitialContext();
>             dataSource = (DataSource)
>                context.lookup("java:comp/env/jdbc/PostgresqlDB");
>          }
>          catch (Exception e) {
>             throw new SQLException("getConnection failed:" +
>                e.toString());
>          }
>       }
>
>       return dataSource.getConnection();
>    }
>
> --- jboss.xml ------------------------------
> ...
>    <resource-managers>
>       <resource-manager>
>          <res-name>jdbc/PostgresqlDB</res-name>
>          <res-type>javax.sql.DataSource</res-type>
>          <res-jndi-name>PostgresqlDB</res-jndi-name>
>       </resource-manager>
>    </resource-managers>
>
>    <enterprise-beans>
>       <session>
>          <ejb-name>DBaseListMaps</ejb-name>
>          <jndi-name>ejb/DBaseListMaps</jndi-name>
>          <resource-ref>
>             <res-ref-name>jdbc/PostgresqlDB</res-ref-name>
>             <resource-name>PostgresqlDB</resource-name>
>          </resource-ref>
>       </session>
>    </enterprise-beans>
> ...
>
> --- ejb-jar.xml ----------------------------
> ...
>    <session>
>    <ejb-name>DBaseListMaps</ejb-name>
>    <home>com.neuroquest.cais.ejb.session.dbaseFetch.DBaseFetchHome</home>
>    <remote>com.neuroquest.cais.ejb.session.dbaseFetch.DBaseFetch</remote>
>
>
<ejb-class>com.neuroquest.cais.ejb.session.dbaseFetch.DBaseFetchBean</ejb-cl
> ass>
>    <session-type>Stateless</session-type>
>    <transaction-type>Container</transaction-type>
>    </session>
> ...
>
> --- jboss-web.xml --------------------------
> ...
>    <ejb-ref>
>       <ejb-ref-name>ejb/DBaseListMaps</ejb-ref-name>
>       <jndi-name>DBaseListMaps</jndi-name>
>    </ejb-ref>
> ...
>
> --- web.xml -------------------------------
> ...
>    <ejb-ref>
>       <ejb-ref-name>ejb/DBaseListMaps</ejb-ref-name>
>       <ejb-ref-type>Session</ejb-ref-type>
>
<home>com.neuroquest.cais.ejb.session.dbaseFetch.DBaseFetchHome</home>
>
<remote>com.neuroquest.cais.ejb.session.dbaseFetch.DBaseFetch</remote>
>       <ejb-link>DBaseListMaps</ejb-link>
>    </ejb-ref>
> ...
>
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user


_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to