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

Optimize the message of DatabaseServerInfo #28428

Merged
merged 4 commits into from
Sep 15, 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 @@ -31,14 +31,14 @@
@Getter
public final class DatabaseServerInfo {

private final String databaseName;
private final String databaseType;

private final String databaseVersion;

public DatabaseServerInfo(final DataSource dataSource) {
try (Connection connection = dataSource.getConnection()) {
DatabaseMetaData databaseMetaData = connection.getMetaData();
databaseName = databaseMetaData.getDatabaseProductName();
databaseType = databaseMetaData.getDatabaseProductName();
databaseVersion = databaseMetaData.getDatabaseProductVersion();
} catch (final SQLException ex) {
throw new DatabaseServerLoadingServerException(ex);
Expand All @@ -47,6 +47,6 @@ public DatabaseServerInfo(final DataSource dataSource) {

@Override
public String toString() {
return String.format("Database name is `%s`, version is `%s`", databaseName, databaseVersion);
return String.format("Database type is `%s`, version is `%s`", databaseType, databaseVersion);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ void assertToString() throws SQLException {
when(databaseMetaData.getDatabaseProductName()).thenReturn("fixtureDB");
when(databaseMetaData.getDatabaseProductVersion()).thenReturn("1.0.0");
when(dataSource.getConnection().getMetaData()).thenReturn(databaseMetaData);
assertThat(new DatabaseServerInfo(dataSource).toString(), is("Database name is `fixtureDB`, version is `1.0.0`"));
assertThat(new DatabaseServerInfo(dataSource).toString(), is("Database type is `fixtureDB`, version is `1.0.0`"));
}
}