1 Reply Latest reply on Feb 12, 2010 2:12 PM by Thomas Nordmeyer

    Sem & Mondrian: Passing DB Connection

    Thomas Nordmeyer Newbie

      I want to use Mondrian (OLAP) in Seam context. As seam knows the DB connection, I want to pass this to Mondrian to perform it's MDX queries on.


      Mondrian accepts javax.sql.Datasource or a String containing the connection info as parameter.


      Does anybody know how to get the connection info in proper type from within a Seam action?


      Mi first thought was, to extract it somehow from the EntityManager, but I couldn't find any way. Now I am about to fail creating a DataSource component in the components.xml


      Any hints?

        • 1. Re: Sem & Mondrian: Passing DB Connection
          Thomas Nordmeyer Newbie

          Thats how I solved it. Unfortiunately, my code must know the JNDI name of my datasource.


                 
                  // get Datasource from JNDI
                  InitialContext ctx = new InitialContext();
                  DataSource dataSource =  (DataSource)ctx.lookup("java:/renaDatasource");
          
                  // assemble mondrian parameters
                  Util.PropertyList props = new Util.PropertyList();
                  props.put ( "Provider", "mondrian" );
                  props.put ( "Catalog", "my-mondrian-schema.xml");
                  
                  CatalogLocator locator = null; // use default catalog locator
                  Connection connection = DriverManager.getConnection(props, locator, dataSource); 
                  Query query = connection.parseQuery(mdxQuery); 
                  Result result = connection.execute(query);