From 362e4fb287ec137da538733de1f9ffe0f51f9d19 Mon Sep 17 00:00:00 2001 From: Radek Felcman Date: Wed, 22 Nov 2023 20:23:39 +0100 Subject: [PATCH] Oracle extension test build fixes Signed-off-by: Radek Felcman --- .../framework/oracle/SessionExchanger.java | 29 +++++++------------ .../rcm/jms/JMSSetupHelper.java | 16 ++-------- .../ProxyAuthenticationTestSuite.java | 29 +++++++------------ .../oci/ProxyTestHelper.java | 3 +- 4 files changed, 24 insertions(+), 53 deletions(-) diff --git a/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/framework/oracle/SessionExchanger.java b/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/framework/oracle/SessionExchanger.java index c5c88c46327..bc6da06fa96 100644 --- a/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/framework/oracle/SessionExchanger.java +++ b/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/framework/oracle/SessionExchanger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -19,7 +19,8 @@ import java.util.Map; import java.util.Properties; -import oracle.jdbc.pool.OracleDataSource; +import oracle.ucp.jdbc.PoolDataSource; +import oracle.ucp.jdbc.PoolDataSourceFactory; import org.eclipse.persistence.sessions.JNDIConnector; import org.eclipse.persistence.sessions.DatabaseLogin; @@ -52,7 +53,7 @@ public class SessionExchanger { DatabaseSession originalSession; DatabaseSession newSession; boolean hasLoggedOutOriginalSession; - OracleDataSource dataSource; + PoolDataSource dataSource; // pass the original session and params for the new one: // useDatabaseSession - "true" means new session is DatabaseSession; "false" - ServerSession; @@ -157,13 +158,7 @@ void clearNewSession() { } finally { newSession = null; if(dataSource != null) { - try { - dataSource.close(); - } catch (SQLException ex) { - throw new TestProblemException("Exception thrown while closing OracleDataSource:\n", ex); - } finally { - dataSource = null; - } + dataSource = null; } } } @@ -190,21 +185,19 @@ void setProperties(Properties loginProperties, Map sessionProperties) { // create a data source using the supplied connection string void createDataSource(String connectionString, int minConnections, int maxConnections) { try { - dataSource = new OracleDataSource(); + dataSource = PoolDataSourceFactory.getPoolDataSource(); + dataSource.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); Properties props = new Properties(); if(minConnections >= 0) { - props.setProperty("MinLimit", Integer.toString(minConnections)); - props.setProperty("InitialLimit", Integer.toString(minConnections)); + dataSource.setMinPoolSize(minConnections); + dataSource.setInitialPoolSize(minConnections); } if(maxConnections >= 0) { - props.setProperty("MaxLimit", Integer.toString(maxConnections)); - } - if(!props.isEmpty()) { - dataSource.setConnectionCacheProperties(props); + dataSource.setMaxPoolSize(maxConnections); } + dataSource.setURL(connectionString); } catch (SQLException ex) { throw new TestProblemException("Failed to create OracleDataSource with " + connectionString + ".\n", ex); } - dataSource.setURL(connectionString); } } diff --git a/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/distributedservers/rcm/jms/JMSSetupHelper.java b/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/distributedservers/rcm/jms/JMSSetupHelper.java index e036a259dde..3d872755589 100644 --- a/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/distributedservers/rcm/jms/JMSSetupHelper.java +++ b/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/distributedservers/rcm/jms/JMSSetupHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -101,13 +101,6 @@ protected void updateDbSettings() { protected Object[] internalCreateFactory() throws Exception { updateDbSettings(); - if (oracleDataSource != null) { - try { - oracleDataSource.close(); - } catch (java.sql.SQLException ex) { - // ignore - } - } createInDb(); oracleDataSource = new oracle.jdbc.pool.OracleDataSource(); @@ -139,12 +132,7 @@ protected void internalDestroyFactory() throws Exception { destroyInDb(); } catch (java.sql.SQLException ex) { } finally { - try { - oracleDataSource.close(); - } catch (java.sql.SQLException ex) { - } finally { - oracleDataSource = null; - } + oracleDataSource = null; } } diff --git a/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/jpa/proxyauthentication/ProxyAuthenticationTestSuite.java b/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/jpa/proxyauthentication/ProxyAuthenticationTestSuite.java index ac83ec529e2..c1b70e94e75 100644 --- a/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/jpa/proxyauthentication/ProxyAuthenticationTestSuite.java +++ b/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/jpa/proxyauthentication/ProxyAuthenticationTestSuite.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -27,7 +27,8 @@ import junit.framework.TestSuite; import oracle.jdbc.OracleConnection; -import oracle.jdbc.pool.OracleDataSource; +import oracle.ucp.jdbc.PoolDataSource; +import oracle.ucp.jdbc.PoolDataSourceFactory; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.eclipse.persistence.config.ExclusiveConnectionMode; @@ -58,7 +59,7 @@ public class ProxyAuthenticationTestSuite extends JUnitTestCase { // indicates whether EclusiveIsolatedClientSession should be used. boolean shoulUseExclusiveIsolatedSession; // datasource created in external connection pooling case. - OracleDataSource dataSource; + PoolDataSource dataSource; // writeUser is set by an event risen by ModifyQuery. private static String writeUser; @@ -160,27 +161,17 @@ public void tearDown() { // the test has customized the factory - it should be closed. closeEntityManagerFactory(); // close the data source if it has been created - if(dataSource != null) { - try { - dataSource.close(); - } catch (SQLException ex) { - throw new RuntimeException("Exception thrown while closing OracleDataSource:\n", ex); - } finally { - dataSource = null; - } - } + dataSource = null; } // create a data source using the supplied connection string void createDataSource(String connectionString) { try { - dataSource = new OracleDataSource(); - Properties props = new Properties(); - // the pool using just one connection would cause deadlock in case of a connection leak - good for the test. - props.setProperty("MinLimit", "1"); - props.setProperty("MaxLimit", "1"); - props.setProperty("InitialLimit", "1"); - dataSource.setConnectionCacheProperties(props); + dataSource = PoolDataSourceFactory.getPoolDataSource(); + dataSource.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); + dataSource.setMinPoolSize(1); + dataSource.setMaxPoolSize(1); + dataSource.setInitialPoolSize(1); dataSource.setURL(connectionString); } catch (SQLException ex) { throw new RuntimeException("Failed to create OracleDataSource with " + connectionString + ".\n", ex); diff --git a/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/proxyauthentication/oci/ProxyTestHelper.java b/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/proxyauthentication/oci/ProxyTestHelper.java index 273d8222ca9..5708dadbc35 100644 --- a/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/proxyauthentication/oci/ProxyTestHelper.java +++ b/foundation/eclipselink.extension.oracle.test/src/org/eclipse/persistence/testing/tests/proxyauthentication/oci/ProxyTestHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at @@ -49,7 +49,6 @@ public void setProxyConnectorIntoLogin(DatabaseLogin login, Session session) thr public void close() throws SQLException { if (oracleDataSource != null) { - oracleDataSource.close(); oracleDataSource = null; } }