Search in sources :

Example 1 with ConnectionFactoryInitializer

use of org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer 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 ConnectionFactoryInitializer

use of org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer in project spring-security by spring-projects.

the class R2dbcReactiveOAuth2AuthorizedClientServiceTests method createDb.

private static ConnectionFactoryInitializer createDb(String schema) {
    ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer();
    CompositeDatabasePopulator populator = new CompositeDatabasePopulator();
    populator.addPopulators(new ResourceDatabasePopulator(new ClassPathResource(schema)));
    initializer.setDatabasePopulator(populator);
    return initializer;
}
Also used : ResourceDatabasePopulator(org.springframework.r2dbc.connection.init.ResourceDatabasePopulator) ConnectionFactoryInitializer(org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer) CompositeDatabasePopulator(org.springframework.r2dbc.connection.init.CompositeDatabasePopulator) ClassPathResource(org.springframework.core.io.ClassPathResource)

Aggregations

ConnectionFactoryInitializer (org.springframework.r2dbc.connection.init.ConnectionFactoryInitializer)2 H2ConnectionFactory (io.r2dbc.h2.H2ConnectionFactory)1 ConnectionFactory (io.r2dbc.spi.ConnectionFactory)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 CompositeDatabasePopulator (org.springframework.r2dbc.connection.init.CompositeDatabasePopulator)1 ResourceDatabasePopulator (org.springframework.r2dbc.connection.init.ResourceDatabasePopulator)1