Skip to content

Commit 540471a

Browse files
committed
[#2478] Terrible error reporting when JDBC scheme is not recognized
1 parent f2e7ec0 commit 540471a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/DefaultSqlClientPoolConfiguration.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Map;
1212
import java.util.concurrent.TimeUnit;
1313

14+
import org.hibernate.internal.util.StringHelper;
1415
import org.hibernate.reactive.logging.impl.Log;
1516
import org.hibernate.reactive.logging.impl.LoggerFactory;
1617
import org.hibernate.reactive.provider.Settings;
@@ -95,7 +96,7 @@ public SqlConnectOptions connectOptions(URI uri) {
9596
? oraclePath( uri )
9697
: uri.getPath();
9798

98-
String database = path.length() > 0
99+
String database = path != null && !path.isEmpty()
99100
? path.substring( 1 )
100101
: "";
101102

@@ -105,9 +106,6 @@ public SqlConnectOptions connectOptions(URI uri) {
105106
database = database.substring( 0, database.indexOf( ':' ) );
106107
}
107108

108-
String host = findHost( uri, scheme );
109-
int port = findPort( uri, scheme );
110-
111109
//see if the credentials were specified via properties
112110
String username = user;
113111
String password = pass;
@@ -183,6 +181,13 @@ else if ( param.startsWith( "database=" ) ) {
183181
}
184182
}
185183

184+
if ( StringHelper.isEmpty( database ) ) {
185+
throw LOG.couldNotDetermineDialectFromConnectionURI( uri.toString() );
186+
}
187+
188+
String host = findHost( uri, scheme );
189+
int port = findPort( uri, scheme );
190+
186191
if ( username == null ) {
187192
throw LOG.databaseUsernameNotSpecified();
188193
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static java.lang.Integer.parseInt;
3030
import static java.util.Objects.requireNonNullElse;
3131
import static java.util.function.Function.identity;
32+
import static org.hibernate.cfg.JdbcSettings.ALLOW_METADATA_ON_BOOT;
3233
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
3334

3435
/**
@@ -84,7 +85,7 @@ protected JdbcEnvironmentImpl getJdbcEnvironmentUsingJdbcMetadata(
8485
Integer explicitDatabaseMajorVersion,
8586
Integer explicitDatabaseMinorVersion,
8687
String explicitDatabaseVersion) {
87-
try {
88+
if ( configurationValues.containsKey( ALLOW_METADATA_ON_BOOT ) ) {
8889
final Dialect dialect = new DialectBuilder( configurationValues, registry )
8990
.build(
9091
dialectFactory,
@@ -97,7 +98,7 @@ protected JdbcEnvironmentImpl getJdbcEnvironmentUsingJdbcMetadata(
9798
);
9899
return new JdbcEnvironmentImpl( registry, dialect );
99100
}
100-
catch (RuntimeException e) {
101+
else {
101102
return getJdbcEnvironmentWithDefaults( configurationValues, registry, dialectFactory );
102103
}
103104
}

0 commit comments

Comments
 (0)