-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jdbc): Remove MySQL ConnectorJ and use MariaDb instead (#2502)
* feat(jdbc): Remove MySQL ConnectorJ and use MariaDb instead * feat(jdbc): Fix license text * feat(jdbc): Refacotr Using variables --------- Co-authored-by: Ev <[email protected]>
- Loading branch information
Showing
6 changed files
with
166 additions
and
36 deletions.
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
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
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(); | ||
} | ||
} |
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
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"); | ||
} | ||
} |