oracle / oracle-r2dbc

R2DBC Driver for Oracle Database
https://oracle.com
Other
193 stars 40 forks source link

Option Values from Supplier and Publisher #137

Closed Michael-A-McMahon closed 8 months ago

Michael-A-McMahon commented 8 months ago

This branch allows a java.util.function.Supplier or an org.reactivestreams.Publisher to provide the value of an io.r2dbc.spi.Option. This is useful for values which change over time, such as a password which gets rotated, or an access token which gets refreshed. Users will no longer need to recreate their connection pool in order to update the value of an option. Instead, their Supplier or Publisher can provide updated values for new connections.

With a small number of exceptions, any Option can be configured to have a Supplier or Publisher provide the value. In order to call ConnectionFactoryOptions.Builder.option(Option, T) with T being a Supplier or Publisher, users must cast the generic type of the Option accordingly. For instance, if a user wants to call this method with ConnectionFactoryOptions.PASSWORD and a Supplier, then PASSWORD must be cast from an Option<CharSequence> to an Option<Supplier<CharSequence>>. New methods which perform these casts are added to the exported API of OracleR2dbcOptions.

Casting the generic type of an Option is safe so long as no other component besides Oracle R2DBC will consume that option's value. Casting is not safe for the DRIVER option, which is consumed as a String by io.r2dbc.ConnectionFactories. Casting is also not safe for the PROTOCOL option, which consumed as a String by r2dbc-pool.

In previous releases, Oracle R2DBC was specified to not retain any reference to any option's value after ConnectionFactories.create(ConnectionFactoryOptions) had returned. This specification does not apply if a Supplier or Publisher provides the value of at least one Option. In this case, references to all Option values are permanently retained by the ConnectionFactory. This limitation allows the implementation of this feature to remain fairly simple. If this limitation is not acceptable to users, then I will investigate alternative implementations which can resolve it.