db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer ConnectionFactoryDBCPImpl.java
Date Fri, 12 Dec 2003 13:29:02 GMT
arminw      2003/12/12 05:29:02

  Modified:    src/java/org/apache/ojb/broker/accesslayer
                        ConnectionFactoryDBCPImpl.java
  Log:
  add new methods to allow user a better control of
  DBCP pool creation. Now it is easy to override one
  of the createXXX methods.
  
  Revision  Changes    Path
  1.6       +26 -8     db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java
  
  Index: ConnectionFactoryDBCPImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/ConnectionFactoryDBCPImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConnectionFactoryDBCPImpl.java	5 May 2003 23:46:42 -0000	1.5
  +++ ConnectionFactoryDBCPImpl.java	12 Dec 2003 13:29:02 -0000	1.6
  @@ -33,8 +33,6 @@
       private Logger log = LoggerFactory.getLogger(ConnectionFactoryDBCPImpl.class);
   
       private Map poolMap = new HashMap();
  -    /* @todo make objectPool configurable at runtime */
  -    private ObjectPool connectionPool;
   
       public Connection getConnectionFromPool(JdbcConnectionDescriptor jcd) throws LookupException
       {
  @@ -102,16 +100,16 @@
           // We'll use a GenericObjectPool instance, although
           // any ObjectPool implementation will suffice.
           //
  -        connectionPool = new GenericObjectPool(null, conf);
  +        // TODO: make objectPool configurable at runtime?
  +        ObjectPool connectionPool = createObjectPool(conf);
   
           // Next, we'll create a ConnectionFactory that the
           // pool will use to create Connections.
           // We'll use the DriverManagerConnectionFactory,
           //
  -        org.apache.commons.dbcp.ConnectionFactory connectionFactory =
  -                new DriverManagerConnectionFactory(getDbURL(jcd), jcd.getUserName(), jcd.getPassWord());
  +        org.apache.commons.dbcp.ConnectionFactory connectionFactory = createConnectionFactory(jcd);
   
  -        KeyedObjectPoolFactory statementPoolFactory = new GenericKeyedObjectPoolFactory(null);
  +        KeyedObjectPoolFactory statementPoolFactory = createStatementPoolFactory(null);
           // set the validation query
           String validationQuery = jcd.getConnectionPoolDescriptor().getValidationQuery();
           boolean defaultReadOnly = false;
  @@ -140,7 +138,27 @@
           // Finally, we create the PoolingDriver itself,
           // passing in the object pool we created.
           //
  -        PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
  +        PoolingDataSource dataSource = createPoolingDataSource(poolableConnectionFactory.getPool());
           return dataSource;
  +    }
  +
  +    protected ObjectPool createObjectPool(GenericObjectPool.Config config)
  +    {
  +        return new GenericObjectPool(null, config);
  +    }
  +
  +    protected org.apache.commons.dbcp.ConnectionFactory createConnectionFactory(JdbcConnectionDescriptor
jcd)
  +    {
  +        return new DriverManagerConnectionFactory(getDbURL(jcd), jcd.getUserName(), jcd.getPassWord());
  +    }
  +
  +    protected KeyedObjectPoolFactory createStatementPoolFactory(Object obj)
  +    {
  +        return new GenericKeyedObjectPoolFactory(null);
  +    }
  +
  +    protected PoolingDataSource createPoolingDataSource(ObjectPool pool)
  +    {
  +        return new PoolingDataSource(pool);
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message