Skip to content

Commit

Permalink
Add protocol support for R2DBC configuration
Browse files Browse the repository at this point in the history
#deploy-levende-arbeidsforhold-ansettelse

Introduced protocol field in R2DBC configuration to enhance flexibility. Adjusted configurations to conditionally include host and protocol options if they are present. Updated application configuration files to use the new protocol setting.
  • Loading branch information
krharum committed Oct 21, 2024
1 parent fe10838 commit 636975b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.r2dbc.spi.ConnectionFactories;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.libs.reactivecore.config.CoreConfig;
import no.nav.testnav.libs.reactivesecurity.config.SecureOAuth2ServerToServerConfiguration;
import no.nav.testnav.libs.standalone.servletsecurity.config.InsecureJwtServerToServerConfiguration;
Expand All @@ -20,8 +21,11 @@
import static io.r2dbc.spi.ConnectionFactoryOptions.HOST;
import static io.r2dbc.spi.ConnectionFactoryOptions.PASSWORD;
import static io.r2dbc.spi.ConnectionFactoryOptions.PORT;
import static io.r2dbc.spi.ConnectionFactoryOptions.PROTOCOL;
import static io.r2dbc.spi.ConnectionFactoryOptions.USER;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

@Slf4j
@Configuration
@Import({
CoreConfig.class,
Expand All @@ -37,9 +41,12 @@ public class ApplicationConfig {
@Value("${config.r2dbc.driver}")
private String driver;

@Value("${config.r2dbc.host}")
@Value("${config.r2dbc.host:null}")
private String host;

@Value("${config.r2dbc.protocol:null}")
private String protocol;

@Value("${config.r2dbc.port}")
private int port;

Expand All @@ -56,14 +63,21 @@ public class ApplicationConfig {
@Bean
ConnectionFactory connectionFactory() {

return ConnectionFactories.get(ConnectionFactoryOptions.builder()
var factory = ConnectionFactoryOptions.builder()
.option(DRIVER, driver)
.option(HOST, host)
.option(PORT, port)
.option(USER, username)
.option(PASSWORD, password)
.option(DATABASE, database)
.build());
}
}
.option(DATABASE, database);

if (isNotBlank(host)) {
factory.option(HOST, host);
}
if (isNotBlank(protocol)) {
factory.option(PROTOCOL, protocol);
}

log.info("ConnectionFactory: {}", factory.build());
return ConnectionFactories.get(factory.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spring:
config:
r2dbc:
driver: h2
host: localhost
protocol: mem
port: 5432
database: testdb
username: sa
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

spring:
flyway:
url: jdbc:h2:mem:testdb
config:
r2dbc:
driver: h2
protocol: mem
port: 5432
database: testdb
username: sa
password:

0 comments on commit 636975b

Please sign in to comment.