Skip to content

Commit 02ceb9b

Browse files
committed
[#1602] Simplify the DialectResolutionInfo creaction
I don't think we need all those try-catch. I think we can rely on the fact that the method will return a failed stage.
1 parent 44c15e7 commit 02ceb9b

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/provider/service/NoJdbcEnvironmentInitiator.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
3131
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
32-
import static org.hibernate.reactive.util.impl.CompletionStages.failedFuture;
3332

3433
/**
3534
* A Hibernate {@link StandardServiceInitiator service initiator} that
@@ -101,22 +100,22 @@ private DialectResolutionInfo dialectResolutionInfo() {
101100
}
102101

103102
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+
} );
120119
}
121120

122121
private static CompletionStage<ReactiveDialectResolutionInfo> resolutionInfoStage(ReactiveConnection connection, DatabaseMetadata databaseMetadata) {

0 commit comments

Comments
 (0)