2 Replies Latest reply on Dec 24, 2011 3:45 PM by jbrow

    How to dynamically add a global data source?

    jlanik

      Hi,

       

      I need to add a new data source dynamically when the server is running (so modifiyng xml is not a solution).

      This date source has to be accessible in multiple deployments.

       

      First I tried adding @DataSourceDefinition definition to a servlet in one of the applications:

      @DataSourceDefinition(

              name = "java:jboss/datasources/LoginDS",

              user = "sa",

              password = "sa",

              className = "org.h2.jdbcx.JdbcDataSource",

              url = "jdbc:h2:tcp://localhost/mem:test"

      )

       

      However, this works for that one application, but not for the others.

      Adding the same DataSourceDefinition to more applications leads to a deployment error.

       

      I thought of using a different name for the data source in different deployments, but that would mean

      that I have to have distinct servlet file for every deployment and that is not a good solution for me as I want

      too keep the number of files minimal.

       

      It should be probably possible to do this via drm api (<https://docs.jboss.org/author/display/AS71/Detyped+management+and+the+jboss-dmr+library>), but the addressing there is not clear to me.

      Could you please provide me with some example of adding data source using dmr or some other usefull advice.

       

      Thanks.