Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: Which is the Context of the JNDI Custom DataSource (BI Server)

  1. #1
    Join Date
    Dec 2011
    Posts
    3

    Default Which is the Context of the JNDI Custom DataSource (BI Server)

    Hi,

    I have created a DataSource in the Pentaho Administration Console (PAC),which creates a jndi interface, and I have tested that it runs with the BI Server.
    I would like to create a custom Java class that invokes the exposed JNDI.
    The problem is that I have to specify the same Context in my Java class that was declared in the DataSource.

    Does anyone knows how to find out that Context?

    Thanks!

  2. #2
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    The BI-Server does not use JNDI for its datasources. In today's application server's JNDI is usually a ill-implemented thing that - in the worst case - requires you to redeploy the whole web-application when you make changes to the configuration.

    To access the BI-Server's data-sources, use this code:

    Code:
          final IDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDatasourceService.class, null);
          final DataSource dataSource = datasourceService.getDataSource(jndiName);
    With that you get a javax.sql.DataSource as you would from JNDI, but using the pentaho datasource implementation instead.
    Get the latest news and tips and tricks for Pentaho Reporting at the Pentaho Reporting Blog.

  3. #3
    Join Date
    Dec 2011
    Posts
    3

    Default

    First of all, thanks for the reply.

    What I'm trying to do is the following:

    1. I launch from the BI Server a xaction.
    2. This xaction calls a job.
    3. This job has a transformation with a Javascript Step.
    4. In the Javascript Step I call a custom Java class, that I have packed into a jar previously.

    Well, the aim is to be able to access the database set from the Administration Console (PAC) using my Java class.
    In a first attempt I have tryed to access the database using Hibernate, but it throwed an exception because the server wasn't able to find the hibernate.cfg.xml with the mappings.

    So now I'm trying to avoid to use the hibernate.cfg.xml, that's why I've tryed the jndi connection.

    Following your instructions, I've typed:

    import javax.sql.DataSource;
    import org.pentaho.platform.api.data.IDatasourceService;
    import org.pentaho.platform.engine.core.system.PentahoSystem;

    ...

    final IDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDatasourceService.class, null);
    final DataSource dataSource = datasourceService.getDataSource("miDataBase");
    Connection conn = dataSource.getConnection();
    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery("select id, id_ecg, user_subjectid, hr, hf, lf , act, id_dsdm from rawdataecghractivity_sleep");

    ...


    But I've get a NullPointerException in this line:
    final IDatasourceService datasourceService = PentahoSystem.getObjectFactory().get(IDatasourceService.class, null);

    What do you suggest me in order to reach my goal?
    (It would be great If I could use Hibernate)

    Thanks!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.