Java Code Examples for io.opentracing.contrib.jdbc.ConnectionInfo

The following examples show how to use io.opentracing.contrib.jdbc.ConnectionInfo. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: java-jdbc   Source File: URLParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * parse the url to the ConnectionInfo
 */
public static ConnectionInfo parse(String url) {
  if (null == url) {
    return ConnectionInfo.UNKNOWN_CONNECTION_INFO;
  }
  String lowerCaseUrl = url.toLowerCase();
  ConnectionURLParser parser = findURLParser(lowerCaseUrl);
  if (parser == null) {
    return ConnectionInfo.UNKNOWN_CONNECTION_INFO;
  }
  try {
    return parser.parse(url);
  } catch (Exception e) {
    log.log(Level.WARNING, "error occurs when parsing jdbc url");
  }
  return ConnectionInfo.UNKNOWN_CONNECTION_INFO;
}
 
Example 2
Source Project: java-jdbc   Source File: OracleURLParser.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public ConnectionInfo parse(final String url) {
  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(trimmedURL);
    }
    if (connectionInfo != null) {
      return new ConnectionInfo.Builder(connectionInfo.getDbPeer()) //
          .dbType(DB_TYPE) //
          .dbInstance(connectionInfo.getDbInstance()) //
          .build();
    }
  }
  return null;
}
 
Example 3
Source Project: java-jdbc   Source File: MysqlURLParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectionInfo parse(String url) {
  URLLocation location = fetchDatabaseHostsIndexRange(url);
  String hosts = url.substring(location.startIndex(), location.endIndex());
  String[] hostSegment = hosts.split(",");
  if (hostSegment.length > 1) {
    StringBuilder sb = new StringBuilder();
    for (String host : hostSegment) {
      if (host.split(":").length == 1) {
        sb.append(host + ":" + DEFAULT_PORT + ",");
      } else {
        sb.append(host + ",");
      }
    }
    if (',' == sb.charAt(sb.length() - 1)) {
      sb.deleteCharAt(sb.length() - 1);
    }
    return new ConnectionInfo.Builder(sb.toString()).dbType(dbType())
        .dbInstance(fetchDatabaseNameFromURL(url)).build();
  } else {
    String[] hostAndPort = hostSegment[0].split(":");
    if (hostAndPort.length != 1) {
      return new ConnectionInfo.Builder(hostAndPort[0], Integer.valueOf(hostAndPort[1]))
          .dbType(dbType()).dbInstance(fetchDatabaseNameFromURL(url, location.endIndex()))
          .build();
    } else {

      return new ConnectionInfo.Builder(hostAndPort[0], DEFAULT_PORT).dbType(dbType())
          .dbInstance(fetchDatabaseNameFromURL(url, location.endIndex())).build();
    }
  }
}
 
Example 4
Source Project: java-jdbc   Source File: PostgreSQLURLParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectionInfo parse(String url) {
  URLLocation location = fetchDatabaseHostsIndexRange(url);
  String hosts = url.substring(location.startIndex(), location.endIndex());
  String[] hostSegment = hosts.split(",");
  if (hostSegment.length > 1) {
    StringBuilder sb = new StringBuilder();
    for (String host : hostSegment) {
      if (host.split(":").length == 1) {
        sb.append(host + ":" + DEFAULT_PORT + ",");
      } else {
        sb.append(host + ",");
      }
    }
    if (',' == sb.charAt(sb.length() - 1)) {
      sb.deleteCharAt(sb.length() - 1);
    }
    return new ConnectionInfo.Builder(sb.toString()).dbType(DB_TYPE)
        .dbInstance(fetchDatabaseNameFromURL(url)).build();
  } else {
    String[] hostAndPort = hostSegment[0].split(":");
    if (hostAndPort.length != 1) {
      return new ConnectionInfo.Builder(hostAndPort[0], Integer.valueOf(hostAndPort[1]))
          .dbType(DB_TYPE).dbInstance(fetchDatabaseNameFromURL(url)).build();
    } else {
      return new ConnectionInfo.Builder(hostAndPort[0], DEFAULT_PORT).dbType(DB_TYPE)
          .dbInstance(fetchDatabaseNameFromURL(url)).build();
    }
  }
}
 
Example 5
Source Project: java-jdbc   Source File: H2URLParser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ConnectionInfo parse(String url) {
  int[] databaseNameRangeIndex = fetchDatabaseNameRangeIndexFromURLForH2FileMode(url);
  if (databaseNameRangeIndex != null) {
    return new ConnectionInfo.Builder(LOCALHOST, -1).dbType(H2_DB_TYPE)
        .dbInstance(fetchDatabaseNameFromURL(url, databaseNameRangeIndex)).build();
  }

  databaseNameRangeIndex = fetchDatabaseNameRangeIndexFromURLForH2MemMode(url);
  if (databaseNameRangeIndex != null) {
    return new ConnectionInfo.Builder(LOCALHOST, -1).dbType(H2_DB_TYPE)
        .dbInstance(fetchDatabaseNameFromURL(url, databaseNameRangeIndex)).build();
  }

  databaseNameRangeIndex = fetchDatabaseNameRangeIndexFromURLForH2ImplicitFileMode(url);
  if (databaseNameRangeIndex != null) {
    return new ConnectionInfo.Builder(LOCALHOST, -1).dbType(H2_DB_TYPE)
        .dbInstance(fetchDatabaseNameFromURL(url, databaseNameRangeIndex)).build();
  }

  String[] hostAndPort = fetchDatabaseHostsFromURL(url).split(":");
  if (hostAndPort.length == 1) {
    return new ConnectionInfo.Builder(hostAndPort[0], DEFAULT_PORT).dbType(H2_DB_TYPE)
        .dbInstance(fetchDatabaseNameFromURL(url)).build();
  } else {
    return new ConnectionInfo.Builder(hostAndPort[0], Integer.valueOf(hostAndPort[1]))
        .dbType(H2_DB_TYPE).dbInstance(fetchDatabaseNameFromURL(url)).build();
  }
}
 
Example 6
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseMysqlJDBCURLWithHost() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:mysql//primaryhost/test");
  assertEquals(MYSQL, connectionInfo.getDbType());
  assertEquals("test", connectionInfo.getDbInstance());
  assertEquals("primaryhost:3306", connectionInfo.getDbPeer());
  assertEquals("test[mysql(primaryhost:3306)]", connectionInfo.getPeerService());
}
 
Example 7
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseMysqlJDBCURLWithoutDB() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:mysql//primaryhost?profileSQL=true");
  assertEquals(MYSQL, connectionInfo.getDbType());
  assertEquals("", connectionInfo.getDbInstance());
  assertEquals("primaryhost:3306", connectionInfo.getDbPeer());
  assertEquals("mysql(primaryhost:3306)", connectionInfo.getPeerService());
}
 
Example 8
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseMysqlURLWithoutExplicitDBOrQueryString() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:mysql://primaryhost");
  assertEquals(MYSQL, connectionInfo.getDbType());
  assertEquals("", connectionInfo.getDbInstance());
  assertEquals("primaryhost:3306", connectionInfo.getDbPeer());
}
 
Example 9
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseMysqlJDBCURLWithHostAndPort() {
  ConnectionInfo connectionInfo = URLParser
      .parser("jdbc:mysql//primaryhost:3307/test?profileSQL=true");
  assertEquals(MYSQL, connectionInfo.getDbType());
  assertEquals("test", connectionInfo.getDbInstance());
  assertEquals("primaryhost:3307", connectionInfo.getDbPeer());
  assertEquals("test[mysql(primaryhost:3307)]", connectionInfo.getPeerService());
}
 
Example 10
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseMysqlJDBCURLWithMultiHost() {
  ConnectionInfo connectionInfo = URLParser
      .parser("jdbc:mysql//primaryhost:3307,secondaryhost1,secondaryhost2/test?profileSQL=true");
  assertEquals(MYSQL, connectionInfo.getDbType());
  assertEquals("test", connectionInfo.getDbInstance());
  assertEquals("primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306",
      connectionInfo.getDbPeer());
  assertEquals("test[mysql(primaryhost:3307,secondaryhost1:3306,secondaryhost2:3306)]",
      connectionInfo.getPeerService());
}
 
Example 11
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseMysqlJDBCURLWithConnectorJs() {
  ConnectionInfo connectionInfo = URLParser
      .parser("jdbc:mysql:replication://master,slave1,slave2,slave3/test");
  assertEquals(MYSQL, connectionInfo.getDbType());
  assertEquals("test", connectionInfo.getDbInstance());
  assertEquals("master:3306,slave1:3306,slave2:3306,slave3:3306", connectionInfo.getDbPeer());
  assertEquals("test[mysql(master:3306,slave1:3306,slave2:3306,slave3:3306)]",
      connectionInfo.getPeerService());
}
 
Example 12
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseOracleJDBCURLWithHost() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:oracle:thin:@localhost:orcl");
  assertEquals(ORACLE, connectionInfo.getDbType());
  assertEquals("orcl", connectionInfo.getDbInstance());
  assertEquals("localhost:1521", connectionInfo.getDbPeer());
  assertEquals("orcl[oracle(localhost:1521)]", connectionInfo.getPeerService());
}
 
Example 13
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseOracleJDBCURLWithHostAndPort() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:oracle:thin:@localhost:1522:orcl");
  assertEquals(ORACLE, connectionInfo.getDbType());
  assertEquals("orcl", connectionInfo.getDbInstance());
  assertEquals("localhost:1522", connectionInfo.getDbPeer());
  assertEquals("orcl[oracle(localhost:1522)]", connectionInfo.getPeerService());
}
 
Example 14
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseOracleServiceName() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:oracle:thin:@//localhost:1521/orcl");
  assertEquals(ORACLE, connectionInfo.getDbType());
  assertEquals("orcl", connectionInfo.getDbInstance());
  assertEquals("localhost:1521", connectionInfo.getDbPeer());
  assertEquals("orcl[oracle(localhost:1521)]", connectionInfo.getPeerService());
}
 
Example 15
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseOracleTNSName() {
  ConnectionInfo connectionInfo = URLParser.parse(
      "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= localhost )(PORT= 1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)))");
  assertEquals(ORACLE, connectionInfo.getDbType());
  assertEquals("orcl", connectionInfo.getDbInstance());
  assertEquals("localhost:1521", connectionInfo.getDbPeer());
  assertEquals("orcl[oracle(localhost:1521)]", connectionInfo.getPeerService());
}
 
Example 16
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseOracleTNSNameWithMultiAddress() {
  ConnectionInfo connectionInfo = URLParser.parse(
      "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)))");
  assertEquals(ORACLE, connectionInfo.getDbType());
  assertEquals("orcl", connectionInfo.getDbInstance());
  assertEquals("hostA:1523,hostB:1521", connectionInfo.getDbPeer());
  assertEquals("orcl[oracle(hostA:1523,hostB:1521)]", connectionInfo.getPeerService());
}
 
Example 17
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseOracleJDBCURLWithUserNameAndPassword() {
  ConnectionInfo connectionInfo = URLParser
      .parser("jdbc:oracle:thin:scott/[email protected]:1521:orcl");
  assertEquals(ORACLE, connectionInfo.getDbType());
  assertEquals("orcl", connectionInfo.getDbInstance());
  assertEquals("myhost:1521", connectionInfo.getDbPeer());
  assertEquals("orcl[oracle(myhost:1521)]", connectionInfo.getPeerService());
}
 
Example 18
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseOracleJDBCURLWithSID() {
  ConnectionInfo connectionInfo = URLParser
      .parser("jdbc:oracle:thin:@orcl");
  assertEquals(ORACLE, connectionInfo.getDbType());
  assertEquals("orcl", connectionInfo.getDbInstance());
  assertEquals("orcl:1521", connectionInfo.getDbPeer());
  assertEquals("orcl[oracle(orcl:1521)]", connectionInfo.getPeerService());
}
 
Example 19
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseH2JDBCURLWithEmbedded() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:h2:file:/data/sample");
  assertEquals(H2, connectionInfo.getDbType());
  assertEquals("/data/sample", connectionInfo.getDbInstance());
  assertEquals("localhost:-1", connectionInfo.getDbPeer());
  assertEquals("/data/sample[h2(localhost:-1)]", connectionInfo.getPeerService());
}
 
Example 20
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseH2JDBCURLWithEmbeddedRunningInWindows() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:h2:file:c:/data/sample");
  assertEquals(H2, connectionInfo.getDbType());
  assertEquals("c:/data/sample", connectionInfo.getDbInstance());
  assertEquals("localhost:-1", connectionInfo.getDbPeer());
  assertEquals("c:/data/sample[h2(localhost:-1)]", connectionInfo.getPeerService());
}
 
Example 21
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseH2JDBCURLWithImplicitFile() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:h2:c:/data/sample");
  assertEquals(H2, connectionInfo.getDbType());
  assertEquals("c:/data/sample", connectionInfo.getDbInstance());
  assertEquals("localhost:-1", connectionInfo.getDbPeer());
  assertEquals("c:/data/sample[h2(localhost:-1)]", connectionInfo.getPeerService());
}
 
Example 22
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseH2JDBCURLWithMemoryMode() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:h2:mem:test_mem");

  assertEquals(H2, connectionInfo.getDbType());
  assertEquals("test_mem", connectionInfo.getDbInstance());
  assertEquals("localhost:-1", connectionInfo.getDbPeer());
  assertEquals("test_mem[h2(localhost:-1)]", connectionInfo.getPeerService());
}
 
Example 23
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParseH2JDBCURL() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:h2:tcp://localhost:8084/~/sample");
  assertEquals(H2, connectionInfo.getDbType());
  assertEquals("sample", connectionInfo.getDbInstance());
  assertEquals("localhost:8084", connectionInfo.getDbPeer());
  assertEquals("sample[h2(localhost:8084)]", connectionInfo.getPeerService());
}
 
Example 24
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParsePostgresqlJDBCURLWithHost() {
  ConnectionInfo connectionInfo = URLParser.parse("jdbc:postgresql//primaryhost/test");
  assertEquals(POSTGRESQL, connectionInfo.getDbType());
  assertEquals("test", connectionInfo.getDbInstance());
  assertEquals("primaryhost:5432", connectionInfo.getDbPeer());
  assertEquals("test[postgresql(primaryhost:5432)]", connectionInfo.getPeerService());
}
 
Example 25
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParsePostgresqlJDBCURLWithHostAndPort() {
  ConnectionInfo connectionInfo = URLParser
      .parser("jdbc:postgresql//primaryhost:3307/test?profileSQL=true");
  assertEquals(POSTGRESQL, connectionInfo.getDbType());
  assertEquals("test", connectionInfo.getDbInstance());
  assertEquals("primaryhost:3307", connectionInfo.getDbPeer());
  assertEquals("test[postgresql(primaryhost:3307)]", connectionInfo.getPeerService());
}
 
Example 26
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParsePostgresqlJDBCURLWithMultiHost() {
  ConnectionInfo connectionInfo = URLParser.parse(
      "jdbc:postgresql//primaryhost:3307,secondaryhost1,secondaryhost2/test?profileSQL=true");
  assertEquals(POSTGRESQL, connectionInfo.getDbType());
  assertEquals("test", connectionInfo.getDbInstance());
  assertEquals("primaryhost:3307,secondaryhost1:5432,secondaryhost2:5432",
      connectionInfo.getDbPeer());
  assertEquals("test[postgresql(primaryhost:3307,secondaryhost1:5432,secondaryhost2:5432)]",
      connectionInfo.getPeerService());
}
 
Example 27
Source Project: java-jdbc   Source File: URLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParsePostgresqlJDBCURLWithConnectorJs() {
  ConnectionInfo connectionInfo = URLParser
      .parser("jdbc:postgresql:replication://master,slave1,slave2,slave3/test");
  assertEquals(POSTGRESQL, connectionInfo.getDbType());
  assertEquals("test", connectionInfo.getDbInstance());
  assertEquals("master:5432,slave1:5432,slave2:5432,slave3:5432", connectionInfo.getDbPeer());
  assertEquals("test[postgresql(master:5432,slave1:5432,slave2:5432,slave3:5432)]",
      connectionInfo.getPeerService());
}
 
Example 28
Source Project: java-jdbc   Source File: OracleURLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@ParameterizedTest(name = "[{0}]")
@MethodSource("easyConnectUrls")
void parseEasyConnect(final String url, final String dbPeer, final String dbInstance) {
  final ConnectionInfo result = testee.parse(url);
  assertThat(result.getDbType()).isEqualTo(ORACLE);
  assertThat(result.getDbPeer()).isEqualTo(dbPeer);
  assertThat(result.getDbInstance()).isEqualTo(dbInstance);
}
 
Example 29
Source Project: java-jdbc   Source File: OracleURLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@ParameterizedTest(name = "[{0}]")
@MethodSource("tnsNameUrls")
void parseTnsName(final String url, final String dbPeer, final String dbInstance) {
  final ConnectionInfo result = testee.parse(url);
  assertThat(result.getDbType()).isEqualTo(ORACLE);
  assertThat(result.getDbPeer()).isEqualTo(dbPeer);
  assertThat(result.getDbInstance()).isEqualTo(dbInstance);
}
 
Example 30
Source Project: java-jdbc   Source File: OracleURLParserTest.java    License: Apache License 2.0 5 votes vote down vote up
@ParameterizedTest(name = "[{0}]")
@MethodSource("otherUrls")
void parseOther(final String url, final String dbPeer, final String dbInstance) {
  final ConnectionInfo result = testee.parse(url);
  assertThat(result.getDbType()).isEqualTo(ORACLE);
  assertThat(result.getDbPeer()).isEqualTo(dbPeer);
  assertThat(result.getDbInstance()).isEqualTo(dbInstance);
}