This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of DevSecOps Adventures: A Game-Changing Approach with Chocolate, LEGO, and Coaching Games and have Dana Pylayeva on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

DataSource in ejb-jar.xml

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I reposting my question :
Chris Thanks for all your help .
Could you please suggest me where to specify this datasource in ejb-jar.xml & jndi name with datasource in ejb-weblogic-jar.xml
Following is my ejb-jar.xml:
<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>statelessSession</ejb-name>
<home> myapp.MYAPPWebServiceHome</home>
<remote> myapp.MYAPPWebService</remote>
<ejb-class> myapp.MYAPPWebServiceBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>statelessSession</ejb-name>
<method-intf>Remote</method-intf>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
<container-transaction>
</assembly-descriptor>
</ejb-jar>
following is my ejb-weblogic-jar.xml :
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 5.1.0 EJB//EN' 'http://www.bea.com/servers/wls510/dtd/weblogic-ejb-jar.dtd'>
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>statelessSession</ejb-name>
<caching-descriptor>
<max-beans-in-free-pool>100</max-beans-in-free-pool>
</caching-descriptor>
<jndi-name>stateless.MYAPPWebServiceHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

Following is my code in the ejb method:
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,
"t3://hostName:7001");
// Get a context for the JNDI look up
ctx = new InitialContext(ht);
javax.sql.DataSource ds
= (javax.sql.DataSource) ctx.lookup ("mydataSource-OracleThinDriverPool");
conn = ds.getConnection();
Thanks,
smita
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't NEED to specify the datasource in your ejb descriptors. It is just a way to avoid hardcoding the datasource's JNDI name in your code. If all of your EJBs use the same datasource and there is no immediate need to use separate datasource that I would put the JNDI name directly in code. Create a helper class for retrieving the connection and have it coded there in one place. I have created a class to this in my projects.
Here is a simple class for this purpose. It uses another class to get an initial context went is not shown:

Usage looks like this:

The thing that I like is that I now have strong compile-time checking on my connection pool usage. If you use the DD and you make a typo in 1 of your 10 ejbs, then you won't know until the first time you access that bean. This way you have one central place to change all your connection pool configuration and if it works for one, it will work for all.
The other benefit is that if you want to know where a connection pool is being used, comment out one line and let the compiler find all the dangling references.
Of course, this means that a change in configuration means a change in code... but I can live with that. If it turns out to be a bad idea in the future than I will just refactor it out!

Imports, comments, and additional code has been left out to protect the innoccent.
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course this doesn't work with CMP. In that case you have to specify the datasource in your deployment descriptor.
 
peter brews
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much.
If you don't mind could you please advise
what is the diffrence between Txdatasource and datasource.

I have diffrent databases on diffrent machines. All i need to do is to pass the url,sid etc
for each of the machine/database and get the data.
for ex>
one is
url :jdbc racle:thin:@mydevelopmentmc:1521 EMO
user: abc
password:abc
my another url is
url :jdbc racle:thin:@mytestmc:1521:TEST
user: abctest
password:abctest
I am planning to create two connection pools one for each
also two corresponding data sources.
Is there any better solution.please advise
Thanks again
smita
 
His brain is the size of a cherry pit! About the size of this ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic