-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user to set up a lambda to initialize new connections #705
Conversation
docs ? |
c08bdea
to
36d9337
Compare
36d9337
to
c4b9c6d
Compare
|
||
ConnectionProviderManager.setConnectionInitFunc((connection, protocol, hostSpec, props) -> { | ||
if ("test-database".equals(props.getProperty("database"))) { | ||
connection.setSchema("test-database-schema"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: assert schema is set for the connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops. That's not supposed to be here.
### Connection Initialization | ||
In some cases it's necessary to configure a connection before a user application can use it. Some target drivers provides such functionality and allow to specify a configuration parameter with SQL statements that are executed when connection is established. However, not all drivers supports such functionality. Also, in some cases, additional conditions should be checked in order to identify what initialization is required for a particular connection. | ||
|
||
AWS JDBC Driver allows to specify a special function that can initialize a connection. It can be done with `ConnectionProviderManager.setConnectionInitFunc` method. `resetConnectionInitFunc` method is also available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AWS JDBC Driver allows users to specify a specific function that will be executed every time a connection is initialized. This function needs to be wrapped in a ConnectionInitFunc
object, that implements the initConnection()
method. Once that object is defined, it is passed to the driver using the ConnectionProviderManager.setConnectionInitFunc
method.
It is also possible to stop/reset executing this function by using the resetConnectionInitFunc
method.
> :warning: Executing CPU and network intensive code in the initialization function may cause significant performance degradation. | ||
|
||
```java | ||
ConnectionProviderManager.setConnectionInitFunc((connection, protocol, hostSpec, props) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: let's also add a case without a lambda
@@ -100,6 +100,25 @@ DriverConfigurationProfiles.addOrReplaceProfile( | |||
CustomConnectionPluginFactory.class)); | |||
``` | |||
|
|||
### Connection Initialization | |||
In some cases it's necessary to configure a connection before a user application can use it. Some target drivers provides such functionality and allow to specify a configuration parameter with SQL statements that are executed when connection is established. However, not all drivers supports such functionality. Also, in some cases, additional conditions should be checked in order to identify what initialization is required for a particular connection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some particular cases, users may need to define a specific configuration for a connection that has just been opened by the driver before an application can use it.
Some...
c4b9c6d
to
4d001b6
Compare
Co-authored-by: crystall-bitquill <[email protected]>
Co-authored-by: crystall-bitquill <[email protected]>
Co-authored-by: crystall-bitquill <[email protected]>
Co-authored-by: Karen <[email protected]>
Co-authored-by: Karen <[email protected]>
Co-authored-by: Karen <[email protected]>
Summary
Allow user to set up a lambda to initialize new connections.
Description
User needs to set an connection initialization function with ConnectionProviderManager.setConnectionInitFunc()
Related to #679
Additional Reviewers
@karenc-bq
@crystall-bitquill
@brunos-bq
@aaronchung-bitquill
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.