Search in sources :

Example 1 with Builder

use of io.r2dbc.spi.ConnectionFactoryOptions.Builder in project spring-boot by spring-projects.

the class ConnectionFactoryOptionsInitializer method initializeRegularOptions.

private ConnectionFactoryOptions.Builder initializeRegularOptions(R2dbcProperties properties) {
    ConnectionFactoryOptions urlOptions = ConnectionFactoryOptions.parse(properties.getUrl());
    Builder optionsBuilder = urlOptions.mutate();
    configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.USER, properties::getUsername, StringUtils::hasText);
    configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.PASSWORD, properties::getPassword, StringUtils::hasText);
    configureIf(optionsBuilder, urlOptions, ConnectionFactoryOptions.DATABASE, () -> determineDatabaseName(properties), StringUtils::hasText);
    if (properties.getProperties() != null) {
        properties.getProperties().forEach((key, value) -> optionsBuilder.option(Option.valueOf(key), value));
    }
    return optionsBuilder;
}
Also used : ConnectionFactoryOptions(io.r2dbc.spi.ConnectionFactoryOptions) StringUtils(org.springframework.util.StringUtils) Builder(io.r2dbc.spi.ConnectionFactoryOptions.Builder)

Example 2 with Builder

use of io.r2dbc.spi.ConnectionFactoryOptions.Builder in project spring-boot by spring-projects.

the class ConnectionFactoryOptionsInitializer method initializeEmbeddedOptions.

private Builder initializeEmbeddedOptions(R2dbcProperties properties, EmbeddedDatabaseConnection embeddedDatabaseConnection) {
    String url = embeddedDatabaseConnection.getUrl(determineEmbeddedDatabaseName(properties));
    if (url == null) {
        throw connectionFactoryBeanCreationException("Failed to determine a suitable R2DBC Connection URL", properties, embeddedDatabaseConnection);
    }
    Builder builder = ConnectionFactoryOptions.parse(url).mutate();
    String username = determineEmbeddedUsername(properties);
    if (StringUtils.hasText(username)) {
        builder.option(ConnectionFactoryOptions.USER, username);
    }
    if (StringUtils.hasText(properties.getPassword())) {
        builder.option(ConnectionFactoryOptions.PASSWORD, properties.getPassword());
    }
    return builder;
}
Also used : Builder(io.r2dbc.spi.ConnectionFactoryOptions.Builder)

Example 3 with Builder

use of io.r2dbc.spi.ConnectionFactoryOptions.Builder in project jOOQ by jOOQ.

the class R2DBC method getConnection.

static final Connection getConnection(String url, Properties properties) {
    if (properties.isEmpty())
        return block(ConnectionFactories.get(url).create());
    Builder builder = ConnectionFactoryOptions.parse(url).mutate();
    properties.forEach((k, v) -> {
        if ("user".equals(k))
            setOption(builder, ConnectionFactoryOptions.USER, v);
        else if ("password".equals(k))
            setOption(builder, ConnectionFactoryOptions.PASSWORD, v);
        else if ("host".equals(k))
            setOption(builder, ConnectionFactoryOptions.HOST, v);
        else if ("port".equals(k))
            setOption(builder, ConnectionFactoryOptions.PORT, Integer.parseInt("" + v));
        else if ("database".equals(k))
            setOption(builder, ConnectionFactoryOptions.DATABASE, v);
        else if ("ssl".equals(k))
            setOption(builder, ConnectionFactoryOptions.SSL, v);
        else
            setOption(builder, Option.valueOf("" + k), v);
    });
    return block(ConnectionFactories.get(builder.build()).create());
}
Also used : Builder(io.r2dbc.spi.ConnectionFactoryOptions.Builder)

Aggregations

Builder (io.r2dbc.spi.ConnectionFactoryOptions.Builder)3 ConnectionFactoryOptions (io.r2dbc.spi.ConnectionFactoryOptions)1 StringUtils (org.springframework.util.StringUtils)1