From 87c0f779e412051755df47e57cf19989a5e96cc6 Mon Sep 17 00:00:00 2001 From: Torsten Friebe Date: Sat, 23 Nov 2019 18:09:37 +0100 Subject: [PATCH 1/5] #1017 fixed upgraded to Apache Commons Pool 2.7.0 and Apache Commons DBCP 2.7.0 --- .../datasource/3.4.0/example_dbcp_mssql.xml | 2 +- .../datasource/3.4.0/example_dbcp_oracle.xml | 2 +- .../3.4.0/example_dbcp_postgres.xml | 2 +- deegree-core/deegree-core-commons/pom.xml | 8 +-- .../deegree/commons/jdbc/ConnectionPool.java | 30 +++++---- .../db/legacy/LegacyConnectionProvider.java | 5 +- .../tile/persistence/geotiff/GeoTIFFTile.java | 2 +- .../geotiff/GeoTIFFTileDataLevel.java | 2 +- .../geotiff/ImageReaderFactory.java | 61 +++++++++---------- .../src/main/asciidoc/serverconnections.adoc | 18 +++--- pom.xml | 12 ++-- 11 files changed, 72 insertions(+), 72 deletions(-) diff --git a/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_mssql.xml b/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_mssql.xml index 97ec533d22..ed80cb824c 100644 --- a/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_mssql.xml +++ b/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_mssql.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd"> - + diff --git a/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_oracle.xml b/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_oracle.xml index 305700e9c7..77cc72831a 100644 --- a/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_oracle.xml +++ b/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_oracle.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd"> - + diff --git a/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_postgres.xml b/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_postgres.xml index 18176a7252..defc7069b8 100644 --- a/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_postgres.xml +++ b/deegree-core/deegree-connectionprovider-datasource/src/main/resources/META-INF/schemas/connectionprovider/datasource/3.4.0/example_dbcp_postgres.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd"> - + diff --git a/deegree-core/deegree-core-commons/pom.xml b/deegree-core/deegree-core-commons/pom.xml index 56f5e9eb5c..199c685fff 100644 --- a/deegree-core/deegree-core-commons/pom.xml +++ b/deegree-core/deegree-core-commons/pom.xml @@ -72,16 +72,16 @@ xercesImpl - commons-dbcp - commons-dbcp + org.apache.commons + commons-dbcp2 org.apache.httpcomponents httpclient - commons-pool - commons-pool + org.apache.commons + commons-pool2 jogl diff --git a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/jdbc/ConnectionPool.java b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/jdbc/ConnectionPool.java index 5664e9ce28..63c525b86c 100644 --- a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/jdbc/ConnectionPool.java +++ b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/jdbc/ConnectionPool.java @@ -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; @@ -67,7 +67,7 @@ public class ConnectionPool { private final PoolingDataSource ds; - private final GenericObjectPool pool; + private final GenericObjectPool pool; /** * Creates a new {@link ConnectionPool} instance. @@ -84,14 +84,16 @@ public ConnectionPool( String id, String connectURI, String user, String passwor int maxActive ) { this.id = id; - pool = new GenericObjectPool( 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 @@ -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 ); } } diff --git a/deegree-core/deegree-core-db/src/main/java/org/deegree/db/legacy/LegacyConnectionProvider.java b/deegree-core/deegree-core-db/src/main/java/org/deegree/db/legacy/LegacyConnectionProvider.java index 30e2cfd422..0f5a3fd223 100644 --- a/deegree-core/deegree-core-db/src/main/java/org/deegree/db/legacy/LegacyConnectionProvider.java +++ b/deegree-core/deegree-core-db/src/main/java/org/deegree/db/legacy/LegacyConnectionProvider.java @@ -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; @@ -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 ); } diff --git a/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/GeoTIFFTile.java b/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/GeoTIFFTile.java index ee14274cd3..7f12bd011a 100644 --- a/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/GeoTIFFTile.java +++ b/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/GeoTIFFTile.java @@ -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; diff --git a/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/GeoTIFFTileDataLevel.java b/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/GeoTIFFTileDataLevel.java index 443c127430..b042dda3a4 100644 --- a/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/GeoTIFFTileDataLevel.java +++ b/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/GeoTIFFTileDataLevel.java @@ -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; diff --git a/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/ImageReaderFactory.java b/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/ImageReaderFactory.java index 6c5d5d2eac..75008d1292 100644 --- a/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/ImageReaderFactory.java +++ b/deegree-datastores/deegree-tilestores/deegree-tilestore-geotiff/src/main/java/org/deegree/tile/persistence/geotiff/ImageReaderFactory.java @@ -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; /** - * ImageReaderFactory: 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... + * ImageReaderFactory: an object factory for Apache commons-pool providing + * file-based image reader. * * @author Andreas Schmitz - * @author last edited by: $Author: mschneider $ - * - * @version $Revision: 31882 $, $Date: 2011-09-15 02:05:04 +0200 (Thu, 15 Sep 2011) $ + * @author Torsten Friebe + * */ +public class ImageReaderFactory implements PooledObjectFactory { -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 makeObject() throws Exception { ImageInputStream iis = null; ImageReader reader = null; Iterator readers = getImageReadersBySuffix( "tiff" ); @@ -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; - } - } diff --git a/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc b/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc index 47a6cf5ede..a30fd85aa1 100644 --- a/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc +++ b/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc @@ -55,7 +55,7 @@ database: xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd"> - + @@ -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 @@ -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"> - + @@ -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 @@ -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"> - + @@ -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 @@ -284,13 +284,13 @@ snippets for clarification: [source,xml] ---- ... - + ... ---- 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. @@ -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 diff --git a/pom.xml b/pom.xml index 6046e3ea4f..bb61a3737d 100644 --- a/pom.xml +++ b/pom.xml @@ -446,14 +446,14 @@ - commons-pool - commons-pool - 1.6 + org.apache.commons + commons-pool2 + 2.7.0 - commons-dbcp - commons-dbcp - 1.4 + org.apache.commons + commons-dbcp2 + 2.7.0 commons-cli From 3861f5b369b89edd4c2b7b1f83e324347b9275d9 Mon Sep 17 00:00:00 2001 From: Torsten Friebe Date: Mon, 25 Nov 2019 14:29:16 +0100 Subject: [PATCH 2/5] Enhanced logging to trace unclosed connection pools --- .../deegree/db/datasource/DataSourceConnectionProvider.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/deegree-core/deegree-connectionprovider-datasource/src/main/java/org/deegree/db/datasource/DataSourceConnectionProvider.java b/deegree-core/deegree-connectionprovider-datasource/src/main/java/org/deegree/db/datasource/DataSourceConnectionProvider.java index 4081badea5..4be290694b 100644 --- a/deegree-core/deegree-connectionprovider-datasource/src/main/java/org/deegree/db/datasource/DataSourceConnectionProvider.java +++ b/deegree-core/deegree-connectionprovider-datasource/src/main/java/org/deegree/db/datasource/DataSourceConnectionProvider.java @@ -118,12 +118,16 @@ public Connection getConnection() { @Override public void destroy() { if ( destroyMethod != null ) { + LOG.info("Closing connection pool " + resourceMetadata.getIdentifier()); try { destroyMethod.invoke( ds ); } catch ( Exception e ) { String msg = "Error destroying DataSource instance: " + e.getLocalizedMessage(); LOG.error( msg ); } + } else { + LOG.warn("Unable to close connection pool " + resourceMetadata.getIdentifier() + + ". Check the DataSource configuration if the attribute 'destroyMethod' is configured." ); } } From 08112b4a21de0715d6840fd838d7e61874cb81de Mon Sep 17 00:00:00 2001 From: Torsten Friebe Date: Mon, 25 Nov 2019 14:47:07 +0100 Subject: [PATCH 3/5] Update handbook about destroyMethod and property name maxTotal (was maxActive in DBCP 1.x) --- .../src/main/asciidoc/serverconnections.adoc | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc b/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc index a30fd85aa1..d42fe073bf 100644 --- a/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc +++ b/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc @@ -54,15 +54,15 @@ database: xmlns="http://www.deegree.org/connectionprovider/datasource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd"> - - + + - + ---- @@ -101,8 +101,8 @@ This example defines a connection pool for an Oracle database: xmlns="http://www.deegree.org/connectionprovider/datasource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd"> - - + + @@ -110,7 +110,7 @@ This example defines a connection pool for an Oracle database: - + @@ -146,8 +146,8 @@ This example defines a connection pool for a Microsoft SQL Server: xmlns="http://www.deegree.org/connectionprovider/datasource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd"> - - + + @@ -155,7 +155,7 @@ This example defines a connection pool for a Microsoft SQL Server: - + @@ -187,7 +187,7 @@ servlet container that runs deegree webservices (e.g. Apache Tomcat): xmlns="http://www.deegree.org/connectionprovider/datasource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.deegree.org/connectionprovider/datasource http://schemas.deegree.org/jdbc/datasource/3.4.0/datasource.xsd"> - + @@ -270,8 +270,8 @@ allows for the following options: |factoryMethod |0..1 |String |If present, this static method is used (instead of constructor) -|destroyMethod |0..1 |String |Configuration of javax.sql.DataSource -object +|destroyMethod |0..1 |String |Method to be invoked on the javax.sql.DataSource +object to close the underlying connection pool |Argument |0..1 |Complex |Argument to use for instantiation/method call |=== @@ -297,7 +297,8 @@ arguments passed to the constructor. [source,xml] ---- -... +... + @@ -335,7 +336,7 @@ _javax.sql.DataSource_ instance: - + ... ---- @@ -368,7 +369,7 @@ is called 'inspire', the database user is 'postgres' and password is [source,xml] ---- + xsi:schemaLocation="http://www.deegree.org/jdbc http://schemas.deegree.org/jdbc/3.4.0/jdbc.xsd"> jdbc:postgresql://localhost:5432/inspire postgres postgres @@ -376,8 +377,8 @@ is called 'inspire', the database user is 'postgres' and password is ---- The legacy connection config file format is defined by schema file -http://schemas.deegree.org/jdbc/3.0.0/jdbc.xsd. The root element is -_JDBCConnection_ and the config attribute must be _3.0.0_. The +http://schemas.deegree.org/jdbc/3.4.0/jdbc.xsd. The root element is +_JDBCConnection_ and the config attribute must be _3.4.0_. The following table lists the available configuration options. When specifiying them, their order must be respected. From 4a7ee0e182628fb87e2e7fa3aa240dbcf013dc53 Mon Sep 17 00:00:00 2001 From: dstenger Date: Wed, 27 Nov 2019 13:29:28 +0100 Subject: [PATCH 4/5] Enhance documentation of destroyMethod --- .../src/main/asciidoc/serverconnections.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc b/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc index d42fe073bf..b35fadadf4 100644 --- a/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc +++ b/deegree-services/deegree-webservices-handbook/src/main/asciidoc/serverconnections.adoc @@ -271,7 +271,7 @@ allows for the following options: (instead of constructor) |destroyMethod |0..1 |String |Method to be invoked on the javax.sql.DataSource -object to close the underlying connection pool +object to close the underlying connection pool. Which method to be called depends on the implementation of the javax.sql.DataSource. Check the API documentation for more information. |Argument |0..1 |Complex |Argument to use for instantiation/method call |=== From 9243ec4eab00464d66c3e987401623a417a00ef5 Mon Sep 17 00:00:00 2001 From: Lyn Elisa Goltz Date: Wed, 27 Jan 2021 13:52:12 +0100 Subject: [PATCH 5/5] fixed formatting, use placeholders --- .../datasource/DataSourceConnectionProvider.java | 15 +++++++-------- .../org/deegree/commons/jdbc/ConnectionPool.java | 13 ++++++------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/deegree-core/deegree-connectionprovider-datasource/src/main/java/org/deegree/db/datasource/DataSourceConnectionProvider.java b/deegree-core/deegree-connectionprovider-datasource/src/main/java/org/deegree/db/datasource/DataSourceConnectionProvider.java index 4be290694b..5808b1e592 100644 --- a/deegree-core/deegree-connectionprovider-datasource/src/main/java/org/deegree/db/datasource/DataSourceConnectionProvider.java +++ b/deegree-core/deegree-connectionprovider-datasource/src/main/java/org/deegree/db/datasource/DataSourceConnectionProvider.java @@ -57,9 +57,9 @@ Occam Labs UG (haftungsbeschränkt) /** * {@link ConnectionProvider} based on javax.sql.DataSource. - * + * * @author Markus Schneider - * + * * @since 3.4 */ class DataSourceConnectionProvider implements ConnectionProvider { @@ -76,7 +76,7 @@ class DataSourceConnectionProvider implements ConnectionProvider { /** * Creates a new {@link DataSourceConnectionProvider} instance. - * + * * @param resourceMetadata * metadata, must not be null * @param ds @@ -118,16 +118,15 @@ public Connection getConnection() { @Override public void destroy() { if ( destroyMethod != null ) { - LOG.info("Closing connection pool " + resourceMetadata.getIdentifier()); + LOG.info("Closing connection pool {}", resourceMetadata.getIdentifier()); try { destroyMethod.invoke( ds ); } catch ( Exception e ) { - String msg = "Error destroying DataSource instance: " + e.getLocalizedMessage(); - LOG.error( msg ); + LOG.error( "Error destroying DataSource instance: {}", e.getLocalizedMessage() ); } } else { - LOG.warn("Unable to close connection pool " + resourceMetadata.getIdentifier() - + ". Check the DataSource configuration if the attribute 'destroyMethod' is configured." ); + LOG.warn( "Unable to close connection pool {}. Check the DataSource configuration if the attribute " + + "'destroyMethod' is configured.", resourceMetadata.getIdentifier() ); } } diff --git a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/jdbc/ConnectionPool.java b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/jdbc/ConnectionPool.java index 63c525b86c..3e4a8e155f 100644 --- a/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/jdbc/ConnectionPool.java +++ b/deegree-core/deegree-core-commons/src/main/java/org/deegree/commons/jdbc/ConnectionPool.java @@ -52,10 +52,9 @@ /** * Simple implementation of a JDBC connection pool based on the Apache Commons Pool and DBCP projects. - * + * * @author Markus Schneider * @author last edited by: $Author: schneider $ - * * @version $Revision: $, $Date: $ */ @LoggingNotes(debug = "logs information about pool usage") @@ -71,7 +70,7 @@ public class ConnectionPool { /** * Creates a new {@link ConnectionPool} instance. - * + * * @param id * @param connectURI * @param user @@ -86,12 +85,12 @@ public ConnectionPool( String id, String connectURI, String user, String passwor this.id = id; ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectURI, user, password ); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( connectionFactory, null ); - pool = new GenericObjectPool<>(poolableConnectionFactory); + pool = new GenericObjectPool<>( poolableConnectionFactory ); pool.setMinIdle( minIdle ); pool.setMaxTotal( maxActive ); - pool.setTestOnBorrow(true); + pool.setTestOnBorrow( true ); - poolableConnectionFactory.setPool(pool); + poolableConnectionFactory.setPool( pool ); ds = new PoolingDataSource( pool ); // needed, so users can retrieve the underlying connection from pooled @@ -102,7 +101,7 @@ public ConnectionPool( String id, String connectURI, String user, String passwor /** * Returns a {@link Connection} from the pool. - * + * * @return a connection from the pool * @throws SQLException */