Skip to content

Commit

Permalink
#2270 configuring host
Browse files Browse the repository at this point in the history
  • Loading branch information
DarioGii committed Dec 13, 2024
1 parent 69604ea commit 5615b37
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@Configuration
public class DatabaseConfig {

public static final String DOCKER_HOST = "://db:";
public static final String LOCALHOST = "://localhost:";
private final ApplicationProperties applicationProperties;

public DatabaseConfig(@Autowired ApplicationProperties applicationProperties) {
Expand All @@ -27,16 +29,20 @@ public Connection connection() throws SQLException {
applicationProperties.getSystem().getDatasource();

DataSourceBuilder<?> dataSourceBuilder = DataSourceBuilder.create();
dataSourceBuilder.driverClassName("org.postgresql.Driver");
// todo: revert back to ->
// dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriver()));
dataSourceBuilder.url(datasource.getUrl());
dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriver()));
dataSourceBuilder.url(getUrlForProfile(datasource));
dataSourceBuilder.username(datasource.getUsername());
dataSourceBuilder.password(datasource.getPassword());

return dataSourceBuilder.build().getConnection();
}

private String getUrlForProfile(ApplicationProperties.Datasource datasource) {
return applicationProperties.getSystem().getProfilesActive().equals("default")
? datasource.getUrl().replace(DOCKER_HOST, LOCALHOST)
: datasource.getUrl();
}

private String getDriverClassName(ApplicationProperties.Driver driverName) {
switch (driverName) {
case ORACLE -> {
Expand Down

0 comments on commit 5615b37

Please sign in to comment.