BTM
  1. BTM
  2. BTM-83

Add setDataSource() method to PoolingDataSource/ResourceBean

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.3
    • Fix Version/s: 3.0.0
    • Labels:
      None
    • Number of attachments :
      4

      Description

      The current approach to configuring the wrapped datasource is by specifying its:

      • classname as a String via the 'className' property
      • configuration properties as a Properties via the 'driverProperties' property

      Please add a second approach to configuring the wrapped datasource by setting a property with a datasource instance.
      This approach enables configuration flexibility of defining database datasources separately from BTM and setting them on the BTM wrapper datasources, particularly useful with Spring bean configuration. We can then keep JTA manager configuration separate from database datasource configuration, making our configuration easier for different databases in different environments (e.g. the BTM PoolingDataSource beans refer to datasource names such as "dbDataSource" and we control which Spring application context files containing the dbDataSources with those expected names are loaded and therefore injected to the BTM datasource).

      We can partially get there by using a property for the 'className' value, but can't configure the 'driverProperties' as easily because different datasources have different property names. So we end up separating the property config from the datasource config and must ensure the 'className' and 'driverProperties' pair of properties always match, vs configuring the datasource bean in one spot (class and properties together) and setting the datasource.

      1. JdbcPooledConnection.java
        19 kB
        Jaco de Groot
      2. JmsPooledConnection.java
        11 kB
        Jaco de Groot
      3. ResourceBean.java
        13 kB
        Jaco de Groot
      4. XAPool.java
        24 kB
        Jaco de Groot

        Issue Links

          Activity

          Hide
          Ludovic Orban added a comment -

          This is a well-known limitation, mostly because of historical reasons.

          It can be removed but it's not as trivial as just adding a pair of getter / setter. Let's target it for 2.1.

          Show
          Ludovic Orban added a comment - This is a well-known limitation, mostly because of historical reasons. It can be removed but it's not as trivial as just adding a pair of getter / setter. Let's target it for 2.1.
          Hide
          Stéphane Nicoll added a comment -

          Hey, I second that request. This applies to the connection factory as well where you redefine how the connection factory gets created instead of injecting it

          Show
          Stéphane Nicoll added a comment - Hey, I second that request. This applies to the connection factory as well where you redefine how the connection factory gets created instead of injecting it
          Hide
          Jaco de Groot added a comment -

          A while ago I've send a message/patches to the mailinglist. Ludovic asked me to add them to this issue. Here's my message (I will add the java files from my email too):

          I made some little changes to make it possible to set a bean on the PoolingDataSource and PoolingConnectionFactory in my Spring configuration instead of using driverProperties, see attached changed java files, based on btm-dist-2.1.3.zip. For creating an ActiveMQXAConnectionFactory bean in Spring and adding it to the PoolingConnectionFactory you can now use the following Spring configuration:

          <bean
          name="activeMQConnectionFactory"
          class="org.apache.activemq.ActiveMQXAConnectionFactory"
          scope="singleton"
          destroy-method="stop"
          >
          <property name="brokerURL" value="vm://localhost"/>
          </bean>

          <bean
          name="defaultConnectionFactory"
          class="bitronix.tm.resource.jms.PoolingConnectionFactory"
          init-method="init"
          destroy-method="close"
          >
          <property name="uniqueName" value="$

          {instance.name.lc}.defaultConnectionFactory"/>
          <property name="maxPoolSize" value="100" />
          <property name="allowLocalTransactions" value="true"/>
          <property name="resource">
          <ref bean="activeMQConnectionFactory"/>
          </property>
          </bean>

          And/or using Spring to get a DataSource from JNDI and adding it to the PoolingDataSource bean:

          <bean
          name="jndiDataSource"
          class="org.springframework.jndi.JndiObjectFactoryBean"
          >
          <property name="jndiName" value="${jndiContextPrefix}jdbc/${instance.name.lc}

          "/>
          </bean>

          <bean
          name="defaultDataSource"
          class="bitronix.tm.resource.jdbc.PoolingDataSource"
          init-method="init"
          destroy-method="close"
          >
          <property name="uniqueName" value="$

          {instance.name.lc}

          .defaultDataSource"/>
          <property name="maxPoolSize" value="20"/>
          <property name="resource">
          <ref bean="jndiDataSource"/>
          </property>
          </bean>

          Show
          Jaco de Groot added a comment - A while ago I've send a message/patches to the mailinglist. Ludovic asked me to add them to this issue. Here's my message (I will add the java files from my email too): I made some little changes to make it possible to set a bean on the PoolingDataSource and PoolingConnectionFactory in my Spring configuration instead of using driverProperties, see attached changed java files, based on btm-dist-2.1.3.zip. For creating an ActiveMQXAConnectionFactory bean in Spring and adding it to the PoolingConnectionFactory you can now use the following Spring configuration: <bean name="activeMQConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory" scope="singleton" destroy-method="stop" > <property name="brokerURL" value="vm://localhost"/> </bean> <bean name="defaultConnectionFactory" class="bitronix.tm.resource.jms.PoolingConnectionFactory" init-method="init" destroy-method="close" > <property name="uniqueName" value="$ {instance.name.lc}.defaultConnectionFactory"/> <property name="maxPoolSize" value="100" /> <property name="allowLocalTransactions" value="true"/> <property name="resource"> <ref bean="activeMQConnectionFactory"/> </property> </bean> And/or using Spring to get a DataSource from JNDI and adding it to the PoolingDataSource bean: <bean name="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean" > <property name="jndiName" value="${jndiContextPrefix}jdbc/${instance.name.lc} "/> </bean> <bean name="defaultDataSource" class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init" destroy-method="close" > <property name="uniqueName" value="$ {instance.name.lc} .defaultDataSource"/> <property name="maxPoolSize" value="20"/> <property name="resource"> <ref bean="jndiDataSource"/> </property> </bean>

            People

            • Assignee:
              Ludovic Orban
              Reporter:
              Jeff Jensen
            • Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: