Skip to content

Commit

Permalink
Add support for informix connection string parsing in jdbc instrument…
Browse files Browse the repository at this point in the history
…ation (#11542)

Co-authored-by: Lauri Tulmin <[email protected]>
  • Loading branch information
jaydeluca and laurit authored Jun 12, 2024
1 parent 40cea5e commit 687cffe
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,62 @@ DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {

return MODIFIED_URL_LIKE.doParse(jdbcUrl, builder);
}
},
INFORMIX_SQLI("informix-sqli") {
private static final int DEFAULT_PORT = 9088;

@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
builder = MODIFIED_URL_LIKE.doParse(jdbcUrl, builder);

DbInfo dbInfo = builder.build();
if (dbInfo.getPort() == null) {
builder.port(DEFAULT_PORT);
}

int hostIndex = jdbcUrl.indexOf("://");
if (hostIndex == -1) {
return builder;
}

int dbNameStartIndex = jdbcUrl.indexOf('/', hostIndex + 3);
if (dbNameStartIndex == -1) {
return builder;
}
int dbNameEndIndex = jdbcUrl.indexOf(':', dbNameStartIndex);
if (dbNameEndIndex == -1) {
dbNameEndIndex = jdbcUrl.length();
}
String name = jdbcUrl.substring(dbNameStartIndex + 1, dbNameEndIndex);
if (name.isEmpty()) {
builder.name(null);
} else {
builder.name(name);
}

return builder;
}
},

INFORMIX_DIRECT("informix-direct") {
private final Pattern pattern = Pattern.compile("://(.*?)(:|;|$)");

@Override
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
builder = MODIFIED_URL_LIKE.doParse(jdbcUrl, builder);
builder.host(null);
builder.port(null);

Matcher matcher = pattern.matcher(jdbcUrl);
if (matcher.find()) {
String name = matcher.group(1);
if (!name.isEmpty()) {
builder.name(name);
}
}

return builder;
}
};

private static final Logger logger = Logger.getLogger(JdbcConnectionUrlParser.class.getName());
Expand Down Expand Up @@ -998,6 +1054,10 @@ private static String toDbSystem(String type) {
return DbSystemValues.H2;
case "hsqldb": // Hyper SQL Database
return "hsqldb";
case "informix-sqli": // IBM Informix
return DbSystemValues.INFORMIX_SQLI;
case "informix-direct":
return DbSystemValues.INFORMIX_DIRECT;
case "mariadb": // MariaDB
return DbSystemValues.MARIADB;
case "mysql": // MySQL
Expand All @@ -1024,6 +1084,8 @@ private static final class DbSystemValues {
static final String MYSQL = "mysql";
static final String ORACLE = "oracle";
static final String DB2 = "db2";
static final String INFORMIX_SQLI = "informix-sqli";
static final String INFORMIX_DIRECT = "informix-direct";
static final String POSTGRESQL = "postgresql";
static final String HANADB = "hanadb";
static final String DERBY = "derby";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,63 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
.setDb("sapdb")
.build(),

// https://www.ibm.com/support/pages/how-configure-informix-jdbc-connection-string-connect-group
arg("jdbc:informix-sqli://infxhost:99/infxdb:INFORMIXSERVER=infxsn;user=infxuser;password=PW")
.setSystem("informix-sqli")
.setUser("infxuser")
.setShortUrl("informix-sqli://infxhost:99")
.setHost("infxhost")
.setPort(99)
.setName("infxdb")
.build(),
arg("jdbc:informix-sqli://localhost:9088/stores_demo:INFORMIXSERVER=informix")
.setSystem("informix-sqli")
.setShortUrl("informix-sqli://localhost:9088")
.setHost("localhost")
.setPort(9088)
.setName("stores_demo")
.build(),
arg("jdbc:informix-sqli://infxhost:99")
.setSystem("informix-sqli")
.setShortUrl("informix-sqli://infxhost:99")
.setHost("infxhost")
.setPort(99)
.build(),
arg("jdbc:informix-sqli://infxhost/")
.setSystem("informix-sqli")
.setShortUrl("informix-sqli://infxhost:9088")
.setHost("infxhost")
.setPort(9088)
.build(),
arg("jdbc:informix-sqli:")
.setSystem("informix-sqli")
.setShortUrl("informix-sqli:")
.setPort(9088)
.build(),

// https://www.ibm.com/docs/en/informix-servers/12.10?topic=method-format-database-urls
arg("jdbc:informix-direct://infxdb:999;user=infxuser;password=PW")
.setSystem("informix-direct")
.setShortUrl("informix-direct:")
.setUser("infxuser")
.setName("infxdb")
.build(),
arg("jdbc:informix-direct://infxdb;user=infxuser;password=PW")
.setSystem("informix-direct")
.setShortUrl("informix-direct:")
.setUser("infxuser")
.setName("infxdb")
.build(),
arg("jdbc:informix-direct://infxdb")
.setSystem("informix-direct")
.setShortUrl("informix-direct:")
.setName("infxdb")
.build(),
arg("jdbc:informix-direct:")
.setSystem("informix-direct")
.setShortUrl("informix-direct:")
.build(),

// http://www.h2database.com/html/features.html#database_url
arg("jdbc:h2:mem:").setShortUrl("h2:mem:").setSystem("h2").setSubtype("mem").build(),
arg("jdbc:h2:mem:")
Expand Down

0 comments on commit 687cffe

Please sign in to comment.