3 Replies Latest reply on Oct 27, 2008 12:21 PM by vickyk

    Problem looking up XADatasource - Always returns Datasource

      This involves using JBOSS 4.2.3 GA, Spring 2.5 and SQLServer 2000 XA jdbc driver.

      I created a file pxdatasource-xa-ds.xml file in the deploy folder with the following definition-

      <xa-datasource>
      <jndi-name>pxDS</jndi-name>
      <track-connection-by-tx>True</track-connection-by-tx>
      <connection-url>jdbc:microsoft:sqlserver://SQLTEST1;SelectMethod=cursor;databasename=App_Dev</connection-url>
      <xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
      <min-pool-size>1</min-pool-size>
      <max-pool-size>20</max-pool-size>
      <new-connection-sql>select 1 from systypes</new-connection-sql>
      <check-valid-connection-sql>select 1 from systypes</check-valid-connection-sql>
      </xa-datasource>

      JBOSS is using org.jboss.resource.adapter.jdbc.WrapperDataSource class for this look up. If the object is assigned to object of type Datasource, there is no problem. But if it is assigned to the type XADatasource there is an exception.

      So even though I am defining a datasource that supports XA i.e. implements XADatasource the object that is returned to me somehow is of the type Datasource.

      How do I tell JBOSS that I need the looked up object to be XADatasource?

      Thanks.

        • 1. Re: Problem looking up XADatasource - Always returns Datasou
          vickyk

           

          "pradeeps" wrote:
          How do I tell JBOSS that I need the looked up object to be XADatasource?


          I am not sure what exactly you want to do with the XADataSource, you should not be trying to get the XADataSource this way.
          If you need to XADataSource you can construct it as
          OracleXADataSource xads = new OracleXADataSource();


          • 2. Re: Problem looking up XADatasource - Always returns Datasou

            Thanks for the reply.

            The connection that is gotten from this datasource is going to participate in a distributed transaction with JMS XA QueueConnectionFactory. I am using the Atomikos JTA API.

            This distributed TX will happen only if both the resources support XA.

            Are you recommending that I create the XADataSource object in my code and not look up using JNDI?

            Thanks.

            • 3. Re: Problem looking up XADatasource - Always returns Datasou
              vickyk

               

              "pradeeps" wrote:

              The connection that is gotten from this datasource is going to participate in a distributed transaction with JMS XA QueueConnectionFactory. I am using the Atomikos JTA API.

              This distributed TX will happen only if both the resources support XA.

              Are you recommending that I create the XADataSource object in my code and not look up using JNDI?

              Thanks.

              I assume that you must have Atomikos TM configured with the JBoss.Now when you are getting the connection from the xa-datasource the jca framework will transparently enlist the connection associated with the datasource in the ongoing transaction.
              Here is the psuedo code :

              UserTransaction utx = (UserTransaction) ctx.lookup("UserTransaction");
              
              Getting JMS XA QueueConnectionFactory from JNDI
              
              Getting JMS session which will also enlist the corresponding XAResource in the ongoing TX
              
              DataSource ds = (DataSource) ctx.lookup("java:/pxDS");
              Connection con = ds.getConnection(); // Here JCA will enlist the connection(precisely XAResource) in ongoing JTA transaction transparently.
              utx.commit();