Skip to content
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

Fix connection url for Oracle and SqlServer #83

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void process(Environment environment, Bindings bindings, Map<String, Obje
map.from("username").to("spring.datasource.username");
map.from("password").to("spring.datasource.password");
map.from("host", "port", "database").to("spring.datasource.url",
(host, port, database) -> String.format("jdbc:oracle://%s:%s/%s", host, port, database));
(host, port, database) -> String.format("jdbc:oracle:thin:@%s:%s/%s", host, port, database));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I commented in #82 (comment), this is incomplete

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is incomplete. But the old code doesn't work in any scenario. I just changed it to work in certain scenarios.
It is not possible to cover all the scenarios. Users will have to use jdbc-url in these cases.

If it is necessary to cover the three connection types (i.e. SID, Service Name, TNS), which key should the user use to specify the connection type?
If the users don't specify the connection type via service binding, the code will not be able to determine what is the connection type.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jdbc:oracle:thin:@%s:%s/%s

Did you mean jdbc:oracle:thin:@//%s:%s/%s (service name) or jdbc:oracle:thin:@%s:%s:%s (sid) ?

I think it's good to introduce new keys connection-type (default sevice name or sid) and driver (default thin)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the code to cover scenarios for sid, service name and tns. Please take a look. Thanks.


// jdbcURL takes precedence
map.from("jdbc-url").to("spring.datasource.url");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void process(Environment environment, Bindings bindings, Map<String, Obje
//jdbc properties
map.from("password").to("spring.datasource.password");
map.from("host", "port", "database").to("spring.datasource.url",
(host, port, database) -> String.format("jdbc:sqlserver://%s:%s/%s", host, port, database));
(host, port, database) -> String.format("jdbc:sqlserver://%s:%s;databaseName=%s", host, port, database));
map.from("username").to("spring.datasource.username");

// jdbcURL takes precedence
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void testJdbc() {
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "oracle.jdbc.OracleDriver")
.containsEntry("spring.datasource.password", "test-password")
.containsEntry("spring.datasource.url", "jdbc:oracle://test-host:test-port/test-database")
.containsEntry("spring.datasource.url", "jdbc:oracle:thin:@test-host:test-port/test-database")
.containsEntry("spring.datasource.username", "test-username");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void testJdbc() {
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
.containsEntry("spring.datasource.password", "test-password")
.containsEntry("spring.datasource.url", "jdbc:sqlserver://test-host:test-port/test-database")
.containsEntry("spring.datasource.url", "jdbc:sqlserver://test-host:test-port;databaseName=test-database")
.containsEntry("spring.datasource.username", "test-username");
}

Expand Down