Problems with PGXADataSource: class cast

Help
DiegoMan
2009-03-03
2013-04-25
  • DiegoMan
    DiegoMan
    2009-03-03

    Hi. I'm trying to configure P6SPY with Atomikos TransactionsEssentials + Tomcat 5.5 + PostgreSQL.

    I have this configured in Tomcat:

    ####################

    <Resource name="jdbc/test2" auth="Container"
        type="org.postgresql.xa.PGXADataSource"
        factory="org.postgresql.xa.PGXADataSourceFactory"
        databaseName="test"
          serverName="localhost"
          portNumber="5432"
          user="test"
          password="test"
    />

    <Resource name="jdbc/test" auth="Container"
        type="com.atomikos.jdbc.AtomikosDataSourceBean"
        factory="com.atomikos.tomcat.BeanFactory"
        uniqueResourceName="jdbc/test"
        xaDataSourceClassName="com.p6spy.engine.spy.P6XADataSource"
        maxPoolSize="10"
           minPoolSize="1"
    />
    ####################

    And then, in spy.properties:

    ####################
    realdatasource=java:comp/env/jdbc/test2
    realdatasourceclass=org.postgresql.xa.PGXADataSource
    ####################

    When I start Tomcat, this exception is thrown:

    ####################
    Caused by: java.lang.ClassCastException: org.postgresql.xa.PGXADataSource
        at com.p6spy.engine.spy.P6DataSource.bindDataSource(P6DataSource.java:191)
        at com.p6spy.engine.spy.P6DataSource.setLoginTimeout(P6DataSource.java:341)
        at com.atomikos.jdbc.AtomikosDataSourceBean.doInit(AtomikosDataSourceBean.java:135)
        at com.atomikos.jdbc.AbstractDataSourceBean.init(AbstractDataSourceBean.java:253)
    ####################

    The source code line:

    ####################
    rds = (DataSource) ctx.lookup(rdsName);
    ####################

    P6SPY is trying to cast the "real" data source to a javax.sql.DataSource reference, yet PGXADataSource doesn't implement that interface. It seems that P6SPY is assuming that the real data source will implement javax.sql.DataSource, apart from javax.sql.XADataSource (which is not a subinterface of DataSource).

    Should this be considered a bug? I think P6XADataSource should override part of P6DataSource behaviour, and not assume that the real data source implements javax.sql.DataSource. I guess most of javax.sql.XADataSource implementations implement javax.sql.DataSource as well, but this is not the case, nor it's forced to do so.

    Thanks in advance

     
    • Ralph Harnden
      Ralph Harnden
      2009-03-06

      Yeah, it looks like a bug, but since this project apparently not longer has an admin, there is no way to get it fixed, unless you want to do it yourself! :)

      That's what I do....

       
    • Pat
      Pat
      2009-03-13

      back in business ... if you have a patch let me know ...

      starting point for new code is in svn (not cvs )

       
  • Pat
    Pat
    2010-12-29

    Hi there -

    Sorry for the late response. I think I am the only one who has recently done anything with p6spy. I got some basic access to this project from the only original developer I could reach. Unfortunately, not full project admin access. So I have moved over to github for further development.

    You are welcome to help out there by forking and then sending me a pull request.

    Further development at : https://github.com/patmoore/p6spy