Hi again,

That's perfectly right -- yesterday I added a recursive generic unwrap-function to the default Oracle9i platform that will try to unwrap Connection and PreparedStatement objects until and Oracle-compatible class is found.

Current implementation knows about Oracle10g, Commons DBCP, P6Spy and BEA WebLogic.

wow really nice...

There is a problem with using Oracle and the default DBCP connection factory, since PreparedStatement caching in DBCP will "eat" all your Oracle cursors rather quickly. See the release notes for a work-around (set PSPoolFactory==null). In OJB 1.1 the configuration mechanism will be a bit more flexible so you will probably not see any new connection factories in the 1.0.x line of releases.

Dang, I spent a couple on days on this issue last week, I didn't saw the release notes...
I ended up implementing a custom DBCP connection factory that is using a BasicDataSource instead of a PooledDataSource. Since the documentation of the DBCP stuff is really ugly I didn't find out what the difference really is between the PooledDataSource and the BasicDataSource. Fact is that with the BasicDataSource based implementation the problem with the MAX_OPEN_CURSORS is solved, because a fixed-size PreparedStatement cache is used.


below the code we are using:
Sorry, I didn't took out the code specific to our application, static calls to ORSConfiguration.<some-method> are used to load stuff from our config. files and could be replaced by constants or values loaded from OJB config, calls to ORSLogger.SYSTEM.<some-method> are used for our internal logging routines.
Note that it is necessary to implement/override also the releaseAllResources() method for closing the pooled connections on application shutdown.


--------

public class ORSConnFactDBCPImpl extends ConnectionFactoryDBCPImpl {

    private BasicDataSource pooledDs = null;

    /** Creates a new instance of ORSConnFactDBCPImpl */
    public ORSConnFactDBCPImpl() {}

    /** Overrides ConnectionFactoryDBCPImpl.createConnectionFactory( 
JdbcConnectionDescriptor jcd ) */
    protected org.apache.commons.dbcp.ConnectionFactory 
createConnectionFactory( JdbcConnectionDescriptor jcd ) {

        // This is custom code for setting custom JDBC driver 
attributes/properties
        // adding support for extracting the attributes from the 
JdbcConnectionDescriptor
        // would be the required implementation of (my) feature request:
        // OJB298 (Setting custom JDBC driver tuning options trough 
jdbc-connection-descriptor)

        Properties connProp = ORSConfiguration.getJDBCDriverOptions();
        // Add user and password
        connProp.put( "user", jcd.getUserName() );
        connProp.put( "password", jcd.getPassWord() );

        return new DriverManagerConnectionFactory( super.getDbURL( jcd ), 
connProp );
    }

    /**
     * Override this method to setup your own pool
     */
    protected DataSource setupPool( JdbcConnectionDescriptor jcd ) {
        ORSLogger.SYSTEM.debug( "Creating new ORS DBCP connection pool" );

        try {
            ClassHelper.newInstance( jcd.getDriver() );
        } catch ( InstantiationException e ){
            ORSLogger.SYSTEM.fatal( "Unable to instantiate the driver class: " + 
jcd.getDriver() + " in ConnectionFactoryDBCImpl!" , e );
        } catch (IllegalAccessException e ) {
            ORSLogger.SYSTEM.fatal( "IllegalAccessException while instantiating the driver 
class: " + jcd.getDriver() + " in ConnectionFactoryDBCImpl!" , e );
        } catch (ClassNotFoundException e ) {
            ORSLogger.SYSTEM.fatal( "Could not find the driver class : " + 
jcd.getDriver() + " in ConnectionFactoryDBCImpl!" , e );
        }

        // get the configuration for the connection pool
        GenericObjectPool.Config conf = 
jcd.getConnectionPoolDescriptor().getObjectPoolConfig();

        this.pooledDs = new BasicDataSource();
        // Init using the data from connection descriptor in repository.xml
        this.pooledDs.setDefaultAutoCommit( jcd.getUseAutoCommit() != 
JdbcConnectionDescriptor.AUTO_COMMIT_SET_FALSE );
        this.pooledDs.setDriverClassName( jcd.getDriver() );
        this.pooledDs.setMaxActive( conf.maxActive );
        this.pooledDs.setMaxIdle( conf.maxIdle );
        this.pooledDs.setMaxWait( conf.maxWait );
        this.pooledDs.setMinEvictableIdleTimeMillis( 
conf.minEvictableIdleTimeMillis );
        this.pooledDs.setMinIdle( conf.minIdle );
        this.pooledDs.setNumTestsPerEvictionRun( conf.numTestsPerEvictionRun );
        this.pooledDs.setPassword( jcd.getPassWord() );
        this.pooledDs.setTestOnBorrow( conf.testOnBorrow );
        this.pooledDs.setTestOnReturn( conf.testOnReturn );
        this.pooledDs.setTestWhileIdle( conf.testWhileIdle );
        this.pooledDs.setTimeBetweenEvictionRunsMillis( 
conf.timeBetweenEvictionRunsMillis );
        this.pooledDs.setUrl( super.getDbURL( jcd ) );
        this.pooledDs.setUsername( jcd.getUserName() );
        this.pooledDs.setValidationQuery( 
jcd.getConnectionPoolDescriptor().getValidationQuery() );

        // Configure PreparedStatement pooling getting data from the ORS 
configuration file
        this.pooledDs.setMaxOpenPreparedStatements( ORSConfiguration.getIntValue( 
"preparedStatement.pooling.size" ) );
        this.pooledDs.setPoolPreparedStatements( ORSConfiguration.getBooleanValue( 
"preparedStatement.pooling.active" ) );

        // Allow this because Oracle LOB handling must have direct access to 
the connection object
        this.pooledDs.setAccessToUnderlyingConnectionAllowed( true );

        return this.pooledDs;
    }

    /** Clean up all resources, this method is called by OJB when shutting down 
the application */
    public synchronized void releaseAllResources() {
        ORSLogger.SYSTEM.debug( "Closing all pooled connections" );
        if ( this.pooledDs != null ) {
            try {
                this.pooledDs.close();
            } catch ( java.sql.SQLException sqle ) {
                ORSLogger.SYSTEM.warn( "Unexpected SQLException occured when closing 
connections", sqle );
            }
        }
        super.releaseAllResources();
    }
}


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to