This is an automated email from the ASF dual-hosted git repository. ntimofeev pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 1df27fc08d407c025eb025b1dd2edb8b5e4466e6 Author: Nikita Timofeev <stari...@gmail.com> AuthorDate: Thu Jun 30 15:31:59 2022 +0300 CAY-2737 Cayenne 4.3: cleanup deprecated code - delete dbcp2 module --- cayenne-dbcp2/pom.xml | 75 ------------------ .../server/DBCPDataSourceFactory.java | 83 -------------------- .../server/DBCP2DataSourceFactoryTest.java | 88 ---------------------- .../configuration/server/testDBCP2.properties | 24 ------ 4 files changed, 270 deletions(-) diff --git a/cayenne-dbcp2/pom.xml b/cayenne-dbcp2/pom.xml deleted file mode 100644 index 3c8734111..000000000 --- a/cayenne-dbcp2/pom.xml +++ /dev/null @@ -1,75 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor - license agreements. See the NOTICE file distributed with this work for additional - information regarding copyright ownership. The ASF licenses this file to - you under the Apache License, Version 2.0 (the "License"); you may not use - this file except in compliance with the License. You may obtain a copy of - the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required - by applicable law or agreed to in writing, software distributed under the - License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS - OF ANY KIND, either express or implied. See the License for the specific - language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>cayenne-parent</artifactId> - <groupId>org.apache.cayenne</groupId> - <version>4.3.M1-SNAPSHOT</version> - </parent> - <artifactId>cayenne-dbcp2</artifactId> - <name>cayenne-dbcp2: Cayenne DBCP2 Extension</name> - <packaging>jar</packaging> - - <dependencies> - - <!-- Compile dependencies --> - <dependency> - <groupId>org.apache.cayenne</groupId> - <artifactId>cayenne-server</artifactId> - <version>${project.version}</version> - </dependency> - - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-dbcp2</artifactId> - </dependency> - - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - - <!-- Test dependencies --> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.cayenne.build-tools</groupId> - <artifactId>cayenne-test-utilities</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <plugins> - <!-- This ensures LICENSE and NOTICE inclusion in all jars --> - <plugin> - <artifactId>maven-remote-resources-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>process</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> -</project> \ No newline at end of file diff --git a/cayenne-dbcp2/src/main/java/org/apache/cayenne/configuration/server/DBCPDataSourceFactory.java b/cayenne-dbcp2/src/main/java/org/apache/cayenne/configuration/server/DBCPDataSourceFactory.java deleted file mode 100644 index bec7404b3..000000000 --- a/cayenne-dbcp2/src/main/java/org/apache/cayenne/configuration/server/DBCPDataSourceFactory.java +++ /dev/null @@ -1,83 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ -package org.apache.cayenne.configuration.server; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.sql.DataSource; - -import org.apache.cayenne.CayenneRuntimeException; -import org.apache.cayenne.configuration.DataNodeDescriptor; -import org.apache.cayenne.resource.Resource; -import org.apache.commons.dbcp2.BasicDataSourceFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A {@link DataSourceFactory} based on DBCP2 connection pool library. - * @deprecated since 4.1 - */ -@Deprecated -public class DBCPDataSourceFactory implements DataSourceFactory { - - private static final String DBCP2_PROPERTIES = "dbcp2.properties"; - - private static final Logger logger = LoggerFactory.getLogger(DBCPDataSourceFactory.class); - - @Override - public DataSource getDataSource(DataNodeDescriptor nodeDescriptor) throws Exception { - - String location = nodeDescriptor.getParameters(); - if (location == null) { - logger.debug("No explicit DBCP2 config location, will use default location: " + DBCP2_PROPERTIES); - location = DBCP2_PROPERTIES; - } - - Resource baseConfiguration = nodeDescriptor.getConfigurationSource(); - if (baseConfiguration == null) { - throw new CayenneRuntimeException("Null 'configurationSource' for nodeDescriptor '%s'", - nodeDescriptor.getName()); - } - - Resource dbcp2Configuration = baseConfiguration.getRelativeResource(location); - if (dbcp2Configuration == null) { - throw new CayenneRuntimeException("Missing DBCP2 configuration '%s' for nodeDescriptor '%s'", location, - nodeDescriptor.getName()); - } - - Properties properties = getProperties(dbcp2Configuration); - if (logger.isDebugEnabled()) { - logger.debug("DBCP2 Properties: " + properties); - } - - return BasicDataSourceFactory.createDataSource(properties); - } - - private Properties getProperties(Resource dbcp2Configuration) throws IOException { - Properties properties = new Properties(); - - try (InputStream in = dbcp2Configuration.getURL().openStream();) { - properties.load(in); - } - - return properties; - } -} diff --git a/cayenne-dbcp2/src/test/java/org/apache/cayenne/configuration/server/DBCP2DataSourceFactoryTest.java b/cayenne-dbcp2/src/test/java/org/apache/cayenne/configuration/server/DBCP2DataSourceFactoryTest.java deleted file mode 100644 index d1f53b248..000000000 --- a/cayenne-dbcp2/src/test/java/org/apache/cayenne/configuration/server/DBCP2DataSourceFactoryTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - ****************************************************************/ - -package org.apache.cayenne.configuration.server; - -import org.apache.cayenne.configuration.DataNodeDescriptor; -import org.apache.cayenne.resource.URLResource; -import org.apache.commons.dbcp2.BasicDataSource; -import org.junit.Test; - -import javax.sql.DataSource; -import java.io.IOException; -import java.net.URL; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class DBCP2DataSourceFactoryTest { - - @Test - public void testGetDataSource() throws Exception { - - String baseUrl = getClass().getPackage().getName().replace('.', '/'); - URL url = getClass().getClassLoader().getResource(baseUrl + "/"); - assertNotNull(url); - - DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor(); - nodeDescriptor.setConfigurationSource(new URLResource(url)); - nodeDescriptor.setParameters("testDBCP2.properties"); - - DBCPDataSourceFactory factory = new DBCPDataSourceFactory(); - DataSource dataSource = factory.getDataSource(nodeDescriptor); - assertNotNull(dataSource); - - assertTrue(dataSource instanceof BasicDataSource); - try (BasicDataSource basicDataSource = (BasicDataSource) dataSource;) { - assertEquals("com.example.jdbc.Driver", basicDataSource.getDriverClassName()); - assertEquals("jdbc:somedb://localhost/cayenne", basicDataSource.getUrl()); - assertEquals("john", basicDataSource.getUsername()); - assertEquals("secret", basicDataSource.getPassword()); - assertEquals(20, basicDataSource.getMaxTotal()); - assertEquals(5, basicDataSource.getMinIdle()); - assertEquals(8, basicDataSource.getMaxIdle()); - assertEquals(10000, basicDataSource.getMaxWaitMillis()); - assertEquals("select 1 from xyz;", basicDataSource.getValidationQuery()); - } - } - - @Test - public void testGetDataSource_InvalidLocation() throws Exception { - - String baseUrl = getClass().getPackage().getName().replace('.', '/'); - URL url = getClass().getClassLoader().getResource(baseUrl + "/"); - assertNotNull(url); - - DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor(); - nodeDescriptor.setConfigurationSource(new URLResource(url)); - nodeDescriptor.setParameters("testDBCP2.properties.nosuchfile"); - - DBCPDataSourceFactory factory = new DBCPDataSourceFactory(); - - try { - factory.getDataSource(nodeDescriptor); - fail("didn't throw on absent config file"); - } catch (IOException ex) { - // expected - } - } - -} diff --git a/cayenne-dbcp2/src/test/resources/org/apache/cayenne/configuration/server/testDBCP2.properties b/cayenne-dbcp2/src/test/resources/org/apache/cayenne/configuration/server/testDBCP2.properties deleted file mode 100644 index a586c5cab..000000000 --- a/cayenne-dbcp2/src/test/resources/org/apache/cayenne/configuration/server/testDBCP2.properties +++ /dev/null @@ -1,24 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -driverClassName=com.example.jdbc.Driver -url=jdbc:somedb://localhost/cayenne -username=john -password=secret -maxTotal=20 -minIdle=5 -maxIdle=8 -maxWaitMillis=10000 -validationQuery=select 1 from xyz; \ No newline at end of file