io.r2dbc.spi.Option Java Examples

The following examples show how to use io.r2dbc.spi.Option. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudConfig.java    From cf-butler with Apache License 2.0 8 votes vote down vote up
@Bean
@ConditionalOnProperty(VCAP_SERVICE_VARIABLE)
ConnectionFactory connectionFactory() {
    R2dbcProperties properties = r2dbcProperties();
    ConnectionFactoryOptions.Builder builder = ConnectionFactoryOptions
            .parse(properties.getUrl()).mutate();
    String username = properties.getUsername();
    if (StringUtils.hasText(username)) {
        builder.option(ConnectionFactoryOptions.USER, username);
    }
    String password = properties.getPassword();
    if (StringUtils.hasText(password)) {
        builder.option(ConnectionFactoryOptions.PASSWORD, password);
    }
    String databaseName = properties.getName();
    if (StringUtils.hasText(databaseName)) {
        builder.option(ConnectionFactoryOptions.DATABASE, databaseName);
    }
    if (properties.getProperties() != null) {
        properties.getProperties()
                .forEach((key, value) -> builder
                        .option(Option.valueOf(key), value));
    }
    return ConnectionFactories.get(builder.build());
}
 
Example #2
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 7 votes vote down vote up
@Test
void invalidProgrammatic() {
    assertThat(assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(SSL, true)
        .build()))
        .getMessage())
        .contains("sslMode");

    for (SslMode mode : SslMode.values()) {
        if (mode.startSsl()) {
            assertThat(assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
                .option(DRIVER, "mysql")
                .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
                .option(USER, "root")
                .option(Option.valueOf("sslMode"), mode.name().toLowerCase())
                .build()))
                .getMessage())
                .contains("sslMode");
        }
    }
}
 
Example #3
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void invalidProgrammatic() {
    assertThat(assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(SSL, true)
        .build()))
        .getMessage())
        .contains("sslMode");

    for (SslMode mode : SslMode.values()) {
        if (mode.startSsl()) {
            assertThat(assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
                .option(DRIVER, "mysql")
                .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
                .option(USER, "root")
                .option(Option.valueOf("sslMode"), mode.name().toLowerCase())
                .build()))
                .getMessage())
                .contains("sslMode");
        }
    }
}
 
Example #4
Source File: BookExampleApp.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param sampleInstance the sample instance to use.
 * @param sampleDatabase the sample database to use.
 * @param sampleProjectId the sample project to use.
 */
public BookExampleApp(String sampleInstance, String sampleDatabase,
    String sampleProjectId) {
  this.connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
      .option(Option.valueOf("project"), sampleProjectId)
      .option(DRIVER, DRIVER_NAME)
      .option(INSTANCE, sampleInstance)
      .option(DATABASE, sampleDatabase)
      .build());
}
 
Example #5
Source File: SpringDataR2dbcApp.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
@Bean
public static ConnectionFactory spannerConnectionFactory() {
  ConnectionFactory connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
      .option(Option.valueOf("project"), GCP_PROJECT)
      .option(DRIVER, DRIVER_NAME)
      .option(INSTANCE, SPANNER_INSTANCE)
      .option(DATABASE, SPANNER_DATABASE)
      .build());

  return connectionFactory;
}
 
Example #6
Source File: DemoApplication.java    From spring-reactive-sample with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public ConnectionFactoryOptionsBuilderCustomizer customizer() {
    Map<String, String> options = new HashMap<>();
    options.put("connectionTimeout", "60s");

    return (builder) -> options.keySet()
            .forEach(
                    optKey -> builder.option(Option.valueOf(optKey), options.get(optKey))

            );
}
 
Example #7
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Test
void validProgrammatic() {
    ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(SSL, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(Option.valueOf("sslMode"), "disabled")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(SSL, false)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(Option.valueOf("sslMode"), "disabled")
        .option(SSL, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(PORT, 3307)
        .option(USER, "root")
        .option(PASSWORD, "123456")
        .option(SSL, true)
        .option(CONNECT_TIMEOUT, Duration.ofSeconds(3))
        .option(DATABASE, "r2dbc")
        .option(Option.valueOf("zeroDate"), "use_round")
        .option(Option.valueOf("sslMode"), "verify_identity")
        .option(Option.valueOf("tlsVersion"), "TLSv1.2,TLSv1.3")
        .option(Option.valueOf("sslCa"), "/path/to/ca.pem")
        .option(Option.valueOf("sslKey"), "/path/to/client-key.pem")
        .option(Option.valueOf("sslCert"), "/path/to/client-cert.pem")
        .option(Option.valueOf("sslKeyPassword"), "ssl123456")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);
}
 
Example #8
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Test
void validProgrammatic() {
    ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(SSL, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(Option.valueOf("sslMode"), "disabled")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(SSL, false)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(Option.valueOf("sslMode"), "disabled")
        .option(SSL, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(PORT, 3307)
        .option(USER, "root")
        .option(PASSWORD, "123456")
        .option(SSL, true)
        .option(CONNECT_TIMEOUT, Duration.ofSeconds(3))
        .option(DATABASE, "r2dbc")
        .option(Option.valueOf("zeroDate"), "use_round")
        .option(Option.valueOf("sslMode"), "verify_identity")
        .option(Option.valueOf("tlsVersion"), "TLSv1.2,TLSv1.3")
        .option(Option.valueOf("sslCa"), "/path/to/ca.pem")
        .option(Option.valueOf("sslKey"), "/path/to/client-key.pem")
        .option(Option.valueOf("sslCert"), "/path/to/client-cert.pem")
        .option(Option.valueOf("sslKeyPassword"), "ssl123456")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);
}