-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Apply simple filtering of the query string passed through to real database drivers #357
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,7 +145,8 @@ public synchronized Connection connect(String url, final Properties info) throws | |
/* | ||
Create a connection using the delegated driver. The container must be ready to accept connections. | ||
*/ | ||
Connection connection = container.createConnection(queryString); | ||
String filteredQueryString = getQueryStringWithoutTCParams(queryString); | ||
Connection connection = container.createConnection(filteredQueryString); | ||
|
||
/* | ||
If this container has not been initialized, AND | ||
|
@@ -175,6 +176,14 @@ private Map<String, String> getContainerParameters(String url) { | |
return results; | ||
} | ||
|
||
private String getQueryStringWithoutTCParams(String queryString) { | ||
return TC_PARAM_MATCHING_PATTERN.matcher(queryString) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we just re-create URL without TC_ query parameters? |
||
.replaceAll("") | ||
.replaceAll("\\?&", "?") | ||
.replaceAll("&&", "&") | ||
.replaceAll("[?&]$", ""); | ||
} | ||
|
||
/** | ||
* Wrap the connection, setting up a callback to be called when the connection is closed. | ||
* <p> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this test isn't adding any verification of the actual implementation, since the tests will succeed even if I change the code in
ContainerDatabaseDriver
to the original implementation.TBH I don't have a better idea to test matching and building the JDBC url but refactoring this component out into it's own class and unit testing it. If you like I can take on this work and also switch to using an URL builder like @bsideup suggested.
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.
Yes, fair point - I'll have a bit more of a think about it, and probably break out into a unit test.
I do have a branch for refactoring towards the Apache URL parser, but I'm not quite happy with it yet. It was the same amount of code (or actually I think a few more lines), and ends up mixing the two URL parsing approaches anyway. We probably shouldn't use both. IIRC I originally used regexes because JDBC URLs couldn't be parsed (colon in scheme part), but I could be wrong. I may have just been using the JRE URL parsing libs; perhaps the Apache library can handle it though.
I'll have a try!