-
Notifications
You must be signed in to change notification settings - Fork 73
feat: introduce target driver dialects #452
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
Conversation
de7b877 to
bb64f60
Compare
wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/PgDataSourceHelper.java
Outdated
Show resolved
Hide resolved
| customProps.setProperty(urlPropertyName, finalUrl); | ||
| } | ||
|
|
||
| LOGGER.finest(() -> PropertyUtils.logProperties(customProps, "Connecting with properties: \n")); |
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.
Can we log the properties and the url in one message? It helps the debugging process in multithreaded applications
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.
Hmm they are different properties. Url may be missed. Let's find a separate solution for multithreaded logs.
wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbDataSourceHelper.java
Outdated
Show resolved
Hide resolved
wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/PgTargetDriverDialect.java
Outdated
Show resolved
Hide resolved
| final @Nullable String databasePropertyName) throws SQLException { | ||
|
|
||
| // The logic is isolated to a separated class since it uses | ||
| // direct reference to org.postgresql.ds.common.BaseDataSource |
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.
Referring to the code comments above, is the idea to decouple the Dialect class from org.postgresql.ds.common.BaseDataSource?
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.
That's correct. The idea is to decouple different dialect classes. Since PgTargetDriverDialect is instantiated in TargetDriverDialectManager, it's impossible to use any classes from org.postgresql package in PgTargetDriverDialect. In this case AWS JDBC Driver would have a dependency on org.postgresql package. That's why all logic is isolated in PgDataSourceHelper class. This helper class has direct references to org.postgresql package but it's instantiated when it's needed only, i.e. when the target driver is actually pgjdbc driver.
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.
Thank you for the explanation!
7f06bff to
8039457
Compare
documentation jacoco min coverage code style fix issue with MariaDb driver for Mysql protocol add checkstyle import exceptions introduce target driver dialects
8039457 to
38abe6f
Compare
| * Dialect objects are shared between different connections. | ||
| * The order of entries in this map is the order in which dialects are called/verified. | ||
| */ | ||
| protected static final Map<String, TargetDriverDialect> knownDialectsByCode = |
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: would it be better to have this mapping located in the TargetDriverDialectCodes class? That way if a new dialect is introduced, it is one less class that needs to be updated, and it is harder for the developer to forget updating this mapping.
Also sorry about the lateness of the comment.
| */ | ||
| @Deprecated | ||
| Connection connect(@NonNull String url, @NonNull Properties props) | ||
| throws SQLException; // TODO: this method is only called by tests/benchmarks and can likely be deprecated |
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.
Should we remove the comment now that this is deprecated or no?
wrapper/src/main/java/software/amazon/jdbc/PropertyDefinition.java
Outdated
Show resolved
Hide resolved
| Throwable exception = throwable; | ||
|
|
||
| while (exception != null) { | ||
| if (exception instanceof SQLLoginException) { |
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: should we move this check to isLoginException?
| protected PluginService pluginService; | ||
|
|
||
| static { | ||
| PropertyDefinition.registerPluginProperties(AwsSecretsManagerConnectionPlugin.class); |
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.
Would it work to register the properties for all available plugins automatically in the ConnectionPluginManager so that we don't need to add this block to every plugin? Might not be necessary but it would be nice to avoid the need to add this to every plugin if possible
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.
Registering properties is direct responsibility of a particular plugin. Register properties for all know plugins in ConnectionPluginManager doesn't look like direct responsibilities of the this class. Also, such approach doesn't cover user custom plugins. I'd prefer to let plugins be responsible for such registration.
| } | ||
|
|
||
| if (hostSpec.isPortSpecified() && !isNullOrEmpty(portPropertyName)) { | ||
| customProps.put(portPropertyName, hostSpec.getPort()); |
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.
should this be setProperty instead of put?
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.
Technically it's the same call to put(). I'll fix it for consistency.
wrapper/src/main/java/software/amazon/jdbc/targetdriverdialect/MariadbTargetDriverDialect.java
Outdated
Show resolved
Hide resolved
| public class TargetDriverDialectCodes { | ||
| public static final String PG_JDBC = "pgjdbc"; | ||
| public static final String MYSQL_CONNECTOR_J = "mysql-connector-j"; | ||
| public static final String MARIADB_CONNECTOR_J_VER_3 = "mariadb-connector-j-3"; // ver 3.0.3+ |
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.
just curious, why do we need the version in this string?
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.
There's a chance that different versions of the same driver may require different dialects. MariaDb driver changed behaviour in version 3+. So I think it makes sense to be explicit in defining dialect codes.
Summary
Introduce target driver dialects
Additional Reviewers
@karenc-bq
@aaron-congo
@davecramer
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.