5 Replies Latest reply on Jun 20, 2017 12:18 PM by Ramesh Reddy

    Getting exception querying using EmbeddedConnection

    Pranav K Novice

      Hi,

       

      While connecting to my application (running on a jetty server), I am able to properly connect and and run queries over Teiid when I use the SocketConnection (using URL format: jdbc:teiid:Portfolio@mm://localhost:31000). But when I try to create an EmbeddedConnection instead (using the jdbc:teiid:Portfolio) inside the same JVM, I am not able to create a connection in my setup. The driver.connect() call fails giving me 2 kinds of exceptions.

       

      The first error I get here is:

      jvm 1    | Caused by: javax.xml.stream.FactoryConfigurationError: Provider com.ctc.wstx.stax.WstxEventFactory not found

      jvm 1    |      at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:201)

      jvm 1    |      at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:152)

      jvm 1    |      at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:265)

      jvm 1    |      at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:227)

      jvm 1    |      at javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:64)

      jvm 1    |      at __redirected.__XMLEventFactory.<clinit>(__XMLEventFactory.java:72)

      jvm 1    |      at __redirected.__JAXPRedirected.initAll(__JAXPRedirected.java:76)

      jvm 1    |      at org.jboss.modules.Module$1.run(Module.java:132)

      jvm 1    |      at org.jboss.modules.Module$1.run(Module.java:119)

      jvm 1    |      at java.security.AccessController.doPrivileged(Native Method)

      jvm 1    |      at org.jboss.modules.Module.<clinit>(Module.java:119)

      jvm 1    |      at org.teiid.jdbc.ModuleHelper.createFromModule(ModuleHelper.java:47)

      jvm 1    |      at org.teiid.jdbc.LocalProfile.createServerConnection(LocalProfile.java:60)

      jvm 1    |      at org.teiid.jdbc.LocalProfile.connect(LocalProfile.java:50)

      jvm 1    |      at org.teiid.jdbc.TeiidDriver.connect(TeiidDriver.java:105)

      jvm 1    |      at org.teiid.jdbc.TeiidDriver.connect(TeiidDriver.java:55)

      jvm 1    |      at java.sql.DriverManager.getConnection(DriverManager.java:664)

      jvm 1    |      at java.sql.DriverManager.getConnection(DriverManager.java:208)

       

      The above exception shows up only for the first time, while subsequent attempts to query give me the following error:

      jvm 1    | Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.jboss.modules.Module

      jvm 1    |      at org.teiid.jdbc.ModuleHelper.createFromModule(ModuleHelper.java:47)

      jvm 1    |      at org.teiid.jdbc.LocalProfile.createServerConnection(LocalProfile.java:60)

      jvm 1    |      at org.teiid.jdbc.LocalProfile.connect(LocalProfile.java:50)

      jvm 1    |      at org.teiid.jdbc.TeiidDriver.connect(TeiidDriver.java:105)

      jvm 1    |      at org.teiid.jdbc.TeiidDriver.connect(TeiidDriver.java:55)

      jvm 1    |      at java.sql.DriverManager.getConnection(DriverManager.java:664)

      jvm 1    |      at java.sql.DriverManager.getConnection(DriverManager.java:208)

       

      While debugging I noticed at the point where the exception comes up, that the current classloader has both the Modules, WstxEventFactory classes available.

      Could you please suggest on why this issue would be coming up/ is this an issue in general?

       

      Thanks,

      Pranav

        • 1. Re: Getting exception querying using EmbeddedConnection
          Ramesh Reddy Master

          You need to get connected as "EmbeddedServer.getDriver().connect(...)"

          • 2. Re: Getting exception querying using EmbeddedConnection
            Pranav K Novice

            Hey Ramesh, thanks for the response.

            I have used "EmbeddedServer.getDriver().connect(...)" before and seen that work fine for creation of an Embedded connection.

             

            But from the looks of the code in the Teiid JDBC driver, it seemed to me that it's based on the URL that Teiid would either create a LocalProfile object (a new one using the standard JDBC construct or pass the object created during Embedded server startup when using embeddedServer.getDriver().connect())

             

            In my current use case I want to create an Embedded conn using the JDBC driver from a standard code like the one below.

            Is there no way to create a local/embedded (non-socket) connection while connecting through the JDBC driver using the standard JDBC API construct ?

             

            Class.forName("org.teiid.jdbc.TeiidDriver").newInstance();

            Connection connection = DriverManager.getConnection("jdbc:teiid:testVDB", info);

            Statement statement = connection.createStatement();

            ResultSet resultSet = statement.executeQuery(sql);

             

            Thanks,

            Pranav

            • 3. Re: Getting exception querying using EmbeddedConnection
              Ramesh Reddy Master

              The issue is getting access to the EmbeddedServer in the VM, since embedded does not use any kind of injection frameworks like Guice, or Spring one must provide access to it. In the WidFly environment, we use JNDI services to get to the EmbeddedServer instance.

               

              So, to make it work in your environment, you can devise a way to provide EmbeddedServer, and provide that with TeiidDriver.setProfile(...) method. See I did the exact same thing here. [1]

               

              [1] teiid-spring-boot/TeiidSpringDriver.java at master · rareddy/teiid-spring-boot · GitHub

              • 4. Re: Getting exception querying using EmbeddedConnection
                Pranav K Novice

                Thanks for that clarification Ramesh. I'll see how I can wire such a setup to pass on EmbeddedServer instance at the right place.

                 

                One more question, since I am down the embedded path, is there a difference in the further code flow between when we go via Socket vs embedded connection? (specially on how multi-threading comes into the picture while processing queries and returning results).

                Do you see any obvious reasons due which I might see noticeable performance gains/reduction while running queries? (apart from the transport layer considerations)

                • 5. Re: Getting exception querying using EmbeddedConnection
                  Ramesh Reddy Master

                  No, once you get the JDBC connection access is same. However in embedded case there are special cases where you can use the calling thread to use do more processing than just waiting around. Also, there are ways to pass the security around from existing context.