use of io.r2dbc.spi.ConnectionFactory in project spring-framework by spring-projects.
the class AbstractRoutingConnectionFactory method determineTargetConnectionFactory.
/**
* Retrieve the current target {@link ConnectionFactory}. Determines the
* {@link #determineCurrentLookupKey() current lookup key}, performs a lookup
* in the {@link #setTargetConnectionFactories targetConnectionFactories} map,
* falls back to the specified {@link #setDefaultTargetConnectionFactory default
* target ConnectionFactory} if necessary.
* @return {@link Mono} emitting the current {@link ConnectionFactory} as
* per {@link #determineCurrentLookupKey()}
* @see #determineCurrentLookupKey()
*/
protected Mono<ConnectionFactory> determineTargetConnectionFactory() {
Assert.state(this.resolvedConnectionFactories != null, "ConnectionFactory router not initialized");
Mono<Object> lookupKey = determineCurrentLookupKey().defaultIfEmpty(FALLBACK_MARKER);
return lookupKey.handle((key, sink) -> {
ConnectionFactory connectionFactory = this.resolvedConnectionFactories.get(key);
if (connectionFactory == null && (key == FALLBACK_MARKER || this.lenientFallback)) {
connectionFactory = this.resolvedDefaultConnectionFactory;
}
if (connectionFactory == null) {
sink.error(new IllegalStateException(String.format("Cannot determine target ConnectionFactory for lookup key '%s'", key == FALLBACK_MARKER ? null : key)));
return;
}
sink.next(connectionFactory);
});
}
use of io.r2dbc.spi.ConnectionFactory in project spring-framework by spring-projects.
the class MapConnectionFactoryLookupUnitTests method shouldLookupConnectionFactory.
@Test
public void shouldLookupConnectionFactory() {
Map<String, ConnectionFactory> connectionFactories = new HashMap<>();
DummyConnectionFactory expectedConnectionFactory = new DummyConnectionFactory();
connectionFactories.put(CONNECTION_FACTORY_NAME, expectedConnectionFactory);
MapConnectionFactoryLookup lookup = new MapConnectionFactoryLookup();
lookup.setConnectionFactories(connectionFactories);
ConnectionFactory connectionFactory = lookup.getConnectionFactory(CONNECTION_FACTORY_NAME);
assertThat(connectionFactory).isNotNull().isSameAs(expectedConnectionFactory);
}
use of io.r2dbc.spi.ConnectionFactory in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method before.
@BeforeEach
@SuppressWarnings({ "rawtypes", "unchecked" })
void before() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
when(connectionFactory.create()).thenReturn((Publisher) Mono.just(connection));
when(connection.close()).thenReturn(Mono.empty());
databaseClientBuilder = DatabaseClient.builder().connectionFactory(connectionFactory).bindMarkers(BindMarkersFactory.indexed("$", 1));
}
use of io.r2dbc.spi.ConnectionFactory in project spring-framework by spring-projects.
the class DefaultDatabaseClientUnitTests method connectionFactoryIsExposed.
@Test
void connectionFactoryIsExposed() {
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
DatabaseClient databaseClient = DatabaseClient.builder().connectionFactory(connectionFactory).bindMarkers(BindMarkersFactory.anonymous("?")).build();
assertThat(databaseClient.getConnectionFactory()).isSameAs(connectionFactory);
}
use of io.r2dbc.spi.ConnectionFactory in project spring-security by spring-projects.
the class R2dbcReactiveOAuth2AuthorizedClientServiceTests method setUp.
@BeforeEach
public void setUp() {
final ConnectionFactory connectionFactory = createDb();
this.clientRegistration = TestClientRegistrations.clientRegistration().build();
this.clientRegistrationRepository = mock(ReactiveClientRegistrationRepository.class);
given(this.clientRegistrationRepository.findByRegistrationId(anyString())).willReturn(Mono.just(this.clientRegistration));
this.databaseClient = DatabaseClient.create(connectionFactory);
this.authorizedClientService = new R2dbcReactiveOAuth2AuthorizedClientService(this.databaseClient, this.clientRegistrationRepository);
}
Aggregations