public final class ConnectionFactories extends Object
ConnectionFactory
based on a set of ConnectionFactoryOptions
.
This utility provides runtime discovery of R2DBC implementations that are available through the class path. A ConnectionFactory
can be obtained in two ways:
get(String)
get(ConnectionFactoryOptions)
r2dbc:a-driver:pipes://localhost:3306/my_database?locale=en_US \___/ \______/ \___/ \____________/\__________/\___________/ | | | | | | scheme driver protocol authority path query
scheme
: Identify that the URL is a valid R2DBC URL. Valid schemes are r2dbc
and r2dbcs
(configure SSL usage).
driver
: Identifier for a driver. The specification has no authority over driver identifiers.
protocol
: Used as optional protocol information to configure a driver-specific protocol. Protocols can be organized hierarchically and are separated by a colon (:).
authority
: Contains an endpoint and authorization. The authority may contain a single host or a collection of hostnames and port tuples by separating these with a comma (,).
path
: (optional) Used as an initial schema or database name.
query
: (optional) Used to pass additional configuration options in the form of String key-value pairs by using the key name as the option name.
fragment
: Unused (reserved for future use).
Example usage:
ConnectionFactory factory = ConnectionFactories.get("r2dbc:a-driver:pipes://localhost:3306/my_database?locale=en_US");
ConnectionFactory
LookupConnectionFactory
can be requested by providing a ConnectionFactoryOptions
object to get(ConnectionFactoryOptions)
. ConnectionFactoryOptions
can be built using a builder from ConnectionFactoryOptions
tuples. Once created, ConnectionFactoryOptions
is immutable.
Example usage:
ConnectionFactoryOptions options = ConnectionFactoryOptions.builder() .option(ConnectionFactoryOptions.DRIVER, "a-driver") .option(ConnectionFactoryOptions.PROTOCOL, "pipes") .option(ConnectionFactoryOptions.HOST, "localhost") .option(ConnectionFactoryOptions.PORT, 3306) .option(ConnectionFactoryOptions.DATABASE, "my_database") .option(Option.valueOf("locale"), "en_US") .build(); ConnectionFactory factory = ConnectionFactories.get(options);
Modifier and Type | Method and Description |
---|---|
static ConnectionFactory |
find(ConnectionFactoryOptions connectionFactoryOptions)
Returns a
ConnectionFactory if an available implementation can be created from a collection of ConnectionFactoryOptions . |
static ConnectionFactory |
get(ConnectionFactoryOptions connectionFactoryOptions)
Returns a
ConnectionFactory from an available implementation, created from a collection of ConnectionFactoryOptions . |
static ConnectionFactory |
get(String url)
Returns a
ConnectionFactory from an available implementation, created from a R2DBC Connection URL. |
static boolean |
supports(ConnectionFactoryOptions connectionFactoryOptions)
Returns whether a
ConnectionFactory can be created from a collection of ConnectionFactoryOptions . |
@Nullable public static ConnectionFactory find(ConnectionFactoryOptions connectionFactoryOptions)
ConnectionFactory
if an available implementation can be created from a collection of ConnectionFactoryOptions
.connectionFactoryOptions
- a collection of ConnectionFactoryOptions
ConnectionFactory
if one can be created, otherwise null
IllegalArgumentException
- if connectionSpecification
is null
public static ConnectionFactory get(String url)
ConnectionFactory
from an available implementation, created from a R2DBC Connection URL.
R2DBC URL format is:
r2dbc:driver[:protocol]
://[user:password@]host[:port][/path][?option=value]}.url
- the R2DBC connection urlConnectionFactory
IllegalArgumentException
- if url
is null
IllegalStateException
- if no available implementation can create a ConnectionFactory
public static ConnectionFactory get(ConnectionFactoryOptions connectionFactoryOptions)
ConnectionFactory
from an available implementation, created from a collection of ConnectionFactoryOptions
.connectionFactoryOptions
- a collection of ConnectionFactoryOptions
ConnectionFactory
IllegalArgumentException
- if connectionFactoryOptions
is null
IllegalStateException
- if no available implementation can create a ConnectionFactory
public static boolean supports(ConnectionFactoryOptions connectionFactoryOptions)
ConnectionFactory
can be created from a collection of ConnectionFactoryOptions
.connectionFactoryOptions
- a collection of ConnectionFactoryOptions
true
if a ConnectionFactory
can be created from a collection of ConnectionFactoryOptions
, false
otherwise.IllegalArgumentException
- if connectionFactoryOptions
is null
Copyright © 2022. All rights reserved.