5 Replies Latest reply on Nov 14, 2011 10:52 AM by rareddy

    How can i set the connection programatically for source model in a VDB?

    fihtisham

      Hello,

       

      I have scenario in which I want to set the "data source/connection profile" programatically. Consider the following example.

       

      1- Create a source model using sql server connection say ''SQLSourceA"

      2- Create a view model using above source model

      3- Create a virtual db say "Sample.vdb" that includes above models

      4- Deploy the vdb which will result in creation of "Sample.vdb", SQLSourceA-ds.xml files in the jboss AS deploy folder.

      5- Create a copy of SQLSourceA-ds.xml as SQLSourceA-ds(2).xml. In SQLSourceA-ds(2).xml change jndi name and connection information to point to some other sql server instance.

       

      Now when I will query this deployed vdb for SQLSourceA model, the connection information stored in SQLSourceA-ds.xml will be used by vdb. I have scenario where in my java client, I want vdb to use SQLSourceA-ds(2).xml instead of SQLSourceA-ds(2).xml

       

      Is it possible to change the "data source/connection profile" of the source model packaged in vdb programatically to use the SQLSourceA-ds(2).xml?

       

      Thanks,

      Farrukh

        • 1. Re: How can i set the connection programatically for source model in a VDB?
          rareddy

          Farrukh,

           

          Yes, you can change it couple different ways. However, first I want to tell you the recommended way. The recommended way is that you keep the data source's JNDI name constant when VDB is being migrated/promoted between environments like development/testing/production, that way there is no change to the VDB itself, but you are deploying the VDB with different -ds.xml in different environments with same JNDI name.

           

          However, if you like to change  the JNDI name for a source in the VDB, then first create -ds.xml with different JNDI name, then you can use

           

          1) admin-console web administration application (http://localhost:8080/admin-console), go to "Data Services" tab and select your VDB and on VDB panel, you have option to change the "connection-jndi-name" on the model. Check Admin Guide admin-console chapter.

           

          2) You can use Admin API and call "assignToModel" method to programmatically change it using Java program. Check the Admin Guide

           

          3) You can use Admin Shell and use "assignToModel" method to change it using scripting in Groovy shell. Check the Admin Guide's admin-shell chapter.

           

          HTH.

           

          Ramesh..

          • 2. Re: How can i set the connection programatically for source model in a VDB?
            fihtisham

            Thanks Ramesh for the prompt reply.

             

            I followed your suggestion and tried to change the connection programatically using the admin api in the following way;

             

            AdminFactory adminFactory = AdminFactory.getInstance();

            Admin admin = adminFactory.createAdmin("admin", "admin".toCharArray(), "mms://localhost:31443");

            admin.assignToModel("Sample", 1, "SQLSourceA", "SQLSourceA", "sqlserver", "SQLSourceA_2");

            Code worked without any error but the data source for the model is not changing. I tested it by doing a jdbc query before and after the call to assignToModel.

            Is there something that I missed?

            Thanks,

            Farrukh

             

             

            • 3. Re: How can i set the connection programatically for source model in a VDB?
              rareddy

              Farrukh,

               

              That looks correct. You can even check with code

               

              VDB vdb = admin.getVDB("sample", 1);
              Model m = vdb.getModel("SQLSourceA");
              String jndiName = m.getSourceConnectionJndiName("SQLSourceA");
              

               

              You can also verify with "admin-console" as I mentioned. If you see the right names but still not seeing the results, then we need to look further. Also what version you are working with?

               

              Ramesh..

              • 4. Re: How can i set the connection programatically for source model in a VDB?
                fihtisham

                Thanks Ramesh!

                 

                The code you suggested returns the updated information but querying still shows that the connection is not updated. I am using teiid 7.5.

                 

                Thanks,

                Farrukh

                • 5. Re: How can i set the connection programatically for source model in a VDB?
                  rareddy

                  Farrukh,

                   

                  Looks like bug due to regression. Can you log a JIRA https://issues.jboss.org/browse/TEIID ?

                   

                  To workaround, if you re-start the server after the name change it will work as expected.

                   

                  Ramesh..