1
1
/*
2
- * Copyright (c) 2015, 2020 , Oracle and/or its affiliates.
2
+ * Copyright (c) 2015, 2021 , Oracle and/or its affiliates.
3
3
*
4
4
* This program is free software; you can redistribute it and/or modify it under
5
5
* the terms of the GNU General Public License, version 2.0, as published by the
54
54
public abstract class MultiHostConnectionProxy implements InvocationHandler {
55
55
private static final String METHOD_GET_MULTI_HOST_SAFE_PROXY = "getMultiHostSafeProxy" ;
56
56
private static final String METHOD_EQUALS = "equals" ;
57
- private static final String METHOD_HASH_CODE = "hashCode" ;
58
57
private static final String METHOD_CLOSE = "close" ;
59
58
private static final String METHOD_ABORT_INTERNAL = "abortInternal" ;
60
59
private static final String METHOD_ABORT = "abort" ;
@@ -466,7 +465,7 @@ void syncSessionState(JdbcConnection source, JdbcConnection target, boolean read
466
465
* if an error occurs
467
466
*/
468
467
@ Override
469
- public synchronized Object invoke (Object proxy , Method method , Object [] args ) throws Throwable {
468
+ public Object invoke (Object proxy , Method method , Object [] args ) throws Throwable {
470
469
String methodName = method .getName ();
471
470
472
471
if (METHOD_GET_MULTI_HOST_SAFE_PROXY .equals (methodName )) {
@@ -478,50 +477,53 @@ public synchronized Object invoke(Object proxy, Method method, Object[] args) th
478
477
return args [0 ].equals (this );
479
478
}
480
479
481
- if (METHOD_HASH_CODE .equals (methodName )) {
482
- return this .hashCode ();
480
+ // Execute remaining ubiquitous methods right away.
481
+ if (method .getDeclaringClass ().equals (Object .class )) {
482
+ return method .invoke (this , args );
483
483
}
484
484
485
- if (METHOD_CLOSE .equals (methodName )) {
486
- doClose ();
487
- this .isClosed = true ;
488
- this .closedReason = "Connection explicitly closed." ;
489
- this .closedExplicitly = true ;
490
- return null ;
491
- }
485
+ synchronized (this ) {
486
+ if (METHOD_CLOSE .equals (methodName )) {
487
+ doClose ();
488
+ this .isClosed = true ;
489
+ this .closedReason = "Connection explicitly closed." ;
490
+ this .closedExplicitly = true ;
491
+ return null ;
492
+ }
492
493
493
- if (METHOD_ABORT_INTERNAL .equals (methodName )) {
494
- doAbortInternal ();
495
- this .currentConnection .abortInternal ();
496
- this .isClosed = true ;
497
- this .closedReason = "Connection explicitly closed." ;
498
- return null ;
499
- }
494
+ if (METHOD_ABORT_INTERNAL .equals (methodName )) {
495
+ doAbortInternal ();
496
+ this .currentConnection .abortInternal ();
497
+ this .isClosed = true ;
498
+ this .closedReason = "Connection explicitly closed." ;
499
+ return null ;
500
+ }
500
501
501
- if (METHOD_ABORT .equals (methodName ) && args .length == 1 ) {
502
- doAbort ((Executor ) args [0 ]);
503
- this .isClosed = true ;
504
- this .closedReason = "Connection explicitly closed." ;
505
- return null ;
506
- }
502
+ if (METHOD_ABORT .equals (methodName ) && args .length == 1 ) {
503
+ doAbort ((Executor ) args [0 ]);
504
+ this .isClosed = true ;
505
+ this .closedReason = "Connection explicitly closed." ;
506
+ return null ;
507
+ }
507
508
508
- if (METHOD_IS_CLOSED .equals (methodName )) {
509
- return this .isClosed ;
510
- }
509
+ if (METHOD_IS_CLOSED .equals (methodName )) {
510
+ return this .isClosed ;
511
+ }
511
512
512
- try {
513
- return invokeMore (proxy , method , args );
514
- } catch (InvocationTargetException e ) {
515
- throw e .getCause () != null ? e .getCause () : e ;
516
- } catch (Exception e ) {
517
- // Check if the captured exception must be wrapped by an unchecked exception.
518
- Class <?>[] declaredException = method .getExceptionTypes ();
519
- for (Class <?> declEx : declaredException ) {
520
- if (declEx .isAssignableFrom (e .getClass ())) {
521
- throw e ;
513
+ try {
514
+ return invokeMore (proxy , method , args );
515
+ } catch (InvocationTargetException e ) {
516
+ throw e .getCause () != null ? e .getCause () : e ;
517
+ } catch (Exception e ) {
518
+ // Check if the captured exception must be wrapped by an unchecked exception.
519
+ Class <?>[] declaredException = method .getExceptionTypes ();
520
+ for (Class <?> declEx : declaredException ) {
521
+ if (declEx .isAssignableFrom (e .getClass ())) {
522
+ throw e ;
523
+ }
522
524
}
525
+ throw new IllegalStateException (e .getMessage (), e );
523
526
}
524
- throw new IllegalStateException (e .getMessage (), e );
525
527
}
526
528
}
527
529
0 commit comments