0 Replies Latest reply on Sep 12, 2012 10:03 AM by Jean-Yves Terrien

    How to dynamically configure the datasource name in camel-jpa  on fuseesb?

    Jean-Yves Terrien Newbie

      hi,

       

      I have a problem with jpa on servicemix

       

      when my bundle starts, I created a route builder.

      In the constructor of the class, I ask a database to know the route definition to create.

       

      it is only at this point that I know the name of the datasource to use (already declared in osgi).

      I have to define jpa consumer who will use this base.

       

       

      But in the documentation and examples, the percistence JPA is defined in an XML file on bundle META-INF.

       

      I do'nt know how to tell jpa to use the datasource name that I have only on creation of the route builder.

       

      Can I leave the persistence.xml file in the bundle and change the name of the datasource in the road builder?

      or should I create a persistenceUnit on the road builder?

       

      and in both cases, how?

       

      I have it in my persistence.xml file:

      <jta-data-source>osgi:services/javax.sql.DataSource/(name=aDataSource)</jta-data-source>

       

      but I do not know what name is given to the datasource when starting the bundle

       

      A+JYT

       

      public class MyRouteBuilder extends RouteBuilder {

       

         private String final MY_MODULE_NAME="logistique.livraison";

          

         protected ModuleConfig moduleConfig = null;

       

         public MyRouteBuilder() {

            super();

             

            //GetConfiguration from extenal config servivce

            moduleConfig = ConfigHelpper.getConfig(MY_BUNDLE_NAME);

             

            logger.log(moduleConfig.getInDatasource());

         }

       

       

        public void configureRoute() throws ExceptionOlympe {

          //how to use the value of moduleConfig.getInDatasource() in

          // jpa://my.domain.model.Livraison?consumer.delay=2000

          from("jpa://my.domain.model.Livraison?consumer.delay=2000")

          .bean(...)

          ...

          ;

        }

       

      Edited by: sekaijin on Sep 12, 2012 4:01 PM