-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jdbc): Address issues with manual backport of "MySQL ConnectorJ a…
…nd use MariaDb instead" (#2507) * feat(jdbc): Remove MySQL ConnectorJ and use MariaDb instead Backporting from #2502 * feat(jdbc): Remove MySQL ConnectorJ and use MariaDb instead Backporting from #2502
- Loading branch information
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
connectors/jdbc/src/main/java/io/camunda/connector/jdbc/utils/ConnectionParameterHelper.java
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
package io.camunda.connector.jdbc.utils; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
/** | ||
* Helper class to add parameters to a URL. Parameters values can be added to the URL as well, but | ||
* it is optional. | ||
* | ||
* @see ConnectionParameterHelperTest for usage examples. | ||
*/ | ||
public class ConnectionParameterHelper { | ||
|
||
public static String addQueryParameterToURL(String urlString, String paramName) | ||
throws URISyntaxException { | ||
return addQueryParameterToURL(urlString, paramName, null); | ||
} | ||
|
||
public static String addQueryParameterToURL(String urlString, String paramName, String paramValue) | ||
throws URISyntaxException { | ||
URI uri = new URI(urlString); | ||
// Check if the URL already has query parameters | ||
int queryParamsIndex = urlString.indexOf('?'); | ||
String query; | ||
if (queryParamsIndex == -1) { | ||
// No query parameters | ||
query = "?"; | ||
} else { | ||
// Query parameters already exist let's add the new one | ||
query = "&"; | ||
} | ||
query += paramName; | ||
// Value is optional | ||
if (paramValue != null) { | ||
query += "=" + paramValue; | ||
} | ||
// jdbc:mysql//localhost:3306?paramName=paramValue for instance is not detected as a regular | ||
// URI, | ||
// so we need to reconstruct the URI using the scheme and the scheme specific part | ||
return new URI(uri.getScheme() + ":" + uri.getSchemeSpecificPart() + query).toString(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...ors/jdbc/src/test/java/io/camunda/connector/jdbc/utils/ConnectionParameterHelperTest.java
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
package io.camunda.connector.jdbc.utils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ConnectionParameterHelperTest { | ||
@Test | ||
void shouldCreateQueryParameters_whenNoExistingQueryParameters() throws Exception { | ||
String urlString = "jdbc:mysql//localhost:3306"; | ||
String paramName = "paramName"; | ||
String paramValue = "paramValue"; | ||
String result = | ||
ConnectionParameterHelper.addQueryParameterToURL(urlString, paramName, paramValue); | ||
assertThat(result).isEqualTo(urlString + "?paramName=paramValue"); | ||
} | ||
|
||
@Test | ||
void shouldNotCreateQueryParameters_whenExistingQueryParameters() throws Exception { | ||
String urlString = "jdbc:mysql//localhost:3306?existingParam=existingValue"; | ||
String paramName = "paramName"; | ||
String paramValue = "paramValue"; | ||
String result = | ||
ConnectionParameterHelper.addQueryParameterToURL(urlString, paramName, paramValue); | ||
assertThat(result).isEqualTo(urlString + "¶mName=paramValue"); | ||
} | ||
|
||
@Test | ||
void shouldCreateQueryParameters_whenNoParamValue() throws Exception { | ||
String urlString = "jdbc:mysql//localhost:3306"; | ||
String paramName = "paramName"; | ||
String result = ConnectionParameterHelper.addQueryParameterToURL(urlString, paramName); | ||
assertThat(result).isEqualTo(urlString + "?paramName"); | ||
} | ||
|
||
@Test | ||
void shouldCreateQueryParameters_whenNoParamValueAndExistingQueryParameters() throws Exception { | ||
String urlString = "jdbc:mysql//localhost:3306?existingParam=existingValue"; | ||
String paramName = "paramName"; | ||
String result = ConnectionParameterHelper.addQueryParameterToURL(urlString, paramName); | ||
assertThat(result).isEqualTo(urlString + "¶mName"); | ||
} | ||
|
||
@Test | ||
void shouldCreateQueryParametersAfterPath_whenQueryPathExistsAndNoParamValue() throws Exception { | ||
String urlString = "jdbc:mysql//localhost:3306/database"; | ||
String paramName = "paramName"; | ||
String result = ConnectionParameterHelper.addQueryParameterToURL(urlString, paramName); | ||
assertThat(result).isEqualTo(urlString + "?paramName"); | ||
} | ||
|
||
@Test | ||
void shouldCreateQueryParametersAfterPath_whenQueryPathExistsAndQueryParametersExist() | ||
throws Exception { | ||
String urlString = "jdbc:mysql//localhost:3306/database?existingParam=existingValue"; | ||
String paramName = "paramName"; | ||
String result = ConnectionParameterHelper.addQueryParameterToURL(urlString, paramName); | ||
assertThat(result).isEqualTo(urlString + "¶mName"); | ||
} | ||
|
||
@Test | ||
void shouldCreateQueryParametersAfterPath_whenEmptyPath() throws Exception { | ||
String urlString = "jdbc:mysql//localhost:3306/"; | ||
String paramName = "paramName"; | ||
String result = ConnectionParameterHelper.addQueryParameterToURL(urlString, paramName); | ||
assertThat(result).isEqualTo(urlString + "?paramName"); | ||
} | ||
} |