Hi!

I just went through this myself and I got some help
from a very nice Dane!!!!!! :-) I don't think he would
mind me posting his email to me on the subject. I
suggest you follow his steps exactly, but filling in
your data in place of his. There's a lot more to this
for jboss than meets the eye, so again, follow these
steps closely.

In particular, pay attention to the jboss.xml stuff
regarding "resource-managers" and the link in the same
file to the EJB jndi references. That's what you need.
But, like I said, there's more!

BTW, THIS SHOULD BE ADDED TO THE DOCS!!! THERE ARE BIG
GAPS IN THE EXISTING ONLINE DOCS FOR THIS!!!

Vaughn

============(snip)================

Ok here goes:

In jboss.conf I specify a datasource:

<MLET CODE="org.jboss.jdbc.XADataSourceLoader"
ARCHIVE="jboss.jar, interclient-core.jar"
CODEBASE="../../lib/ext/">
    <ARG TYPE="java.lang.String" VALUE="InterBase">
    <ARG TYPE="java.lang.String"
VALUE="org.jboss.minerva.xa.XADataSourceImpl">
</MLET>

The important thing here is its name "InterBase"

This name is again used in the mbean definition in
jboss.jcml:

<mbean
name="DefaultDomain:service=XADataSource,name=InterBase">
  <attribute name="Properties"></attribute>
  <attribute
name="URL">jdbc:interbase://localhost/e:/tmp/gdb.gdb</attribute>
  <attribute name="GCMinIdleTime">1200000</attribute>
  <attribute name="JDBCUser">xxx</attribute>
  <attribute name="MaxSize">0</attribute>
  <attribute name="Password">yyy</attribute>
  <attribute name="GCEnabled">false</attribute>
  <attribute
name="InvalidateOnError">false</attribute>
  <attribute name="TimestampUsed">false</attribute>
  <attribute name="Blocking">true</attribute>
  <attribute name="GCInterval">120000</attribute>
  <attribute name="IdleTimeout">1800000</attribute>
  <attribute
name="IdleTimeoutEnabled">false</attribute>
  <attribute name="LoggingEnabled">false</attribute>
  <attribute
name="MaxIdleTimeoutPercent">1.0</attribute>
  <attribute name="MinSize">0</attribute>
</mbean>

in standardjaws.xml I have the following datasource:

<datasource>java:/InterBase</datasource>

In my ejb-jar.xml I add a resource of type datasource
to the bean using it:
The name used here is "jdbc/DBPool" which will make
the lookup (when used
in a bean) look like "java:comp/env/jdbc/DBPool"

<session>
  <ejb-name>ItemManagerEJB</ejb-name>
 
<home>com.netmill.cityshop.interfaces.item.ItemManagerEJBHome</home>
 
<remote>com.netmill.cityshop.interfaces.item.ItemManagerEJB</remote>
 
<ejb-class>com.netmill.cityshop.ejb.item.ItemManagerEJBBean</ejb-class>
  <session-type>Stateless</session-type>
  <transaction-type>Bean</transaction-type>
  <resource-ref>
    <description>DataSource connected to the cityshop
database.</description>
    <res-ref-name>jdbc/DBPool</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
</session>


In jboss.xml I add a resource manager for the
application, it gets bound to
"InterBase" specified in jboss.conf:

<resource-managers>
  <resource-manager
res-class="org.jboss.ejb.deployment.JDBCResource">
  <res-name>CityShopDataSourceManager</res-name>
  <res-jndi-name>InterBase</res-jndi-name>
  </resource-manager>
</resource-managers>

and again in jboss.xml I add the resource for the bean
which is using the datasource

<session>
  <ejb-name>ItemManagerEJB</ejb-name>
  <jndi-name>item/ItemManager</jndi-name>
  <configuration-name></configuration-name>
  <resource-ref>
    <res-ref-name>jdbc/DBPool</res-ref-name>
   
<resource-name>CityShopDataSourceManager</resource-name>
  </resource-ref>
</session>

By now I should have a naming chain like this going:

java:comp/env/jdbc/DBPool -> CityShopDataSourceManager
-> InterBase

so finnally in the bean code I can use something like:

Context ctx = new InitialContext();
Connection conn = null;
try {
  DataSource ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/DBPool");
  conn = ds.getConnection();
  System.out.println("Yahooo... got it!!! :-)");
  } catch(NamingException ne) {
  System.out.println("NamingException caught:" +
ne.getMessage());
  } catch(SQLException se) {
  System.out.println("SQLException caught:" +
se.getMessage());
  } finally {
  if(conn != null)
  try {
    conn.close();
  } catch(SQLException e){}
}

to get "Yahooo... got it!!! :-)" printed to standard
out :-)

Hope it helps...

^torsten

btw. I can see that you use comp/env/... in you
deployment descriptors.

>From what I understand you should never yourself
specify the comp/env

prefix since it is automatically prefixed when you
look up a name in

some bean context!

===========(end snip)=====================

From: "Jerson Chua" <[EMAIL PROTECTED]>  | Block
address 
To: "jBoss" <[EMAIL PROTECTED]> 
Subject: [jBoss-User] Accesing DataSource thru
resource-ref 
Date: Wed, 29 Nov 2000 11:20:14 +0800 
Reply-to: "jBoss" <[EMAIL PROTECTED]> 
        Add Addresses  

Hi everyone...
I'm trying to access the DataSource using res-ref-name
like

        DataSource ds = (DataSource) new
InitialContext().lookup(
                "java:comp/env/jdbc/CatalystDS");

But I think I'm getting a different connect coz the
table i'm trying to
query is not available.

Here's my descriptor... can you please check what's
wrong

ejb-jar.xml
<ejb-jar>
  <description>jBoss test application </description>
  <display-name>Test</display-name>
  <enterprise-beans>
    <session>
      <ejb-name>Interest</ejb-name>
     
<home>com.web_tomorrow.interest.InterestHome</home>
     
<remote>com.web_tomorrow.interest.Interest</remote>
     
<ejb-class>com.web_tomorrow.interest.InterestBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Bean</transaction-type>
      <resource-ref>
          <res-ref-name>jdbc/CatalystDS</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
      </resource-ref>
    </session>
  </enterprise-beans>
</ejb-jar>


jboss.xml
<?xml version="1.0" encoding="Cp1252"?>

<jboss>
  <secure>false</secure>
  <container-configurations />
  <resource-managers />
  <enterprise-beans>
     <session>
       <ejb-name>Interest</ejb-name>
       <jndi-name>interest/Interest</jndi-name>
       <configuration-name></configuration-name>

        <resource-ref>
           
<res-ref-name>jdbc/CatalystDS</res-ref-name>
            <resource-name>CatalystDS</resource-name>
<!-- In weblogic, 
this
is a jndi name. -->
        </resource-ref>

      <resource-managers>
        <resource-manager>
          <res-name>CatalystDS</res-name>
         
<res-jndi-name>java:/CatalystDS</res-jndi-name>
        </resource-manager>
      </resource-managers>


     </session>
  </enterprise-beans>
</jboss>

I have successfully created a DataSource. In JBoss
console, it prints 
that
CatalystDS is bound to java:/CatalystDS. Now, my
question how do I link 
the
jdbc/CatalystDS to the CatalystDS. How do I specify
the jndi name for 
the
data source? How do I specify the jndi name of the
datasource?

Please help. Thanks in advance.

Jerson



__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to