Top Description Inners Fields Constructors Methods
io.r2dbc.spi

public final Class ConnectionFactoryOptions

extends Object
Class Inheritance
Imports
java.time.Duration, java.util.ArrayList, .HashMap, .List, .Map, .Objects, java.util.function.Predicate

A holder for configuration options related to ConnectionFactorys.

A ConnectionFactoryOptions represents a configuration state that consists of one or more Option objects. Each configuration option can be specified at most once to associate a value with its key.

New objects are constructed through builder() or by parsing a R2DBC Connection URL. ConnectionFactoryOptions can be augmented to allow staged construction of the configuration state using a initialized builder to create a new ConnectionFactoryOptions objects with mutations applied. Values of this class are immutable once created. Builder initializers are left unchanged.

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();

Note that Connection URL Parsing cannot access Option type information T due to Java's type erasure. Options configured by URL parsing are represented as String values.

See Also
ConnectionFactories

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
public static final Option<Duration>
CONNECT_TIMEOUT

Connection timeout.

public static final Option<String>
DATABASE

Initial database name.

public static final Option<String>
DRIVER

Driver name.

public static final Option<String>
HOST

Endpoint host name.

public static final Option<Duration>
LOCK_WAIT_TIMEOUT

Lock timeout.

private final Map<Option<?>, Object>
public static final Option<CharSequence>
PASSWORD

Password for authentication.

public static final Option<Integer>
PORT

Endpoint port number.

public static final Option<String>
PROTOCOL

Driver protocol name.

public static final Option<Boolean>
SSL

Whether to require SSL.

public static final Option<Duration>
STATEMENT_TIMEOUT

Statement timeout.

public static final Option<String>
USER

User for authentication.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ConnectionFactoryOptions.Builder

Returns:

a new Builder
builder
()

Returns a new Builder.

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Object

Returns:

the value for an option
getRequiredValue
(Option<?>
the option to retrieve the value for
option
)

Returns the value for an option if it exists.

public Object

Returns:

the value for an option if it exists, otherwise null
getValue
(Option<?>
the option to retrieve the value for
option
)

Returns the value for an option if it exists, otherwise null.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean

Returns:

true if the option exists, otherwise false
hasOption
(Option<?>
the option to test for
option
)

Returns true if the option exists, otherwise false.

public ConnectionFactoryOptions.Builder

Returns:

a new Builder
mutate
()

Returns a new Builder initialized with this ConnectionFactoryOptions.

public static ConnectionFactoryOptions

Returns:

the parsed ConnectionFactoryOptions.
parse
(CharSequence
the R2DBC URL.
url
)

Parses a R2DBC Connection URL and returns the parsed ConnectionFactoryOptions.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private static String
toString(Map<Option<?>, Object> options)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

CONNECT_TIMEOUTback to summary
public static final Option<Duration> CONNECT_TIMEOUT

Connection timeout.

DATABASEback to summary
public static final Option<String> DATABASE

Initial database name.

DRIVERback to summary
public static final Option<String> DRIVER

Driver name.

HOSTback to summary
public static final Option<String> HOST

Endpoint host name.

LOCK_WAIT_TIMEOUTback to summary
public static final Option<Duration> LOCK_WAIT_TIMEOUT

Lock timeout.

Since
0.9
optionsback to summary
private final Map<Option<?>, Object> options
PASSWORDback to summary
public static final Option<CharSequence> PASSWORD

Password for authentication.

PORTback to summary
public static final Option<Integer> PORT

Endpoint port number.

PROTOCOLback to summary
public static final Option<String> PROTOCOL

Driver protocol name. Typically represented as tcp or a database vendor-specific protocol string.

SSLback to summary
public static final Option<Boolean> SSL

Whether to require SSL.

STATEMENT_TIMEOUTback to summary
public static final Option<Duration> STATEMENT_TIMEOUT

Statement timeout.

Since
0.9
USERback to summary
public static final Option<String> USER

User for authentication.

Constructor Detail

ConnectionFactoryOptionsback to summary
private ConnectionFactoryOptions(Map<Option<?>, Object> options)

Method Detail

builderback to summary
public static ConnectionFactoryOptions.Builder builder()

Returns a new Builder.

Returns:ConnectionFactoryOptions.Builder

a new Builder

equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getRequiredValueback to summary
public Object getRequiredValue(Option<?> option)

Returns the value for an option if it exists.

Parameters
option:Option<?>

the option to retrieve the value for

Returns:Object

the value for an option

Exceptions
IllegalArgumentException:
if option is null
NoSuchOptionException:
if option is not configured or there is no value for option
getValueback to summary
public Object getValue(Option<?> option)

Returns the value for an option if it exists, otherwise null.

Parameters
option:Option<?>

the option to retrieve the value for

Returns:Object

the value for an option if it exists, otherwise null

Annotations
@Nullable
Exceptions
IllegalArgumentException:
if option is null
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
hasOptionback to summary
public boolean hasOption(Option<?> option)

Returns true if the option exists, otherwise false.

Parameters
option:Option<?>

the option to test for

Returns:boolean

true if the option exists, otherwise false

Exceptions
IllegalArgumentException:
if option is null
mutateback to summary
public ConnectionFactoryOptions.Builder mutate()

Returns a new Builder initialized with this ConnectionFactoryOptions.

Returns:ConnectionFactoryOptions.Builder

a new Builder

parseback to summary
public static ConnectionFactoryOptions parse(CharSequence url)

Parses a R2DBC Connection URL and returns the parsed ConnectionFactoryOptions. URL format: r2dbc:driver[:protocol]://[user:password@]host[:port][/path][?option=value]}.

Parameters
url:CharSequence

the R2DBC URL.

Returns:ConnectionFactoryOptions

the parsed ConnectionFactoryOptions.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
toStringback to summary
private static String toString(Map<Option<?>, Object> options)
io.r2dbc.spi back to summary

public final Class ConnectionFactoryOptions.Builder

extends Object
Class Inheritance

A builder for ConnectionFactoryOptions instances.

This class is not threadsafe

Field Summary

Modifier and TypeField and Description
private final Map<Option<?>, Object>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public ConnectionFactoryOptions

Returns:

a configured ConnectionFactoryOptions
build
()

Returns a configured ConnectionFactoryOptions.

public ConnectionFactoryOptions.Builder

Returns:

this Builder
from
(ConnectionFactoryOptions connectionFactoryOptions)

Populates the builder with the existing values from a configured ConnectionFactoryOptions.

public ConnectionFactoryOptions.Builder

Returns:

this Builder
from
(ConnectionFactoryOptions connectionFactoryOptions, Predicate<Option<?>>
a filter function to include/exclude existing Options.
filter
)

Populates the builder with the existing values from a configured ConnectionFactoryOptions allowing to filter which values to include.

public <
the type of the value
T
>
ConnectionFactoryOptions.Builder

Returns:

this Builder
option
(Option<T>
the Option to configure
option
,
T
the Option's value
value
)

Configure an Option value.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

optionsback to summary
private final Map<Option<?>, Object> options

Constructor Detail

Builderback to summary
private Builder()

Method Detail

buildback to summary
public ConnectionFactoryOptions build()

Returns a configured ConnectionFactoryOptions.

Returns:ConnectionFactoryOptions

a configured ConnectionFactoryOptions

fromback to summary
public ConnectionFactoryOptions.Builder from(ConnectionFactoryOptions connectionFactoryOptions)

Populates the builder with the existing values from a configured ConnectionFactoryOptions.

Parameters
connectionFactoryOptions:ConnectionFactoryOptions

a configured ConnectionFactoryOptions

Returns:ConnectionFactoryOptions.Builder

this Builder

Exceptions
IllegalArgumentException:
if connectionFactoryOptions is null
fromback to summary
public ConnectionFactoryOptions.Builder from(ConnectionFactoryOptions connectionFactoryOptions, Predicate<Option<?>> filter)

Populates the builder with the existing values from a configured ConnectionFactoryOptions allowing to filter which values to include.

Parameters
connectionFactoryOptions:ConnectionFactoryOptions

a configured ConnectionFactoryOptions

filter:Predicate<Option<?>>

a filter function to include/exclude existing Options.

Returns:ConnectionFactoryOptions.Builder

this Builder

Exceptions
IllegalArgumentException:
if connectionFactoryOptions or filter is null
optionback to summary
public <T> ConnectionFactoryOptions.Builder option(Option<T> option, T value)

Configure an Option value.

Parameters
<T>
the type of the value
option:Option<T>

the Option to configure

value:T

the Option's value

Returns:ConnectionFactoryOptions.Builder

this Builder

Exceptions
IllegalArgumentException:
if option or value are null
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override