Search in sources :

Example 1 with ConnectionFactory

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

the class R2dbcReactiveOAuth2AuthorizedClientServiceTests method createDb.

private static ConnectionFactory createDb() {
    ConnectionFactory connectionFactory = H2ConnectionFactory.inMemory("oauth-test");
    Mono.from(connectionFactory.create()).flatMapMany((connection) -> Flux.from(connection.createStatement("drop table oauth2_authorized_client").execute()).flatMap(Result::getRowsUpdated).onErrorResume((e) -> Mono.empty()).thenMany(connection.close())).as(StepVerifier::create).verifyComplete();
    ConnectionFactoryInitializer createDb = createDb(OAUTH2_CLIENT_SCHEMA_SQL_RESOURCE);
    createDb.setConnectionFactory(connectionFactory);
    createDb.afterPropertiesSet();
    return connectionFactory;
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) H2ConnectionFactory(io.r2dbc.h2.H2ConnectionFactory) ConnectionFactoryInitializer(org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer)

Example 2 with ConnectionFactory

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

the class BeanFactoryConnectionFactoryLookupUnitTests method shouldLookupConnectionFactory.

@Test
public void shouldLookupConnectionFactory() {
    DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory();
    when(beanFactory.getBean(CONNECTION_FACTORY_BEAN_NAME, ConnectionFactory.class)).thenReturn(expectedConnectionFactory);
    BeanFactoryConnectionFactoryLookup lookup = new BeanFactoryConnectionFactoryLookup();
    lookup.setBeanFactory(beanFactory);
    ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_BEAN_NAME);
    assertThat(connectionFactory).isNotNull();
    assertThat(connectionFactory).isSameAs(expectedConnectionFactory);
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) Test(org.junit.jupiter.api.Test)

Example 3 with ConnectionFactory

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

the class MapConnectionFactoryLookupUnitTests method addingConnectionFactoryPermitsOverride.

@Test
public void addingConnectionFactoryPermitsOverride() {
    Map<String, ConnectionFactory> connectionFactories = new HashMap<>();
    DummyConnectionFactory overriddenConnectionFactory = new DummyConnectionFactory();
    DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory();
    connectionFactories.put(CONNECTION_FACTORY_NAME, overriddenConnectionFactory);
    MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup();
    lookup.setConnectionFactories(connectionFactories);
    lookup.addConnectionFactory(CONNECTION_FACTORY_NAME, expectedConnectionFactory);
    ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_NAME);
    assertThat(connectionFactory).isNotNull().isSameAs(expectedConnectionFactory);
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 4 with ConnectionFactory

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

the class ConnectionFactoryUtils method getConnectionSynchronizationOrder.

/**
 * Determine the connection synchronization order to use for the given {@link ConnectionFactory}.
 * Decreased for every level of nesting that a {@link ConnectionFactory} has,
 * checked through the level of {@link DelegatingConnectionFactory} nesting.
 * @param connectionFactory the {@link ConnectionFactory} to check
 * @return the connection synchronization order to use
 * @see #CONNECTION_SYNCHRONIZATION_ORDER
 */
private static int getConnectionSynchronizationOrder(ConnectionFactory connectionFactory) {
    int order = CONNECTION_SYNCHRONIZATION_ORDER;
    ConnectionFactory current = connectionFactory;
    while (current instanceof DelegatingConnectionFactory) {
        order--;
        current = ((DelegatingConnectionFactory) current).getTargetConnectionFactory();
    }
    return order;
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory)

Example 5 with ConnectionFactory

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

the class R2dbcTest method setup.

@Before
public void setup() {
    ConnectionFactory connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.parse("r2dbc:h2:file://localhost/~/jooq-r2dbc-example").mutate().option(ConnectionFactoryOptions.USER, "sa").option(ConnectionFactoryOptions.PASSWORD, "").build());
    ctx = DSL.using(connectionFactory);
    Flux.fromIterable(ctx.parser().parse(Source.of(R2dbcTest.class.getResourceAsStream("/db.sql")).readString())).ofType(RowCountQuery.class).flatMap(q -> q).collectList().block();
}
Also used : ConnectionFactory(io.r2dbc.spi.ConnectionFactory) RowCountQuery(org.jooq.RowCountQuery) Before(org.junit.Before)

Aggregations

ConnectionFactory (io.r2dbc.spi.ConnectionFactory)12 Test (org.junit.jupiter.api.Test)4 H2ConnectionFactory (io.r2dbc.h2.H2ConnectionFactory)2 HashMap (java.util.HashMap)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ConnectionProvider (org.jooq.ConnectionProvider)1 RowCountQuery (org.jooq.RowCountQuery)1 Before (org.junit.Before)1 ConnectionFactoryInitializer (org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer)1 ReactiveClientRegistrationRepository (org.springframework.security.oauth2.client.registration.ReactiveClientRegistrationRepository)1