Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 @@ -911,6 +911,72 @@ DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
}
return GENERIC_URL_LIKE.doParse(clickhouseUrl, builder);
}
},
/** jdbc:oceanbase://host:port/dbname jdbc:oceanbase:oracle://host:port/dbname */
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps change the comment to

  /**
   * Sample urls:
   *
   * <ul>
   *   <li>jdbc:oceanbase://host:port/dbname
   *   <li>jdbc:oceanbase:oracle://host:port/dbname
   * </ul>
   */

OCEANBASE("oceanbase") {
@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
int protoLoc = jdbcUrl.indexOf("://");
int typeEndLoc = jdbcUrl.indexOf(':');
if (protoLoc > typeEndLoc) {
String subtype = jdbcUrl.substring(typeEndLoc + 1, protoLoc);
builder.subtype(subtype);
if (subtype.equals(DbSystemValues.ORACLE)) {
builder.system(DbSystemValues.ORACLE);
Copy link
Contributor

Choose a reason for hiding this comment

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

is oracle the only supported subtype?

}
Comment on lines +924 to +926
Copy link
Contributor

Choose a reason for hiding this comment

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

initially I though that it is weird to have subtype and system set to the same value but DATADIRECT url handling does the same

return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder);
} else {
return GENERIC_URL_LIKE.doParse(jdbcUrl, builder);
}
}
},
/**
* <a
* href="https://www.alibabacloud.com/help/en/lindorm/user-guide/view-endpoints?spm=a2c63.p38356.help-menu-172543.d_2_0_1.7a1e41feMntzyJ">Driver
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* href="https://www.alibabacloud.com/help/en/lindorm/user-guide/view-endpoints?spm=a2c63.p38356.help-menu-172543.d_2_0_1.7a1e41feMntzyJ">Driver
* href="https://www.alibabacloud.com/help/en/lindorm/user-guide/view-endpoints">Driver

Copy link
Author

Choose a reason for hiding this comment

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

deleted

Copy link
Contributor

Choose a reason for hiding this comment

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

deleted

did you forget to actually delete the url parameters?

* configuration doc</a> jdbc:lindorm:table:url=http//server_name:30060/test
* jdbc:lindorm:tsdb:url=http://server_name:8242/test
* jabc:lindorm:search:url=http://server_name:30070/test
*/
LINDORM("lindorm") {
private static final String DEFAULT_HOST = "localhost";
private static final int DEFAULT_PORT = 30060;

@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
String lindormUrl = jdbcUrl.substring("lindorm:".length());
DbInfo dbInfo = builder.build();
if (dbInfo.getHost() == null) {
builder.host(DEFAULT_HOST);
}
if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT);
}

int urlIndex = lindormUrl.indexOf(":url=");
if (urlIndex < 0) {
return builder;
}
builder.subtype(lindormUrl.substring(0, urlIndex));
String realUrl = lindormUrl.substring(urlIndex + 5);
return GENERIC_URL_LIKE.doParse(realUrl, builder);
}
},
/** jdbc:polardb://server_name:1901/dbname */
POLARDB("polardb") {
private static final int DEFAULT_PORT = 1521;
private static final String DEFAULT_HOST = "localhost";

@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
DbInfo dbInfo = builder.build();
if (dbInfo.getHost() == null) {
builder.host(DEFAULT_HOST);
}
if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT);
}
return GENERIC_URL_LIKE.doParse(jdbcUrl, builder);
}
};

private static final Logger logger = Logger.getLogger(JdbcConnectionUrlParser.class.getName());
Expand Down Expand Up @@ -943,8 +1009,13 @@ public static DbInfo parse(String connectionUrl, Properties props) {
connectionUrl = connectionUrl.toLowerCase(Locale.ROOT);

String jdbcUrl;
if (connectionUrl.startsWith("jdbc:")) {
if (connectionUrl.startsWith("jdbc:tracing:")) {
// see https://github.com/opentracing-contrib/java-jdbc
jdbcUrl = connectionUrl.substring("jdbc:tracing:".length());
} else if (connectionUrl.startsWith("jdbc:")) {
jdbcUrl = connectionUrl.substring("jdbc:".length());
} else if (connectionUrl.startsWith("jdbc-secretsmanager:tracing:")) {
jdbcUrl = connectionUrl.substring("jdbc-secretsmanager:tracing:".length());
} else if (connectionUrl.startsWith("jdbc-secretsmanager:")) {
jdbcUrl = connectionUrl.substring("jdbc-secretsmanager:".length());
} else {
Expand Down Expand Up @@ -1100,6 +1171,12 @@ private static String toDbSystem(String type) {
return DbSystemValues.HANADB;
case "clickhouse": // ClickHouse
return DbSystemValues.CLICKHOUSE;
case "oceanbase": // Oceanbase
return DbSystemValues.OCEANBASE;
case "polardb": // PolarDB
return DbSystemValues.POLARDB;
case "lindorm": // Lindorm
return DbSystemValues.LINDORM;
default:
return DbSystemValues.OTHER_SQL; // Unknown DBMS
}
Expand All @@ -1120,6 +1197,9 @@ private static final class DbSystemValues {
static final String MARIADB = "mariadb";
static final String H2 = "h2";
static final String CLICKHOUSE = "clickhouse";
static final String OCEANBASE = "oceanbase";
static final String POLARDB = "polardb";
static final String LINDORM = "lindorm";

private DbSystemValues() {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,127 @@ void testSecretsManagerParsing(ParseTestArgument argument) {
testVerifySystemSubtypeParsingOfUrl(argument);
}

private static Stream<Arguments> openTracingArguments() {
return args(
// https://github.com/opentracing-contrib/java-jdbc
arg("jdbc:tracing:mysql://example.com:50000")
.setShortUrl("mysql://example.com:50000")
.setSystem("mysql")
.setHost("example.com")
.setPort(50000)
.build(),
arg("jdbc:tracing:postgresql://example.com:50000/dbname")
.setShortUrl("postgresql://example.com:50000")
.setSystem("postgresql")
.setHost("example.com")
.setPort(50000)
.setDb("dbname")
.build(),
arg("jdbc:tracing:oracle:thin:@example.com:50000/ORCL")
.setShortUrl("oracle:thin://example.com:50000")
.setSystem("oracle")
.setSubtype("thin")
.setHost("example.com")
.setPort(50000)
.setName("orcl")
.build(),
arg("jdbc:tracing:sqlserver://example.com:50000")
.setShortUrl("sqlserver://example.com:50000")
.setSystem("mssql")
.setHost("example.com")
.setPort(50000)
.build());
}

@ParameterizedTest(name = "{index}: {0}")
@MethodSource("openTracingArguments")
void testOpenTracingParsing(ParseTestArgument argument) {
testVerifySystemSubtypeParsingOfUrl(argument);
}

private static Stream<Arguments> oceanbaseArguments() {
return args(
// https://en.oceanbase.com/
arg("jdbc:oceanbase://host:3306/test")
.setShortUrl("oceanbase://host:3306")
.setSystem("oceanbase")
.setHost("host")
.setPort(3306)
.setDb("test")
.build(),
arg("jdbc:oceanbase:oracle://host:1521")
.setShortUrl("oceanbase:oracle://host:1521")
.setSystem("oracle")
.setSubtype("oracle")
.setHost("host")
.setPort(1521)
.build());
}

@ParameterizedTest(name = "{index}: {0}")
@MethodSource("oceanbaseArguments")
void testOceasbaseParsing(ParseTestArgument argument) {
testVerifySystemSubtypeParsingOfUrl(argument);
}

private static Stream<Arguments> lindormArguments() {
return args(
// https://www.alibabacloud.com/help/en/lindorm/user-guide/view-endpoints
arg("jdbc:lindorm:table:url=http://host:30060/test")
.setShortUrl("lindorm:table://host:30060")
.setSystem("lindorm")
.setSubtype("table")
.setHost("host")
.setDb("test")
.setPort(30060)
.build(),
arg("jdbc:lindorm:tsdb:url=http://host:8242/test")
.setShortUrl("lindorm:tsdb://host:8242")
.setSystem("lindorm")
.setSubtype("tsdb")
.setHost("host")
.setDb("test")
.setPort(8242)
.setDb("test")
.build(),
arg("jdbc:lindorm:search:url=http://host:30070/test")
.setShortUrl("lindorm:search://host:30070")
.setSystem("lindorm")
.setSubtype("search")
.setHost("host")
.setDb("test")
.setPort(30070)
.build());
}

@ParameterizedTest(name = "{index}: {0}")
@MethodSource("lindormArguments")
void testLindormManagerParsing(ParseTestArgument argument) {
testVerifySystemSubtypeParsingOfUrl(argument);
}

private static Stream<Arguments> polardbArguments() {
return args(
arg("jdbc:polardb://example.com:1901")
.setShortUrl("polardb://example.com:1901")
.setSystem("polardb")
.setHost("example.com")
.setPort(1901)
.build(),
arg("jdbc:polardb://example.com")
.setShortUrl("polardb://example.com:1521")
.setSystem("polardb")
.setHost("example.com")
.setPort(1521)
.build());
}

@ParameterizedTest(name = "{index}: {0}")
@MethodSource("polardbArguments")
void testPolardbParsing(ParseTestArgument argument) {
testVerifySystemSubtypeParsingOfUrl(argument);
}

private static void testVerifySystemSubtypeParsingOfUrl(ParseTestArgument argument) {
DbInfo info = parse(argument.url, argument.properties);
DbInfo expected = argument.dbInfo;
Expand Down
Loading