Skip to content

Commit

Permalink
deegree#1017 fixed upgraded to Apache Commons Pool 2.7.0 and Apache C…
Browse files Browse the repository at this point in the history
…ommons DBCP 2.7.0
  • Loading branch information
tfr42 committed Nov 23, 2019
1 parent 348111b commit 87c0f77
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd">

<!-- Creation / lookup of javax.sql.DataSource instance -->
<DataSource javaClass="org.apache.commons.dbcp.BasicDataSource" />
<DataSource javaClass="org.apache.commons.dbcp2.BasicDataSource" />

<!-- Configuration of DataSource properties -->
<Property name="driverClassName" value="com.mysql.jdbc.Driver" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd">

<!-- Creation / lookup of javax.sql.DataSource instance -->
<DataSource javaClass="org.apache.commons.dbcp.BasicDataSource" />
<DataSource javaClass="org.apache.commons.dbcp2.BasicDataSource" />

<!-- Configuration of DataSource properties -->
<Property name="driverClassName" value="oracle.jdbc.OracleDriver" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd">

<!-- Creation / lookup of javax.sql.DataSource instance -->
<DataSource javaClass="org.apache.commons.dbcp.BasicDataSource" />
<DataSource javaClass="org.apache.commons.dbcp2.BasicDataSource" />

<!-- Configuration of DataSource properties -->
<Property name="driverClassName" value="org.postgresql.Driver" />
Expand Down
8 changes: 4 additions & 4 deletions deegree-core/deegree-core-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@
<artifactId>xercesImpl</artifactId>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>jogl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbcp.ConnectionFactory;
import org.apache.commons.dbcp.DelegatingConnection;
import org.apache.commons.dbcp.DriverManagerConnectionFactory;
import org.apache.commons.dbcp.PoolableConnectionFactory;
import org.apache.commons.dbcp.PoolingDataSource;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.commons.dbcp2.ConnectionFactory;
import org.apache.commons.dbcp2.DriverManagerConnectionFactory;
import org.apache.commons.dbcp2.PoolableConnection;
import org.apache.commons.dbcp2.PoolableConnectionFactory;
import org.apache.commons.dbcp2.PoolingDataSource;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.deegree.commons.annotations.LoggingNotes;
import org.slf4j.Logger;

Expand All @@ -67,7 +67,7 @@ public class ConnectionPool {

private final PoolingDataSource ds;

private final GenericObjectPool<Connection> pool;
private final GenericObjectPool<PoolableConnection> pool;

/**
* Creates a new {@link ConnectionPool} instance.
Expand All @@ -84,14 +84,16 @@ public ConnectionPool( String id, String connectURI, String user, String passwor
int maxActive ) {

this.id = id;
pool = new GenericObjectPool<Connection>( null );
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectURI, user, password );
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( connectionFactory, null );
pool = new GenericObjectPool<>(poolableConnectionFactory);
pool.setMinIdle( minIdle );
pool.setMaxActive( maxActive );
pool.setMaxTotal( maxActive );
pool.setTestOnBorrow(true);

ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectURI, user, password );
// TODO make this configurable
new PoolableConnectionFactory( connectionFactory, pool, null, null, readOnly, true );
poolableConnectionFactory.setPool(pool);
ds = new PoolingDataSource( pool );

// needed, so users can retrieve the underlying connection from pooled
// connections, e.g. to access the
// LargeObjectManager from a PGConnection
Expand All @@ -117,11 +119,13 @@ public Connection getConnection()
public void destroy()
throws Exception {
pool.close();
ds.close();
}

public void invalidate( DelegatingConnection conn )
public void invalidate( PoolableConnection conn )
throws Exception {
conn.getDelegate().close();
conn.reallyClose();
pool.invalidateObject( conn );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Occam Labs UG (haftungsbeschränkt)
import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbcp.DelegatingConnection;
import org.apache.commons.dbcp2.DelegatingConnection;
import org.apache.commons.dbcp2.PoolableConnection;
import org.deegree.commons.jdbc.ConnectionPool;
import org.deegree.db.ConnectionProvider;
import org.deegree.sqldialect.SQLDialect;
Expand Down Expand Up @@ -128,7 +129,7 @@ public SQLDialect getDialect() {
@Override
public void invalidate( Connection conn ) {
try {
pool.invalidate( (DelegatingConnection) conn );
pool.invalidate( (PoolableConnection) conn );
} catch ( Exception e ) {
throw new RuntimeException( e );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Occam Labs UG (haftungsbeschränkt)
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;

import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.deegree.feature.FeatureCollection;
import org.deegree.geometry.Envelope;
import org.deegree.tile.Tile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Occam Labs UG (haftungsbeschränkt)
import java.io.File;
import java.util.List;

import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.deegree.geometry.Envelope;
import org.deegree.geometry.GeometryFactory;
import org.deegree.tile.TileDataLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,42 +50,52 @@ Occam Labs UG (haftungsbeschränkt)
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.apache.commons.pool2.PooledObjectFactory;
import org.apache.commons.pool2.impl.DefaultPooledObject;

/**
* <code>ImageReaderFactory</code>: an object factory for commons-pool. It should really be replaced with a better
* solution, not using generics here (and throwing Exception) is not the way to go...
* <code>ImageReaderFactory</code>: an object factory for Apache commons-pool providing
* file-based image reader.
*
* @author <a href="mailto:schmitz@occamlabs.de">Andreas Schmitz</a>
* @author last edited by: $Author: mschneider $
*
* @version $Revision: 31882 $, $Date: 2011-09-15 02:05:04 +0200 (Thu, 15 Sep 2011) $
* @author <a href="mailto:friebe@lat-lon.de">Torsten Friebe</a>
*
*/
public class ImageReaderFactory implements PooledObjectFactory<ImageReader> {

public class ImageReaderFactory implements PoolableObjectFactory {

private File file;
private final File file;

public ImageReaderFactory( File file ) {
this.file = file;
}

@Override
public void activateObject( Object o )
throws Exception {
public void destroyObject(PooledObject pooledObject) throws Exception {
ImageReader reader = (ImageReader) pooledObject;
reader.dispose();
}

@Override
public boolean validateObject(PooledObject pooledObject) {
// ImageReader reader = (ImageReader) o;
// ImageInputStream iis = (ImageInputStream) reader.getInput();
// unknown if we need something here, so far no readers have become invalid
return true;
}

@Override
public void activateObject(PooledObject pooledObject) throws Exception {
// nothing to do
}

@Override
public void destroyObject( Object o )
throws Exception {
ImageReader reader = (ImageReader) o;
reader.dispose();
public void passivateObject(PooledObject pooledObject) throws Exception {
// nothing to do
}

@Override
public Object makeObject()
throws Exception {
public PooledObject<ImageReader> makeObject() throws Exception {
ImageInputStream iis = null;
ImageReader reader = null;
Iterator<ImageReader> readers = getImageReadersBySuffix( "tiff" );
Expand All @@ -95,21 +105,6 @@ public Object makeObject()
iis = createImageInputStream( file );
// already checked in provider
reader.setInput( iis );
return reader;
return new DefaultPooledObject(reader);
}

@Override
public void passivateObject( Object o )
throws Exception {
// nothing to do
}

@Override
public boolean validateObject( Object o ) {
// ImageReader reader = (ImageReader) o;
// ImageInputStream iis = (ImageInputStream) reader.getInput();
// unknown if we need something here, so far no readers have become invalid
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ database:
xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd">
<!-- Creation / lookup of javax.sql.DataSource instance -->
<DataSource javaClass="org.apache.commons.dbcp.BasicDataSource" />
<DataSource javaClass="org.apache.commons.dbcp2.BasicDataSource" />
<!-- Configuration of DataSource properties -->
<Property name="driverClassName" value="org.postgresql.Driver" />
Expand All @@ -68,7 +68,7 @@ database:
----

* The DataSource object uses Java class
_org.apache.commons.dbcp.BasicDataSource_ (a connection pool class
_org.apache.commons.dbcp2.BasicDataSource_ (a connection pool class
provided by
http://commons.apache.org/proper/commons-dbcp/index.html[Apache Commons
DBCP].). If you don't know what this means, then this is most likely
Expand Down Expand Up @@ -102,7 +102,7 @@ This example defines a connection pool for an Oracle database:
xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd">
<!-- Creation / lookup of javax.sql.DataSource instance -->
<DataSource javaClass="org.apache.commons.dbcp.BasicDataSource" />
<DataSource javaClass="org.apache.commons.dbcp2.BasicDataSource" />
<!-- Configuration of DataSource properties -->
<Property name="driverClassName" value="oracle.jdbc.OracleDriver" />
Expand All @@ -119,7 +119,7 @@ This example defines a connection pool for an Oracle database:
This defines a database connection with the following properties:

* The DataSource object uses the Java class
_org.apache.commons.dbcp.BasicDataSource_ (a connection pool class
_org.apache.commons.dbcp2.BasicDataSource_ (a connection pool class
provided by Apache DBCP). If you are not familiar with J2EE containers,
this is most likely what you want to use.
* The JDBC driver class is _oracle.jdbc.OracleDriver_. This is the
Expand Down Expand Up @@ -147,7 +147,7 @@ This example defines a connection pool for a Microsoft SQL Server:
xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd">
<!-- Creation / lookup of javax.sql.DataSource instance -->
<DataSource javaClass="org.apache.commons.dbcp.BasicDataSource" />
<DataSource javaClass="org.apache.commons.dbcp2.BasicDataSource" />
<!-- Configuration of DataSource properties -->
<Property name="driverClassName" value="org.postgresql.Driver" />
Expand All @@ -164,7 +164,7 @@ This example defines a connection pool for a Microsoft SQL Server:
This defines a database connection with the following properties:

* The DataSource object uses the Java class
_org.apache.commons.dbcp.BasicDataSource_ (a connection pool class
_org.apache.commons.dbcp2.BasicDataSource_ (a connection pool class
provided by Apache DBCP). If you are not familiar with J2EE containers,
this is most likely what you want to use.
* The JDBC driver class is _org.postgresql.Driver_. This is the Java
Expand Down Expand Up @@ -284,13 +284,13 @@ snippets for clarification:
[source,xml]
----
...
<DataSource javaClass="org.apache.commons.dbcp.BasicDataSource" />
<DataSource javaClass="org.apache.commons.dbcp2.BasicDataSource" />
...
----

In this snippet, no _factoryMethod_ attribute is present. Therefore,
the constructor of Java class
_org.apache.commons.dbcp.BasicDataSource_ is invoked. The returned
_org.apache.commons.dbcp2.BasicDataSource_ is invoked. The returned
instance must be an implementation of _javax.sql.DataSource_, and this
is guaranteed, because the class implements this interface. There are no
arguments passed to the constructor.
Expand Down Expand Up @@ -344,7 +344,7 @@ The properties available for configuration depend on the implementation
of _javax.sql.DataSource_:

* Apache Commons DBCP: See
http://commons.apache.org/proper/commons-dbcp/api-1.4/org/apache/commons/dbcp/BasicDataSource.html
http://commons.apache.org/proper/commons-dbcp/api-2.7.0/org/apache/commons/dbcp2/BasicDataSource.html
* Oracle UCP:
http://docs.oracle.com/cd/E11882_01/java.112/e12826/oracle/ucp/jdbc/PoolDataSource.html

Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,14 @@
</exclusions>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down

0 comments on commit 87c0f77

Please sign in to comment.