Skip to content

Commit

Permalink
Merge 624b3ae into 3f4c6e1
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-slavchev committed Mar 16, 2020
2 parents 3f4c6e1 + 624b3ae commit 092a0ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,33 @@
*/
package io.opentracing.contrib.jdbc.parser;

import io.opentracing.contrib.jdbc.ConnectionInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.opentracing.contrib.jdbc.ConnectionInfo;

public class OracleURLParser implements ConnectionURLParser {
public static final String DB_TYPE = "oracle";
public static final String PREFIX = "jdbc:oracle:thin:";
public static final String PREFIX_THIN = "jdbc:oracle:thin:";
public static final String PREFIX_OCI = "jdbc:oracle:oci:";
public static final int DEFAULT_PORT = 1521;
private static Pattern EASY_CONNECT_PATTERN = Pattern.compile(
"(?<username>.*)@(//)?(?<host>[^:/]+)(?<port>:[0-9]+)?(?<service>[:/][^:/]+)?(?<server>:[^:/]+)?(?<instance>/[^:/]+)?");

@Override
public ConnectionInfo parse(final String url) {
if (url != null && url.startsWith(PREFIX)) {
OracleConnectionInfo connectionInfo = parseTnsName(url.substring(PREFIX.length()));
if (url != null && (url.startsWith(PREFIX_THIN) || url.startsWith(PREFIX_OCI))) {
String trimmedURL;
if (url.startsWith(PREFIX_THIN)) {
trimmedURL = url.substring(PREFIX_THIN.length());
} else {
trimmedURL = url.substring(PREFIX_OCI.length());
}
OracleConnectionInfo connectionInfo = parseTnsName(trimmedURL);
if (connectionInfo == null) {
connectionInfo = parseEasyConnect(url.substring(PREFIX.length()));
connectionInfo = parseEasyConnect(trimmedURL);
}
if (connectionInfo != null) {
return new ConnectionInfo.Builder(connectionInfo.getDbPeer()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ private static Stream<Arguments> easyConnectUrls() {
Arguments.of("jdbc:oracle:thin:@localhost:1234/XEPDB1", "localhost:1234", "XEPDB1"), //
Arguments.of("jdbc:oracle:thin:@//localhost:1234/XEPDB1", "localhost:1234", "XEPDB1"), //
Arguments.of("jdbc:oracle:thin:@//localhost:1234/XEPDB1:server/instance", "localhost:1234",
"XEPDB1") //
"XEPDB1"), //
Arguments.of("jdbc:oracle:oci:@//localhost:1234/XEPDB1:server/instance", "localhost:1234",
"XEPDB1") //
);
}

Expand All @@ -46,6 +48,9 @@ private static Stream<Arguments> tnsNameUrls() {
"localhost:1521", "orcl"), //
Arguments
.of("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL= TCP)(HOST=hostA)(PORT= 1523 ))(ADDRESS=(PROTOCOL=TCP)(HOST=hostB)(PORT= 1521 )))(SOURCE_ROUTE=yes)(CONNECT_DATA=(SERVICE_NAME=orcl)))",
"hostA:1523,hostB:1521", "orcl"), //
Arguments
.of("jdbc:oracle:oci:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL= TCP)(HOST=hostA)(PORT= 1523 ))(ADDRESS=(PROTOCOL=TCP)(HOST=hostB)(PORT= 1521 )))(SOURCE_ROUTE=yes)(CONNECT_DATA=(SERVICE_NAME=orcl)))",
"hostA:1523,hostB:1521", "orcl") //
);
}
Expand All @@ -56,7 +61,8 @@ private static Stream<Arguments> otherUrls() {
Arguments.of("jdbc:oracle:thin:@localhost:1522:orcl", "localhost:1522", "orcl"), //
Arguments.of("jdbc:oracle:thin:@//localhost:1521/orcl", "localhost:1521", "orcl"), //
Arguments.of("jdbc:oracle:thin:scott/tiger@myhost:1521:orcl", "myhost:1521", "orcl"), //
Arguments.of("jdbc:oracle:thin:@orcl", "orcl:1521", "orcl") //
Arguments.of("jdbc:oracle:thin:@orcl", "orcl:1521", "orcl"), //
Arguments.of("jdbc:oracle:oci:@orcl", "orcl:1521", "orcl") //
);
}

Expand Down

0 comments on commit 092a0ec

Please sign in to comment.