1111 * Header, with the fields enclosed by brackets [] replaced by your own identifying
1212 * information: "Portions Copyright [year] [name of copyright owner]".
1313 *
14- * Copyright 2024 3A Systems, LLC.
14+ * Copyright 2024-2025 3A Systems, LLC.
1515 */
1616package org .opends .server .backends .jdbc ;
1717
2727public class CachedConnection implements Connection {
2828 final Connection parent ;
2929
30- static LoadingCache <String , BlockingQueue <Connection >> cached = CacheBuilder .newBuilder ()
30+ static LoadingCache <String , BlockingQueue <CachedConnection >> cached = CacheBuilder .newBuilder ()
3131 .expireAfterAccess (Long .parseLong (System .getProperty ("org.openidentityplatform.opendj.jdbc.ttl" ,"15000" )), TimeUnit .MILLISECONDS )
32- .removalListener (new RemovalListener <String , BlockingQueue <Connection >>() {
32+ .removalListener (new RemovalListener <String , BlockingQueue <CachedConnection >>() {
3333 @ Override
34- public void onRemoval (RemovalNotification <String , BlockingQueue <Connection >> notification ) {
34+ public void onRemoval (RemovalNotification <String , BlockingQueue <CachedConnection >> notification ) {
3535 assert notification .getValue () != null ;
36- for (Connection con : notification .getValue ()) {
36+ for (CachedConnection con : notification .getValue ()) {
3737 try {
3838 if (!con .isClosed ()) {
39- con .close ();
39+ con .parent . close ();
4040 }
4141 } catch (SQLException e ) {
4242 }
4343 }
4444 }
4545 })
46- .build (new CacheLoader <String , BlockingQueue <Connection >>() {
46+ .build (new CacheLoader <String , BlockingQueue <CachedConnection >>() {
4747 @ Override
48- public BlockingQueue <Connection > load (String connectionString ) throws Exception {
48+ public BlockingQueue <CachedConnection > load (String connectionString ) throws Exception {
4949 return new LinkedBlockingQueue <>();
5050 }
5151 });
@@ -61,11 +61,11 @@ static Connection getConnection(String connectionString) throws Exception {
6161 }
6262
6363 static Connection getConnection (String connectionString , final int waitTime ) throws Exception {
64- Connection con =cached .get (connectionString ).poll (waitTime ,TimeUnit .MILLISECONDS );
64+ CachedConnection con =cached .get (connectionString ).poll (waitTime ,TimeUnit .MILLISECONDS );
6565 while (con !=null ) {
6666 if (!con .isValid (0 )) {
6767 try {
68- con .close ();
68+ con .parent . close ();
6969 } catch (SQLException e ) {
7070 con =null ;
7171 }
@@ -75,10 +75,10 @@ static Connection getConnection(String connectionString, final int waitTime) thr
7575 }
7676 }
7777 try {
78- con = DriverManager .getConnection (connectionString );
79- con .setAutoCommit (false );
80- con .setTransactionIsolation (TRANSACTION_READ_COMMITTED );
81- return new CachedConnection (connectionString , con );
78+ final Connection conNew = DriverManager .getConnection (connectionString );
79+ conNew .setAutoCommit (false );
80+ conNew .setTransactionIsolation (TRANSACTION_READ_COMMITTED );
81+ return new CachedConnection (connectionString , conNew );
8282 }catch (SQLException e ) { //max_connection server error: try recursion for reuse connection
8383 return getConnection (connectionString ,(waitTime ==0 )?1 :waitTime *2 );
8484 }
0 commit comments