Support r2dbc

Adds r2dbc properties for mysql, postgres, sqlserver, oracle, and db2
bindings. This allow bindings to be used with reactive drivers.

Signed-off-by: Emily Casey <ecasey@pivotal.io>
This commit is contained in:
Emily Casey
2020-05-28 18:24:33 -04:00
parent 05596d901e
commit 8595e847a3
11 changed files with 95 additions and 14 deletions

View File

@@ -45,12 +45,19 @@ public final class Db2BindingsPropertiesProcessor implements BindingsPropertiesP
bindings.filterBindings(KIND).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
//jdbc properties
map.from("password").to("spring.datasource.password");
map.from("host", "port", "database").to("spring.datasource.url",
(host, port, database) -> String.format("jdbc:db2://%s:%s/%s", host, port, database));
map.from("username").to("spring.datasource.username");
properties.put("spring.datasource.driver-class-name", "com.ibm.db2.jcc.DB2Driver");
//r2dbc properties
map.from("password").to("spring.r2dbc.password");
map.from("host", "port", "database").to("spring.r2dbc.url",
(host, port, database) -> String.format("r2dbc:db2://%s:%s/%s", host, port, database));
map.from("username").to("spring.r2dbc.username");
});
}

View File

@@ -45,14 +45,12 @@ public final class MySqlBindingsPropertiesProcessor implements BindingsPropertie
bindings.filterBindings(KIND).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
//jdbc properties
map.from("password").to("spring.datasource.password");
map.from("host", "port", "database").to("spring.datasource.url",
(host, port, database) -> String.format("jdbc:mysql://%s:%s/%s", host, port, database));
map.from("username").to("spring.datasource.username");
Map<String, String> secret = binding.getSecret();
try {
Class.forName("org.mariadb.jdbc.Driver", false, getClass().getClassLoader());
properties.put("spring.datasource.driver-class-name", "org.mariadb.jdbc.Driver");
@@ -63,6 +61,12 @@ public final class MySqlBindingsPropertiesProcessor implements BindingsPropertie
} catch (ClassNotFoundException ignored) {
}
}
//r2dbc properties
map.from("password").to("spring.r2dbc.password");
map.from("host", "port", "database").to("spring.r2dbc.url",
(host, port, database) -> String.format("r2dbc:mysql://%s:%s/%s", host, port, database));
map.from("username").to("spring.r2dbc.username");
});
}

View File

@@ -45,12 +45,19 @@ public final class OracleBindingsPropertiesProcessor implements BindingsProperti
bindings.filterBindings(KIND).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
//jdbc properties
map.from("password").to("spring.datasource.password");
map.from("host", "port", "database").to("spring.datasource.url",
(host, port, database) -> String.format("jdbc:oracle://%s:%s/%s", host, port, database));
map.from("username").to("spring.datasource.username");
properties.put("spring.datasource.driver-class-name", "oracle.jdbc.OracleDriver");
//r2dbc properties
map.from("password").to("spring.r2dbc.password");
map.from("host", "port", "database").to("spring.r2dbc.url",
(host, port, database) -> String.format("r2dbc:oracle://%s:%s/%s", host, port, database));
map.from("username").to("spring.r2dbc.username");
});
}

View File

@@ -45,12 +45,19 @@ public final class PostgreSqlBindingsPropertiesProcessor implements BindingsProp
bindings.filterBindings(KIND).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
//jdbc properties
map.from("password").to("spring.datasource.password");
map.from("host", "port", "database").to("spring.datasource.url",
(host, port, database) -> String.format("jdbc:postgres://%s:%s/%s", host, port, database));
map.from("username").to("spring.datasource.username");
properties.put("spring.datasource.driver-class-name", "org.postgresql.Driver");
//r2dbc properties
map.from("password").to("spring.r2dbc.password");
map.from("host", "port", "database").to("spring.r2dbc.url",
(host, port, database) -> String.format("r2dbc:postgres://%s:%s/%s", host, port, database));
map.from("username").to("spring.r2dbc.username");
});
}

View File

@@ -45,12 +45,19 @@ public final class SqlServerBindingsPropertiesProcessor implements BindingsPrope
bindings.filterBindings(KIND).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
//jdbc properties
map.from("password").to("spring.datasource.password");
map.from("host", "port", "database").to("spring.datasource.url",
(host, port, database) -> String.format("jdbc:sqlserver://%s:%s/%s", host, port, database));
map.from("username").to("spring.datasource.username");
properties.put("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
//r2dbc properties
map.from("password").to("spring.r2dbc.password");
map.from("host", "port", "database").to("spring.r2dbc.url",
(host, port, database) -> String.format("r2dbc:sqlserver://%s:%s/%s", host, port, database));
map.from("username").to("spring.r2dbc.username");
});
}

View File

@@ -98,7 +98,7 @@ final class BindingSpecificEnvironmentPostProcessorTest {
@Test
@DisplayName("included implementations are registered")
void includedImplementations() {
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(14);
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(15);
}
}

View File

@@ -50,8 +50,8 @@ final class Db2BindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
@DisplayName("contributes jdbc properties")
void testJdbc() {
new Db2BindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "com.ibm.db2.jcc.DB2Driver")
@@ -60,6 +60,15 @@ final class Db2BindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("contributes r2dbc properties")
void testR2dbc() {
new Db2BindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.r2dbc.password", "test-password")
.containsEntry("spring.r2dbc.url", "r2dbc:db2://test-host:test-port/test-database")
.containsEntry("spring.r2dbc.username", "test-username"); }
@Test
@DisplayName("can be disabled")
void disabled() {

View File

@@ -50,8 +50,8 @@ final class MySqlBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
@DisplayName("contributes jdbc properties")
void testJdbc() {
new MySqlBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "org.mariadb.jdbc.Driver")
@@ -60,6 +60,16 @@ final class MySqlBindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("contributes r2dbc properties")
void testR2dbc() {
new MySqlBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.r2dbc.password", "test-password")
.containsEntry("spring.r2dbc.url", "r2dbc:mysql://test-host:test-port/test-database")
.containsEntry("spring.r2dbc.username", "test-username");
}
@Test
@DisplayName("can be disabled")
void disabled() {

View File

@@ -50,8 +50,8 @@ final class OracleBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
@DisplayName("contributes jdbc properties")
void testJdbc() {
new OracleBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "oracle.jdbc.OracleDriver")
@@ -60,6 +60,16 @@ final class OracleBindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("contributes r2dbc properties")
void testR2dbc() {
new OracleBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.r2dbc.password", "test-password")
.containsEntry("spring.r2dbc.url", "r2dbc:oracle://test-host:test-port/test-database")
.containsEntry("spring.r2dbc.username", "test-username");
}
@Test
@DisplayName("can be disabled")
void disabled() {

View File

@@ -50,8 +50,8 @@ final class PostgreSqlBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
@DisplayName("contributes jdbc properties")
void testJdbc() {
new PostgreSqlBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "org.postgresql.Driver")
@@ -60,6 +60,16 @@ final class PostgreSqlBindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("contributes r2dbc properties")
void testR2dbc() {
new PostgreSqlBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.r2dbc.password", "test-password")
.containsEntry("spring.r2dbc.url", "r2dbc:postgres://test-host:test-port/test-database")
.containsEntry("spring.r2dbc.username", "test-username");
}
@Test
@DisplayName("can be disabled")
void disabled() {

View File

@@ -50,8 +50,8 @@ final class SqlServerBindingsPropertiesProcessorTest {
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
@DisplayName("contributes jdbc properties")
void testJdbc() {
new SqlServerBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
@@ -60,6 +60,16 @@ final class SqlServerBindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("contributes r2dbc properties")
void testR2dbc() {
new SqlServerBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.r2dbc.password", "test-password")
.containsEntry("spring.r2dbc.url", "r2dbc:sqlserver://test-host:test-port/test-database")
.containsEntry("spring.r2dbc.username", "test-username");
}
@Test
@DisplayName("can be disabled")
void disabled() {