Top Description Constructors Methods
io.r2dbc.spi

public final Class ConnectionFactories

extends Object
Class Inheritance
Imports
java.util.ServiceLoader

Utility for discovering an available 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:

R2DBC Connection URL

R2DBC defines a standard URL format that is an enhanced form of RFC 3986. The following example shows a valid R2DBC URL:
r2dbc:a-driver:pipes://localhost:3306/my_database?locale=en_US
\___/ \______/ \___/   \____________/\__________/\___________/
  |       |      |           |           |           |
scheme  driver  protocol  authority    path        query

Example usage:

ConnectionFactory factory = ConnectionFactories.get("r2dbc:a-driver:pipes://localhost:3306/my_database?locale=en_US");

Programmatic ConnectionFactory Lookup

A ConnectionFactory can be requested by providing a ConnectionFactoryOptions object to ConnectionFactories#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);
See Also
ConnectionFactoryOptions, ConnectionFactoryOptions#parse(CharSequence), ServiceLoader

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ConnectionFactory

Returns:

the created ConnectionFactory if one can be created, otherwise null
find
(ConnectionFactoryOptions
a collection of ConnectionFactoryOptions
connectionFactoryOptions
)

Returns a ConnectionFactory if an available implementation can be created from a collection of ConnectionFactoryOptions.

public static ConnectionFactory

Returns:

the created ConnectionFactory
get
(String
the R2DBC connection url
url
)

Returns a ConnectionFactory from an available implementation, created from a R2DBC Connection URL.

public static ConnectionFactory

Returns:

the created ConnectionFactory
get
(ConnectionFactoryOptions
a collection of ConnectionFactoryOptions
connectionFactoryOptions
)

Returns a ConnectionFactory from an available implementation, created from a collection of ConnectionFactoryOptions.

private static String
private static ServiceLoader<ConnectionFactoryProvider>
public static boolean

Returns:

true if a ConnectionFactory can be created from a collection of ConnectionFactoryOptions, false otherwise.
supports
(ConnectionFactoryOptions
a collection of ConnectionFactoryOptions
connectionFactoryOptions
)

Returns whether a ConnectionFactory can be created from a collection of ConnectionFactoryOptions.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ConnectionFactoriesback to summary
private ConnectionFactories()

Method Detail

findback to summary
public static ConnectionFactory find(ConnectionFactoryOptions connectionFactoryOptions)

Returns a ConnectionFactory if an available implementation can be created from a collection of ConnectionFactoryOptions.

Parameters
connectionFactoryOptions:ConnectionFactoryOptions

a collection of ConnectionFactoryOptions

Returns:ConnectionFactory

the created ConnectionFactory if one can be created, otherwise null

Annotations
@Nullable
Exceptions
IllegalArgumentException:
if connectionSpecification is null
getback to summary
public static ConnectionFactory get(String url)

Returns a 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]}.

Parameters
url:String

the R2DBC connection url

Returns:ConnectionFactory

the created ConnectionFactory

Exceptions
IllegalArgumentException:
if url is null
IllegalStateException:
if no available implementation can create a ConnectionFactory
getback to summary
public static ConnectionFactory get(ConnectionFactoryOptions connectionFactoryOptions)

Returns a ConnectionFactory from an available implementation, created from a collection of ConnectionFactoryOptions.

Parameters
connectionFactoryOptions:ConnectionFactoryOptions

a collection of ConnectionFactoryOptions

Returns:ConnectionFactory

the created ConnectionFactory

Exceptions
IllegalArgumentException:
if connectionFactoryOptions is null
IllegalStateException:
if no available implementation can create a ConnectionFactory
getAvailableDriversback to summary
private static String getAvailableDrivers()
loadProvidersback to summary
private static ServiceLoader<ConnectionFactoryProvider> loadProviders()
supportsback to summary
public static boolean supports(ConnectionFactoryOptions connectionFactoryOptions)

Returns whether a ConnectionFactory can be created from a collection of ConnectionFactoryOptions.

Parameters
connectionFactoryOptions:ConnectionFactoryOptions

a collection of ConnectionFactoryOptions

Returns:boolean

true if a ConnectionFactory can be created from a collection of ConnectionFactoryOptions, false otherwise.

Exceptions
IllegalArgumentException:
if connectionFactoryOptions is null