6 Replies Latest reply on Oct 31, 2012 8:30 AM by wdfink

    how creat a datasource per server instance?

    liuliu

      hi,

       

      I am migrating our application from jboss 4 to jboss 7. we have one same ear for every client, just the datasource is different.

       

      and now on jboss 7.1.1 I create one server instance per client in domain mode. my problem is the datasource is declared in the profile, so i must give a différent jndi name for every client

       

      and the application can not more be the same because of the data connection's lookup.

       

      Is there a way to creat one data source per server instance?

       

      thanks in advance

       

      liumin

        • 1. Re: how creat a datasource per server instance?
          wdfink

          You might use expressions for that, replace connect string and user/passwd by "${database.xyz}" and set it as system property for each server.

          This should work, I'm not sure but there was an issue that not every attribute can use it so you might build based on tag 7.1.3.

          • 2. Re: how creat a datasource per server instance?
            liuliu

            thanks for your reply,

             

            Do you mean  i do something like:

             

            String dbJndi = System.getProperty('dbJndiStr");

            Connection conn = initContext.lookup(dbJndi);

             

            does this solution work for resource injection too?

            • 3. Re: how creat a datasource per server instance?
              wdfink

              No, I meant something in the configuration (domain.xml):

               

              <subsystem xmlns="urn:jboss:domain:datasources:1.1">

                <datasources>

                  <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">

                    <connection-url>${datasource.url}</connection-url>

                    .....

               

               

              (host.xml):

              <server name="one"! ...>

                <system-properties>

                  <property name="datasource.url" value="mydatasourceURL"/>

                   .....

              • 4. Re: how creat a datasource per server instance?
                liuliu

                Interesting. I did not know it could work like that. in this case, the jndi for data source is the same, but it link to the different database per server instance. do jboss creat a connection pool for every server instance?

                • 5. Re: how creat a datasource per server instance?
                  nickarls

                  No, that won't be necessary. Since the application references the pool by JNDI it will just point to a different location do to the datasource url.

                  • 6. Re: how creat a datasource per server instance?
                    wdfink

                    Each server instance create its own a pool for the database connections.

                    i.e. if you have a DS with min-pool-size=10 and 3 server instances each instance will create 10 connections to the database url which is configured via the expression and the server properties.