Kriss
Kriss

Reputation: 31

How to Configure P6Spy with OracleConnectionPoolDataSource in specific

We are using Oracle connection Pooling mechanism in our project as our application uses some oracle specific features.

The configuration of our datasource in jetty.xml is as follows:

<Call name="addService">
<Arg>
  <New class="org.mortbay.jetty.plus.DefaultDataSourceService">
    <Set name="Name">DataSourceService</Set>

    <Call name="addDataSource">
        <Arg>app_ds</Arg><!--java:comp/env-->
        <Arg>
         <New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
            <Set name="description">xxxx</Set>
            <Set name="user">xxx</Set>
            <Set name="password">xxxx</Set>
            <Set name="loginTimeout">xxx</Set>
            <Set name="URL">jdbc:oracle:thin:@localhost:1521:xxx</Set>
        </New>
      </Arg>
    </Call>
     <Call name="start"/>
 </New>

Now How do we integrate this datasource with P6Spy, so that P6Spy can print out all the SQL statements on to the console...?

I have previously used P6spy with other datasources like spring's DriverManagerDataSource, other datasources like as

(In Tomcat)

Resource name="jdbc/test" auth="Container"
      type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
      url="jdbc:oracle:thin:@xxx"
      username="xxx" password="xxx" maxActive="65" maxIdle="10"
      maxWait="-1" removeAbandoned="true"/>

..etc.

All these datasources take driverClassName as argument where we can provide the "com.p6spyengine.spy.P6SpyDriver" in the place of "oracle.jdbc.driver.OracleDriver" and provide the real driver name in spy.properties. The all worked fine.

But with oracle.jdbc.pool.OracleConnectionPoolDataSource, there is no such property called driverClassName to provide a proxy driver to.

In this case how can i integrate P6Spy with it?

Please help...

Thanks in Advance, Krishna V

Upvotes: 3

Views: 3583

Answers (2)

quintonm
quintonm

Reputation: 848

With Jetty, adding P6Spy is actually a little easier. P6Spy has a P6DataSource that accepts another data source via constructor parameter. This is by far the easiest way to setup P6Spy.

<Call name="addService">
<Arg>
  <New class="org.mortbay.jetty.plus.DefaultDataSourceService">
    <Set name="Name">DataSourceService</Set>

    <Call name="addDataSource">
        <Arg>app_ds</Arg><!--java:comp/env-->
        <Arg>
         <New class="com.p6spy.engine.spy.P6DataSource">
           <Arg>
              <New class="oracle.jdbc.pool.OracleConnectionPoolDataSource">
                 <Set name="description">xxxx</Set>
                 <Set name="user">xxx</Set>
                 <Set name="password">xxxx</Set>
                 <Set name="loginTimeout">xxx</Set>
                 <Set name="URL">jdbc:oracle:thin:@localhost:1521:xxx</Set>
              </New>
           </Arg>
         </New>
      </Arg>
    </Call>
     <Call name="start"/>
 </New>

Upvotes: 1

Peter Butkovic
Peter Butkovic

Reputation: 12189

From my experience with Glassfish, I would suggest to:

  • keep your existing oracle (real) datasource definition
  • create new one (P6Spy one) used as proxy to real one,

defined like this:

<Call name="addService">
    <Arg>
        <New class="org.mortbay.jetty.plus.DefaultDataSourceService">
            <Set name="Name">DataSourceService</Set>

            <Call name="addDataSource">
                <Arg>p6spy_ds</Arg><!--java:comp/env -->
                <Arg>
                    <New class="com.p6spy.engine.spy.P6DataSource">
                        <!-- properties would be irrelevant here -->
                        <Set name="description">xxxx</Set>
                        <Set name="user">xxx</Set>
                        <Set name="password">xxxx</Set>
                        <Set name="loginTimeout">xxx</Set>
                        <Set name="URL">jdbc:oracle:thin:@localhost:1521:xxx</Set>
                    </New>
                </Arg>
            </Call>
            <Call name="start" />
        </New>
  • and make sure to refer the real one from the spy.properties file,

using:

realdatasource=jdbc/app_ds # assuming that app_ds is your real datasource
  • the last thing is to refer the proxy_ds in all your application logic to make sure to use it (If referring would cost you too much, you can always call the proxy datasource the same as the original one and rename the original one + refer the new name in spy.properties config file)

Upvotes: 1

Related Questions