Yes, thanks, I also noticed the broken link and found the sample, figuring it must exist somewhere. That code is better.
I will open JIRA, thanks. On 07/31/2017 01:16 PM, Phil Steitz wrote: > On 7/31/17 9:07 AM, Steve Cohen wrote: >> The DBCP package description page is referred to from the Overview page >> as containing important information on usage of the package. >> >> The following sample code is provided there: >> >> >>> GenericObjectPool connectionPool = new GenericObjectPool(null); >>> ConnectionFactory connectionFactory = new >>> DriverManagerConnectionFactory("jdbc:some:connect:string", "username", >>> "password"); >>> PoolableConnectionFactory poolableConnectionFactory = new >>> PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true); >>> PoolingDataSource dataSource = new PoolingDataSource(connectionPool); >> >> >> The third line appears out of date: No such constructor of >> PoolableConnectionFactory appears to exist. Instead I find >> >> PoolableConnectionFactory(ConnectionFactory connFactory, ObjectName >> dataSourceJmxName) >> >> OK, I can use that. >> >> But ... >> Eclipse is warning me that this PoolableConnectionFactory is not used in >> the code. And it's right! Nothing ties the poolableConnectionFactory >> object we create in that line to anything else, and it doesn't appear to >> be needed. >> >> At any rate, I'm confused. What role does this object play in the >> scenario the documentation is referring to? > > The package javadoc was not updated to reflect the API changes made > in dbcp2. It would be good to raise a JIRA for this. > Unfortunately, the examples link appears now to be broken, but there > is an example in the /doc directory of the source distribution that > shows how to set up a PoolingDataSource. You can also see this in > the unit tests. Here is the relevant bit of the sample code from > the /doc sources: > > public static DataSource setupDataSource(String connectURI) { > // > // First, we'll create a ConnectionFactory that the > // pool will use to create Connections. > // We'll use the DriverManagerConnectionFactory, > // using the connect string passed in the command line > // arguments. > // > ConnectionFactory connectionFactory = > new DriverManagerConnectionFactory(connectURI,null); > > // > // Next we'll create the PoolableConnectionFactory, which wraps > // the "real" Connections created by the ConnectionFactory with > // the classes that implement the pooling functionality. > // > PoolableConnectionFactory poolableConnectionFactory = > new PoolableConnectionFactory(connectionFactory, null); > > // > // Now we'll need a ObjectPool that serves as the > // actual pool of connections. > // > // We'll use a GenericObjectPool instance, although > // any ObjectPool implementation will suffice. > // > ObjectPool<PoolableConnection> connectionPool = > new GenericObjectPool<>(poolableConnectionFactory); > > // Set the factory's pool property to the owning pool > poolableConnectionFactory.setPool(connectionPool); > > // > // Finally, we create the PoolingDriver itself, > // passing in the object pool we created. > // > PoolingDataSource<PoolableConnection> dataSource = > new PoolingDataSource<>(connectionPool); > > return dataSource; > } > > hth, > > Phil >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org >> For additional commands, e-mail: user-h...@commons.apache.org >> >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org