Skip to content

Commit

Permalink
Oracle extension test build fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Radek Felcman <[email protected]>
  • Loading branch information
rfelcman committed Nov 22, 2023
1 parent b4e15e3 commit b648a4a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -49,7 +49,6 @@ public void setProxyConnectorIntoLogin(DatabaseLogin login, Session session) thr

public void close() throws SQLException {
if (oracleDataSource != null) {
oracleDataSource.close();
oracleDataSource = null;
}
}
Expand Down

0 comments on commit b648a4a

Please sign in to comment.