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

DataSourceBuilder throws an UnsupportedDataSourcePropertyException when trying to derive a DataSource from an unknown DataSource type #27453

Closed
Closed
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 @@ -281,17 +281,22 @@ public String toString() {
}

Method findSetter(Class<?> type) {
return extracted("set", type);
return extracted("set", type, true);
}

Method findGetter(Class<?> type) {
return extracted("get", type);
return extracted("get", type, false);
}

private Method extracted(String prefix, Class<?> type) {
private Method extracted(String prefix, Class<?> type, boolean hasParameter) {
for (String candidate : this.names) {
Method method = ReflectionUtils.findMethod(type, prefix + StringUtils.capitalize(candidate),
String.class);
Method method;
if (hasParameter) {
method = ReflectionUtils.findMethod(type, prefix + StringUtils.capitalize(candidate), String.class);
}
else {
method = ReflectionUtils.findMethod(type, prefix + StringUtils.capitalize(candidate));
}
if (method != null) {
return method;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,19 @@ void buildWhenDerivedFromExistingDatabaseWithTypeChange() {
assertThat(built.getUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
}

@Test // gh -27295
void buildWhenDerivedFromCustomTypeSpecifiedReturnsDataSource() {
CustomDataSource dataSource = new CustomDataSource();
dataSource.setUsername("test");
dataSource.setPassword("secret");
dataSource.setUrl("jdbc:postgresql://localhost:5432/postgres");
DataSourceBuilder<?> builder = DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class);
SimpleDriverDataSource testSource = (SimpleDriverDataSource) builder.build();
assertThat(testSource.getUsername()).isEqualTo("test");
assertThat(testSource.getUrl()).isEqualTo("jdbc:postgresql://localhost:5432/postgres");
assertThat(testSource.getPassword()).isEqualTo("secret");
}

final class HidePackagesClassLoader extends URLClassLoader {

private final String[] hiddenPackages;
Expand Down