Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Accessing to Java EE DataSource from an extension

Is it possible? How?
RTC seems to use Java EE DataSources defined in the Application Server but I haven't found any way to do it.

Thanks in advance,

     Chemi.

0 votes



3 answers

Permanent link

Jose,

By default RTC uses direct JDBC, it can use Java EE DS from the App Server if configured to do so, you can set it in the Database connection on the admin page.

Check the topic, Configuring Database Connection in the IC:

http://pic.dhe.ibm.com/infocenter/clmhelp/v4r0m1/index.jsp?topic=%2Fcom.ibm.jazz.repository.web.admin.doc%2Ftopics%2Ftconfigdbconnection.html

Sandy

0 votes

Comments

Hi Sandy, I understand that documentation is to setup RTC itself.
I was looking for a way to access a DS from custom code in a RTC Extension. In my case, for example, the lookups never work. Thanks.

I try to create a JNDI InitialContext and it is always null:

Context initialContext = new InitialContext();

I always get a javax.naming.NoInitialContextException so it seems to me I haven't access to Java EE environment from a RTC Extension. Should I add anything to dependencies?


Permanent link
I think I found a way to do it, although I am sure it is not supported:

1.- Add following plug-in as a dependency in your manifest file: com.ibm.team.repository.jndi
2.- Make sure you have an Activator in your plug-in
3.- Use following code:

try
{
  BundleContext bundleContext = Activator.getContext();
  IJNDIService testService = (IJNDIService)bundleContext.getService(bundleContext.getServiceReference(IJNDIService.class.getName()));
           
  Context initialContext = testService.getInitialContext();
  DataSource datasource = (DataSource)initialContext.lookup("java:comp/env/jdbc/YourDB");
  Connection con = datasource.getConnection();
  ....
  ....
  ....

I have tested successfully with RTC 4.0.4 on Tomcat

Hope it helps,

      Chemi.

0 votes


Permanent link
Hi, I found this very useful, just a few comments, in case of Team Concert, the examples recommend do not creat the Activator class cause these plugins are not pure osgi, in that case we can get the bundle like this 

try {
      BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
      ServiceReference jndiServiceReference = bundleContext.getServiceReference(IJNDIService.class.getName());
      IJNDIService jndiService = (IJNDIService) bundleContext.getService(jndiServiceReference);
      Context initialContext = jndiService.getInitialContext();
      DataSource datasource = (DataSource) initialContext.lookup("java:comp/env/jdbc/YourDB");
      Connection con = datasource.getConnection();
     ...

or if you set the prerequisites in your Team Concert service then you just need to do that inside the component

try {
     IJNDIService jndiService = (IJNDIService) getService(IJNDIService.class);
     Context initialContext = jndiService.getInitialContext();
     DataSource datasource = (DataSource) initialContext.lookup("java:comp/env/jdbc/YourDB");
     Connection con = datasource.getConnection();
     ...

also in the plugin.xml

        <prerequisites>         
            <requiredService interface="com.ibm.team.repository.jndi.IJNDIService"/>
        ...
              more prerequisites
        ...
       </prerequisites>

Hope this help
Amaury

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937
× 38

Question asked: Jul 11 '13, 6:34 a.m.

Question was seen: 5,488 times

Last updated: Feb 23 '14, 8:55 a.m.

Confirmation Cancel Confirm