Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve JDBC driver error message in Agroal processor #30751

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.stream.Collectors;

import javax.enterprise.inject.Default;
import javax.inject.Singleton;
Expand Down Expand Up @@ -344,14 +345,13 @@ private String resolveDriver(String dataSourceName, String dbKind,
}
}

throw new ConfigurationException("Unable to find a JDBC driver corresponding to the database kind '"
+ dbKind + "' for the "
+ (DataSourceUtil.isDefault(dataSourceName) ? "default datasource"
: "datasource '" + dataSourceName + "'")
+ ". Either provide a suitable JDBC driver extension, define the driver manually, or disable the JDBC datasource by adding "
+ (DataSourceUtil.isDefault(dataSourceName) ? "'quarkus.datasource.jdbc=false'"
: "'quarkus.datasource." + dataSourceName + ".jdbc=false'")
+ " to your configuration if you don't need it.");
throw new ConfigurationException(String.format(
"Unable to find a JDBC driver corresponding to the database kind '%s' for the %s (available: '%s'). "
gastaldi marked this conversation as resolved.
Show resolved Hide resolved
+ "Check if it's a typo, otherwise provide a suitable JDBC driver extension, define the driver manually,"
+ " or disable the JDBC datasource by adding '%s=false' to your configuration if you don't need it.",
dbKind, DataSourceUtil.isDefault(dataSourceName) ? "default datasource" : "datasource '" + dataSourceName + "'",
jdbcDriverBuildItems.stream().map(JdbcDriverBuildItem::getDbKind).collect(Collectors.joining("','")),
DataSourceUtil.dataSourcePropertyKey(dataSourceName, "jdbc")));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,10 @@ public AgroalDataSource doCreateDataSource(String dataSourceName) {

DataSourceSupport.Entry matchingSupportEntry = dataSourceSupport.entries.get(dataSourceName);
if (!dataSourceJdbcRuntimeConfig.url.isPresent()) {
String errorMessage;
// we don't have any URL configuration so using a standard message
if (DataSourceUtil.isDefault(dataSourceName)) {
errorMessage = "quarkus.datasource.jdbc.url has not been defined";
} else {
errorMessage = "quarkus.datasource." + dataSourceName + ".jdbc.url has not been defined";
}
//this is not an error situation, because we want to allow the situation where a JDBC extension
//is installed but has not been configured
return new UnconfiguredDataSource(errorMessage);
return new UnconfiguredDataSource(
DataSourceUtil.dataSourcePropertyKey(dataSourceName, "jdbc.url") + " has not been defined");
}

// we first make sure that all available JDBC drivers are loaded in the current TCCL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public static boolean hasDefault(Collection<String> dataSourceNames) {
return dataSourceNames.contains(DEFAULT_DATASOURCE_NAME);
}

public static String dataSourcePropertyKey(String datasourceName, String radical) {
if (datasourceName == null || DataSourceUtil.isDefault(datasourceName)) {
return "quarkus.datasource." + radical;
} else {
return "quarkus.datasource.\"" + datasourceName + "\"." + radical;
}
}

public static List<String> dataSourcePropertyKeys(String datasourceName, String radical) {
if (datasourceName == null || DataSourceUtil.isDefault(datasourceName)) {
return List.of("quarkus.datasource." + radical);
Expand Down