Search in sources :

Example 16 with ConnectionFactory

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

the class R2dbcAutoConfigurationTests method configureWithoutPoolShouldApplyAdditionalProperties.

@Test
void configureWithoutPoolShouldApplyAdditionalProperties() {
    this.contextRunner.withPropertyValues("spring.r2dbc.pool.enabled=false", "spring.r2dbc.url:r2dbc:simple://foo", "spring.r2dbc.properties.test=value", "spring.r2dbc.properties.another=2").run((context) -> {
        ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
        assertThat(connectionFactory).asInstanceOf(type(OptionsCapableConnectionFactory.class)).extracting(OptionsCapableConnectionFactory::getOptions).satisfies((options) -> {
            assertThat(options.getRequiredValue(Option.<String>valueOf("test"))).isEqualTo("value");
            assertThat(options.getRequiredValue(Option.<String>valueOf("another"))).isEqualTo("2");
        });
    });
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleTestConnectionFactory(org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider.SimpleTestConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 17 with ConnectionFactory

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

the class R2dbcAutoConfigurationTests method configureWithPoolShouldApplyAdditionalProperties.

@Test
void configureWithPoolShouldApplyAdditionalProperties() {
    this.contextRunner.withPropertyValues("spring.r2dbc.url:r2dbc:simple://foo", "spring.r2dbc.properties.test=value", "spring.r2dbc.properties.another=2").run((context) -> {
        assertThat(context).hasSingleBean(ConnectionFactory.class).hasSingleBean(ConnectionPool.class);
        ConnectionFactory connectionFactory = context.getBean(ConnectionPool.class).unwrap();
        assertThat(connectionFactory).asInstanceOf(type(OptionsCapableConnectionFactory.class)).extracting(OptionsCapableConnectionFactory::getOptions).satisfies((options) -> {
            assertThat(options.getRequiredValue(Option.<String>valueOf("test"))).isEqualTo("value");
            assertThat(options.getRequiredValue(Option.<String>valueOf("another"))).isEqualTo("2");
        });
    });
}
Also used : ConnectionPool(io.r2dbc.pool.ConnectionPool) ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleTestConnectionFactory(org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider.SimpleTestConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 18 with ConnectionFactory

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

the class R2dbcAutoConfigurationTests method configureWithoutPoolInvokeOptionCustomizer.

@Test
void configureWithoutPoolInvokeOptionCustomizer() {
    this.contextRunner.withPropertyValues("spring.r2dbc.pool.enabled=false", "spring.r2dbc.url:r2dbc:simple://host/database").withUserConfiguration(CustomizerConfiguration.class).run((context) -> {
        assertThat(context).hasSingleBean(ConnectionFactory.class).doesNotHaveBean(ConnectionPool.class);
        ConnectionFactory connectionFactory = context.getBean(ConnectionFactory.class);
        assertThat(connectionFactory).asInstanceOf(type(OptionsCapableConnectionFactory.class)).extracting(OptionsCapableConnectionFactory::getOptions).satisfies((options) -> assertThat(options.getRequiredValue(Option.valueOf("customized"))).isEqualTo(Boolean.TRUE));
    });
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) SimpleTestConnectionFactory(org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider.SimpleTestConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) OptionsCapableConnectionFactory(org.springframework.boot.r2dbc.OptionsCapableConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 19 with ConnectionFactory

use of io.r2dbc.spi.ConnectionFactory in project jOOQ by jOOQ.

the class DefaultCloseableDSLContext method close.

// -------------------------------------------------------------------------
// XXX AutoCloseable
// -------------------------------------------------------------------------
@Override
public void close() {
    ConnectionProvider cp = configuration().connectionProvider();
    ConnectionFactory cf = configuration().connectionFactory();
    if (cp instanceof DefaultCloseableConnectionProvider) {
        DefaultCloseableConnectionProvider dcp = (DefaultCloseableConnectionProvider) cp;
        JDBCUtils.safeClose(dcp.connection);
        dcp.connection = null;
    }
    if (cf instanceof DefaultConnectionFactory) {
        DefaultConnectionFactory dcf = (DefaultConnectionFactory) cf;
        if (dcf.finalize) {
            R2DBC.block(dcf.connection.close());
            dcf.connection = null;
        }
    }
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) ConnectionProvider(org.jooq.ConnectionProvider)

Example 20 with ConnectionFactory

use of io.r2dbc.spi.ConnectionFactory in project spring-framework by spring-projects.

the class AbstractRoutingConnectionFactory method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    Assert.notNull(this.targetConnectionFactories, "Property 'targetConnectionFactories' must not be null");
    this.resolvedConnectionFactories = CollectionUtils.newHashMap(this.targetConnectionFactories.size());
    this.targetConnectionFactories.forEach((key, value) -> {
        Object lookupKey = resolveSpecifiedLookupKey(key);
        ConnectionFactory connectionFactory = resolveSpecifiedConnectionFactory(value);
        this.resolvedConnectionFactories.put(lookupKey, connectionFactory);
    });
    if (this.defaultTargetConnectionFactory != null) {
        this.resolvedDefaultConnectionFactory = resolveSpecifiedConnectionFactory(this.defaultTargetConnectionFactory);
    }
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory)

Aggregations

ConnectionFactory (io.r2dbc.spi.ConnectionFactory)25 Test (org.junit.jupiter.api.Test)17 H2ConnectionFactory (io.r2dbc.h2.H2ConnectionFactory)11 CloseableConnectionFactory (io.r2dbc.h2.CloseableConnectionFactory)5 H2ConnectionOption (io.r2dbc.h2.H2ConnectionOption)5 Connection (io.r2dbc.spi.Connection)5 Result (io.r2dbc.spi.Result)5 ValidationDepth (io.r2dbc.spi.ValidationDepth)5 Collections (java.util.Collections)5 UUID (java.util.UUID)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Assertions.entry (org.assertj.core.api.Assertions.entry)5 BDDMockito.given (org.mockito.BDDMockito.given)5 Mockito.mock (org.mockito.Mockito.mock)5 ReactiveHealthIndicator (org.springframework.boot.actuate.health.ReactiveHealthIndicator)5 Status (org.springframework.boot.actuate.health.Status)5 Flux (reactor.core.publisher.Flux)5 Mono (reactor.core.publisher.Mono)5 StepVerifier (reactor.test.StepVerifier)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4