11 Replies Latest reply on Nov 29, 2012 4:57 PM by shawkins

    Using a custom data source in a dynamic VDB

    ileitch

      When deploying Teiid dynamic VDB in jBoss, it seems that jBoss uses the default “org.jboss.jca.adapters.jdbc.WrapperDataSource” in getConnection(WrapperDataSource) in the execution factory.

      Is there a way to specify my own data source class for jBoss to use in the Teiid configuration XML file? (ie., getConnection(MyDataSource)?

      Thanks

        • 1. Re: Using a custom data source in a dynamic VDB
          rareddy

          Those are implementation semantics of JCA in the JBoss AS for providing various services. As long as your abstraction is at DataSource (for jdbc sources) it should be fine. If your goal is to typecast the connection to different class to use some vendor specific call then you need to do

           

           

          Connection connection = datasource.getConnection();
          if (connection instanceof WrappedConnection) {
              try {
                  OriginalConnection unwrapped = ((WrappedConnection)connection).unwrap();
              } catch (ResourceException e) {
             
              }    
          }
          

           

           

          Ramesh..

          • 2. Re: Using a custom data source in a dynamic VDB
            ileitch

            Thanks Ramesh.

             

            I have a custom data source class called "MyDataSource" extends from DataSource.

             

            When deploying the VDB dynamically, I do not know how to specify 'MyDataSource' class in the 'standalone-teiid.xml' for Teiid framwork to use it instead of the jBoss default "WrapperDataSource". I saw the 'resource-adapter' section in the teiid.xml but I am not clear about the format to specify the custom datasource class.

             

             

             

             

             

             

             

             

             

            • 3. Re: Using a custom data source in a dynamic VDB
              rareddy

              When deploying the VDB dynamically, I do not know how to specify 'MyDataSource' class in the 'standalone-teiid.xml' for Teiid framwork to use it instead of the jBoss default "WrapperDataSource". I saw the 'resource-adapter' section in the teiid.xml but I am not clear about the format to specify the custom datasource class.

              Just follow the same procedure to create a data source as any other database like Oracle if this is JDBC source. If you have built the RAR file for it, then follow the same procedure as others to create a "resource-adaptor" configuration.

              • 4. Re: Using a custom data source in a dynamic VDB
                ileitch

                Thanks Ramesh.

                 

                I just hope that I do not have to go with the "RAR" file method since I only wants to override the DataSource part.

                 

                I guess that I have to follow the procedure to create custom resource adapter as indicated below

                 

                      Define Managed Connection Factory

                      Define the Connection Factory class

                      Define the Connection class

                     Define the configuration properties in a "ra.xml" file

                 

                 

                Thanks

                • 5. Re: Using a custom data source in a dynamic VDB
                  rareddy

                  Leitch,

                   

                  Frankly I am not sure what the usecase is, and not sure what you are trying to do. What you listed above is the process of defining a RAR, which contradicts what you said above. If you are trying to use the already built data source or RAR, you just need to define the configuration to create the data source and then do what I mentioned in the first post about unwrapping in your ExecutionFactory class. If not, some explanation of your usecase as to what you are trying accomplish may help.

                   

                  Ramesh..

                  • 6. Re: Using a custom data source in a dynamic VDB
                    shawkins

                    Let me see if I understand what you are saying.  You have a custom java.sql.DataSource correct?  In that case you do not need full war deployment, the class/jar should be usable as a standard JDBC source.  The jar containing the DataSource class will need deployed just as any JDBC driver and configured similarly.

                     

                    However the WrappedDataSource is required by AS to perform pooling.  Also the WrapperDataSource does not return the underlying DataSource via the unwrap call.  So if you need to reference to your actual DataSource for whatever reason, you would do so off of your Connection object.

                     

                    Steve

                    • 7. Re: Using a custom data source in a dynamic VDB
                      ileitch

                      Thanks Steve.

                       

                      I implemented my custom data source extends from DataSource and use it in the EMBEDDED TEIID environment as following:

                      class MyCustomDataSource extends DataSource {

                       

                       

                       

                              @Override

                       

                              public Connection getConnection() throws

                              SQLException {

                            }

                       

                       

                       

                       

                       

                      EmbeddedServer.ConnectionFactoryProvider<DataSource> edmProvider = new EmbeddedServer.ConnectionFactoryProvider<DataSource>() {

                       

                       

                           @Override

                       

                       

                           public DataSource getConnectionFactory() throws

                           TranslatorException {

                       

                       

                              return _myCustomdataSource ;

                             }

                      };

                       

                       

                      Now, I want to do the same thing in the dynamic TEIID VDB environment.

                       

                      When I deploy the VDB in JBoss AS, in the "getConnection()" method in my translator, it seems that Teiid uses the default WrapperDataSource to get metadata. I want Teiid to use "myCustomDataSource.getConnection()" instead and I do not know how to specify in the "standalone-teiid.xml" for Teiid to use myCustomDataSource.

                       

                      The documentation seems to say that I have to go through the steps below to define a custom resource adapter. (i.e., my custom data source). I am wondering if there is an easy way to specify my custom data source.

                       

                                Define Managed Connection Factory

                                Define the Connection Factory class

                                Define the Connection class

                                Define the configuration properties in a "ra.xml" file

                       

                      Thanks

                      Ian

                      • 8. Re: Using a custom data source in a dynamic VDB
                        rareddy

                        I do not think you need to create resource-adaptor. You need to package your MyCustomDataSource in jar with right service initialization files like a JDBC driver.  Then deploy that file in JBoss AS as JDBC driver and define the configuration in standalone-teiid.xml as you do for any other JDBC data source and use the resulting data source's JNDI name in your Dynamic VDB.


                        Ramesh..

                        • 9. Re: Using a custom data source in a dynamic VDB
                          shawkins

                          > When I deploy the VDB in JBoss AS, in the "getConnection()" method in my translator, it seems that Teiid uses the default WrapperDataSource to get metadata.

                           

                          WrapperDataSource is just a wrapper around the JBoss JCA connection pooling facility.  It will indirectly call your MyCustomDataSource getConnection, when getConnection is called.  In turn a wrapped Connection that is tracked for pooling will be returned.  You can if needed get at your Connection instance by using the unwrap method on the pooled connection.

                           

                          To a consuming application, such as Teiid, it shouldn't make a difference whether the Connection is obtained off of MyCustomDataSource directly or via the WrapperDataSource.

                           

                          So if you have MyCustomDataSource configured in AS as a standard JDBC source and are obtaining connections from it, why and where do you need a refernce to MyCustomerDataSource?

                          • 10. Re: Using a custom data source in a dynamic VDB
                            ileitch

                            Thanks Steve.

                             

                            Okay. So, I must do something wrong because it never calls MyDataSource.getConnection() method when deploying my VDB in jBoss AS.

                             

                            This is how I defined for my data source:

                             

                                  "standalone-teidd.xml"

                             

                                            <datasource jndi-name="java:/mydata-ds" pool-name="mydata-ds" enabled="true" use-java-context="true">
                                                <connection-url>jdbc:oracle:thin:user1/password1@//localhost:1521/MYDATA</connection-url>
                                                <driver>oracle</driver>
                                                <security>
                                                    <user-name>user1</user-name>
                                                    <password>password1</password>
                                                </security>
                                            </datasource>

                                        <translator name="MyTranslator" module="org.jboss.teiid.translator.MyTranslator"/>

                             

                                   "myvdb.xml"


                                    <source name="mydata" translator-name="MyTranslator" connection-jndi-name="java:/mydata-ds"/>

                             

                            Ian

                            • 11. Re: Using a custom data source in a dynamic VDB
                              shawkins

                              Following https://docs.jboss.org/author/display/AS71/Admin+Guide#AdminGuide-DataSources - you'll need to define or alter a driver definition with the xa-datasource-class:

                               

                              <driver name="my-driver" module="my-module">

                              <xa-datasource-class>...MyCustomDataSource</xa-datasource-class>

                              </driver>

                               

                              Where my-module should contain your custom class. Then you'll create the source using the xa-datasource tag:

                               

                              <xa-datasource jndi-name="java:jboss/mydata-ds" pool-name="mydata-ds">

                              <driver>my-driver</driver>

                              <xa-datasource-property name="...">...</xa-datasource-property>

                              <xa-datasource-property name="...">...</xa-datasource-property>

                                ...

                              </xa-datasource>

                               

                              It's unclear to me however whether this xa configuration also supports just a java.sql.DataSource, rather than an XADataSource.  The worst case scenario would be that you would have to also supply a Driver based connection mechanism to use the non-XA JBoss configuration.

                               

                              Steve