Skip to content
Merged
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 @@ -4,14 +4,10 @@
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.dropwizard.util.Duration;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import jakarta.validation.constraints.NotNull;
import lombok.*;
import lombok.extern.jackson.Jacksonized;
import lombok.extern.slf4j.Slf4j;
import org.jooq.DSLContext;

/**
* Connection properties for a SQL database.
Expand All @@ -31,8 +27,18 @@ public class DatabaseConnectionConfig {
/**
* SQL vendor specific dialect used to transform queries to SQL
*/
@NotNull
private Dialect dialect;

/**
* Name of the column which is shared among the table and all aggregations are grouped by.
*/
@Builder.Default
@NotNull
private String primaryColumn = DEFAULT_PRIMARY_COLUMN;

private String propertiesFile;

/**
* Username used to connect to the database.
*/
Expand All @@ -52,18 +58,22 @@ public class DatabaseConnectionConfig {

private Duration connectivityTimeout;

/**
* Name of the column which is shared among the table and all aggregations are grouped by.
*/
@Builder.Default
private String primaryColumn = DEFAULT_PRIMARY_COLUMN;


public HikariDataSource createDataSource(HealthCheckRegistry healthCheckRegistry) {
HikariConfig hikariConfig = new HikariConfig();
hikariConfig.setJdbcUrl(getJdbcConnectionUrl());
hikariConfig.setUsername(getDatabaseUsername());
hikariConfig.setPassword(getDatabasePassword());

// If propertiesFile is provided start with that and overwrite with internal settings. Allows us to use both.
HikariConfig hikariConfig = propertiesFile != null ? new HikariConfig(propertiesFile) : new HikariConfig();

if (getJdbcConnectionUrl() != null) {
hikariConfig.setJdbcUrl(getJdbcConnectionUrl());
}

if (getDatabaseUsername() != null) {
hikariConfig.setUsername(getDatabaseUsername());
}
if (getDatabasePassword() != null) {
hikariConfig.setPassword(getDatabasePassword());
}

if (healthCheckRegistry != null) {
hikariConfig.setHealthCheckRegistry(healthCheckRegistry);
Expand Down
Loading