14 Replies Latest reply on Nov 21, 2008 9:12 PM by alwu-Oracle

    Use oracle.spatial.rdf.client.jena.Oracle with Datasource

    630782
      Hi,

      From the Javadoc it looks that oracle.spatial.rdf.client.jena.Oracle support Datasource only takes connection URL, user, and password as parameters. Does it support Datasource to make use of the connection pool if running inside the application server? Thanks,

      Weihua
        • 1. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
          alwu-Oracle
          Actually a new constructor of Oracle.java that accepts Connection object has already been implemented. It will be part of next release.
          • 2. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
            630782
            Any idea when the next release will be made available? Thanks,

            Weihua
            • 3. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
              alwu-Oracle
              Should be soon. We will post a message once a new version is put on OTN.
              • 4. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                637657
                Hi,

                In the Oracle Jena Adaptor 2 Javadoc API, I see there is an Oracle ctor: Oracle(OracleConnection connection), but no ctor for java.sql.Connection. I'm using Apache DBCP to get a data source. The Connection I get back from the data source is actually a pooled connection wrapper (org.apache.commons.dbcp.cpdsadapter.ConnectionImpl). The connection wraps the Oracle connection (in this case oracle.jdbc.driver.T4CConnection). Any suggestions?

                Thanks,
                Scott
                • 5. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                  671506
                  What application server are you using?
                  If you are using Tomcat, you should configure the datasource using the parameters:

                  accessToUnderlyingConnectionAllowed="true"
                  driverClassName="oracle.jdbc.OracleDriver" (is important, you must use this and not oracle.jdbc.driver.OracleDriver)

                  then in your code


                  org.apache.tomcat.dbcp.dbcp.DelegatingConnection delegatedConnection = (org.apache.tomcat.dbcp.dbcp.DelegatingConnection) conn;                         
                  OracleConnection connection=(OracleConnection) delegatedConnection.getInnermostDelegate();

                  hope it works
                  • 6. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                    alwu-Oracle
                    If the above suggestion works, then great. I don't have a Tomcat to try it out.

                    If not or you have some other concerns, then I can certainly try to use Connection class directly
                    in Jena Adaptor code.

                    Cheers,
                    Zhe Wu (Aka. Alan Wu)
                    • 7. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                      637657
                      Sorry for duplicate message. See next in thread. -Scott

                      Edited by: skagelsM3t4 on Nov 20, 2008 5:29 PM
                      • 8. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                        637657
                        Thanks for suggestion. Unfortunately, I'm not using Tomcat. Or more specifically, I cannot guarantee that the code will be running under Tomcat. There should be a way to do this with
                        Apache DBCP API only, right (I want to stay away from app server specific solutions)? But I can't figure it out. Unfortunately, I'm not an Apache DBCP guru either. Here is what I've tried but I can't get a org.apache.commons.dbcp.DelegatingConnection back. It is probably more appropriate to post this to the DBCP mailing list. I will try them as well but figured perhaps someone here might know.

                        Registering data source in JNDI:

                        String bindName = "myOracleDS";

                                       // ConstructOracle Connection Pool DataSource reference
                                       Reference ocpdsRef = new Reference(
                                                 "oracle.jdbc.pool.OracleConnectionPoolDataSource",
                                                 "oracle.jdbc.pool.OracleDataSourceFactory", null);
                                       ocpdsRef.add(new StringRefAddr("driver", "oracle.jdbc.OracleDriver"));
                                       ocpdsRef.add(new StringRefAddr("url", url));
                                       ocpdsRef.add(new StringRefAddr("user", user));
                                       ocpdsRef.add(new StringRefAddr("password", password));

                                       initialContext.rebind(bindName, ocpdsRef);               

                                       // Construct SharedPoolDataSource reference
                                       Reference ref = new Reference(
                                                 "org.apache.commons.dbcp.datasources.SharedPoolDataSource",
                                                 "org.apache.commons.dbcp.datasources.SharedPoolDataSourceFactory", null);
                                       ref.add(new StringRefAddr("dataSourceName", bindName));
                                       
                                       // Set remaining properties
                                       ref.add(new StringRefAddr("maxActive", maxIdle));
                                       ref.add(new StringRefAddr("maxIdle", maxIdle));
                                       ref.add(new StringRefAddr("maxWait", maxWait));
                                       ref.add(new StringRefAddr("testOnBorrow", testOnBorrow));
                                       ref.add(new StringRefAddr("validationQuery", validationQuery));
                                       ref.add(new StringRefAddr("testOnReturn", testOnReturn));

                                       initialContext.rebind("jdbc/myDS", ref);

                        Lookup/Retrieving data source:

                        InitialContext ic = new InitialContext();

                                       Object obj = ic.lookup(config.dataSourceName);
                                       SharedPoolDataSource ds = (SharedPoolDataSource) obj;
                        Connection conn = ds.getConnection();     

                        // conn is type oracle.jdbc.driver.LogicalConnection - doesn't look like I can get OracleConnection from this.
                                       // Can't cast conn to DelegatingConnection - missing link to do the following:
                        // DelegatingConnection delConn = (org.apache.dbcp.DelegatingConnection)conn;
                                       // OracleConnection oraConn = (OracleConnection) delConn.getInnermostDelegate();
                                       // return new Oracle(oraConn);

                        Thanks,
                        Scott
                        • 9. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                          alwu-Oracle
                          I am looking into this issue right now and will keep you posted. Behind the scene, the Jena Adaptor uses Oracle's JDBC batching and ClOB API.
                          It is a bit involved to change the logic ... We will see how it goes.
                          • 10. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                            alwu-Oracle
                            Please email alan dot wu at oracle dot com. I will need you to verify the new logic because I don't have similar setup on my machine.

                            Thanks,

                            Zhe Wu (Aka. Alan Wu)
                            • 11. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                              637657
                              Thanks Alan!

                              I should explain that my main goal is to use a pooled connection with the Jena Adaptor and I am having a hard time figuring out how to do so. I need an OracleConnection object that is really a pooled connection or Oracle should support a constructor Oracle(java.sql.Connection). Part of the challenge is also figuring out how to correctly create/configure the pooled DataSource object (data source that gets a pooled connection).

                              Thanks,
                              Scott
                              • 12. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                                alwu-Oracle
                                If you can get oracle.jdbc.driver.LogicalConnection consistently (or app server independently), then it seems that it is possible to get OracleConnection from it.

                                oracle.jdbc.driver.LogicalConnection extends
                                ... oracle.jdbc.driver.OracleConnection

                                oracle.jdbc.driver.OracleConnection extends
                                ... oracle.jdbc.OracleConnectionWrapper

                                oracle.jdbc.OracleConnectionWrapper implments
                                ... oracle.jdbc.OracleConnection

                                So that LogicalConnection object you get is of type oracle.jdbc.OracleConnection. You should not have problem
                                casting it.

                                The above is a fyi only. I understand that having a constructor that takes a java.sql.Connection is more universal.
                                • 13. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                                  637657
                                  Sorry, this was a class loader issue. I can cast the inner most connection delegate to oracle.jdbc.OracleConnection now.

                                  -Scott

                                  Edited by: skagelsM3t4 on Nov 21, 2008 2:37 PM
                                  • 14. Re: Use oracle.spatial.rdf.client.jena.Oracle with Datasource
                                    alwu-Oracle
                                    :) to know it is working out for you. Cheers.