|
29 | 29 |
|
30 | 30 | import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
|
31 | 31 | import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
|
32 |
| -import static org.hibernate.reactive.util.impl.CompletionStages.failedFuture; |
33 | 32 |
|
34 | 33 | /**
|
35 | 34 | * A Hibernate {@link StandardServiceInitiator service initiator} that
|
@@ -101,22 +100,22 @@ private DialectResolutionInfo dialectResolutionInfo() {
|
101 | 100 | }
|
102 | 101 |
|
103 | 102 | private static CompletionStage<ReactiveDialectResolutionInfo> buildResolutionInfo(ReactiveConnection connection) {
|
104 |
| - try { |
105 |
| - final DatabaseMetadata databaseMetadata = connection.getDatabaseMetadata(); |
106 |
| - return resolutionInfoStage( connection, databaseMetadata ) |
107 |
| - .thenCompose( info -> connection.close().thenApply( v -> info ) ); |
108 |
| - } |
109 |
| - catch (Throwable t) { |
110 |
| - try { |
111 |
| - return connection.close() |
112 |
| - .handle( CompletionStages::handle ) |
113 |
| - // Ignore errors when closing the connection |
114 |
| - .thenCompose( handled -> failedFuture( t ) ); |
115 |
| - } |
116 |
| - catch (Throwable onClose) { |
117 |
| - return failedFuture( t ); |
118 |
| - } |
119 |
| - } |
| 103 | + final DatabaseMetadata databaseMetadata = connection.getDatabaseMetadata(); |
| 104 | + return resolutionInfoStage( connection, databaseMetadata ) |
| 105 | + .handle( CompletionStages::handle ) |
| 106 | + .thenCompose( handled -> { |
| 107 | + if ( handled.hasFailed() ) { |
| 108 | + // Something has already gone wrong: try to close the connection |
| 109 | + // and returns the original failure |
| 110 | + return connection.close() |
| 111 | + .handle( (unused, throwable) -> handled.getResultAsCompletionStage() ) |
| 112 | + .thenCompose( identity() ); |
| 113 | + } |
| 114 | + else { |
| 115 | + return connection.close() |
| 116 | + .thenCompose( v -> handled.getResultAsCompletionStage() ); |
| 117 | + } |
| 118 | + } ); |
120 | 119 | }
|
121 | 120 |
|
122 | 121 | private static CompletionStage<ReactiveDialectResolutionInfo> resolutionInfoStage(ReactiveConnection connection, DatabaseMetadata databaseMetadata) {
|
|
0 commit comments