test_class.file: base/lang/src/test/java/leap/lang/jdbc/JdbcTest.java
test_class.identifier: JdbcTest
test_class.superclass: extends TestBase
test_case.body: @Test
      public void testExtractServerString() {
          /*
              jdbc:microsoft:sqlserver://<server_name>:<port> -> port is optional
              jdbc:sqlserver://<server_name>:<port>
              jdbc:oracle:thin:@//<host>:<port>/ServiceName
              jdbc:oracle:thin:@<host>:<port>:<SID>
              jdbc:db2://<host>[:<port>]/<database_name>
              jdbc:mysql://<host>:<port>/<database_name>
              jdbc:postgresql://<host>:<port>/<database_name>
              jdbc:h2:tcp://<server>[:<port>]/[<path>]<databaseName>
              jdbc:h2:[file:][<path>]<databaseName>
              jdbc:h2:<url>[;USER=<username>][;PASSWORD=<value>]
  
           */
          assertEquals("127.0.0.1",      JDBC.tryExtractServerString("jdbc:microsoft:sqlserver://127.0.0.1"));
          assertEquals("127.0.0.1:1234", JDBC.tryExtractServerString("jdbc:microsoft:sqlserver://127.0.0.1:1234"));
          assertEquals("127.0.0.1",      JDBC.tryExtractServerString("jdbc:sqlserver://127.0.0.1"));
          assertEquals("127.0.0.1:1234", JDBC.tryExtractServerString("jdbc:sqlserver://127.0.0.1:1234"));
          assertEquals("127.0.0.1:1234", JDBC.tryExtractServerString("jdbc:oracle:thin:@127.0.0.1:1234:db"));
          assertEquals("127.0.0.1:1234", JDBC.tryExtractServerString("jdbc:oracle:thin:@//127.0.0.1:1234/db"));
          assertEquals("127.0.0.1:1234", JDBC.tryExtractServerString("jdbc:db2://127.0.0.1:1234/db"));
          assertEquals("127.0.0.1",      JDBC.tryExtractServerString("jdbc:mysql://127.0.0.1"));
          assertEquals("127.0.0.1:1234", JDBC.tryExtractServerString("jdbc:mysql://127.0.0.1:1234"));
          assertEquals("127.0.0.1:1234", JDBC.tryExtractServerString("jdbc:mysql://127.0.0.1:1234?a=b&c=d"));
          assertEquals("127.0.0.1",      JDBC.tryExtractServerString("jdbc:h2:tcp://127.0.0.1/path/db"));
          assertEquals("127.0.0.1",      JDBC.tryExtractServerString("jdbc:h2:tcp://127.0.0.1/path/db;a=b;c=d"));
          assertEquals("127.0.0.1:1234", JDBC.tryExtractServerString("jdbc:h2:tcp://127.0.0.1:1234/path/db"));
          assertEquals("file:a.db",      JDBC.tryExtractServerString("jdbc:h2:file:a.db"));
  
          assertNull(JDBC.tryExtractServerString("jdbc:h2:./target/test"));
          assertNull(JDBC.tryExtractServerString("abcd"));
      }
test_case.class_method_signature: JdbcTest.testExtractServerString()
test_case.full_signature: @Test public void testExtractServerString()
test_case.identifier: testExtractServerString
test_case.invocations: assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertEquals tryExtractServerString assertNull tryExtractServerString assertNull tryExtractServerString
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testExtractServerString()
focal_class.declarator: log = LogFactory.get(JDBC.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Log log = LogFactory.get(JDBC.class);
focal_class.type: Log
focal_class.var_name: log
focal_class.declarator: PARAMETER_PLACEHOLDER_CHAR   = '?'
focal_class.modifier: public static final
focal_class.original_string: public static final char   PARAMETER_PLACEHOLDER_CHAR   = '?';
focal_class.type: char
focal_class.var_name: PARAMETER_PLACEHOLDER_CHAR
focal_class.declarator: PARAMETER_PLACEHOLDER_STRING = "?"
focal_class.modifier: public static final
focal_class.original_string: public static final String PARAMETER_PLACEHOLDER_STRING = "?";
focal_class.type: String
focal_class.var_name: PARAMETER_PLACEHOLDER_STRING
focal_class.file: base/lang/src/main/java/leap/lang/jdbc/JDBC.java
focal_class.identifier: JDBC
focal_class.class_method_signature: JDBC.closeConnection(Connection connection)
focal_class.full_signature: public static void closeConnection(Connection connection)
focal_class.identifier: closeConnection
focal_class.modifiers: public static
focal_class.parameters: (Connection connection)
focal_class.return: void
focal_class.signature: void closeConnection(Connection connection)
focal_class.class_method_signature: JDBC.closeStatementOnly(Statement statement)
focal_class.full_signature: public static void closeStatementOnly(Statement statement)
focal_class.identifier: closeStatementOnly
focal_class.modifiers: public static
focal_class.parameters: (Statement statement)
focal_class.return: void
focal_class.signature: void closeStatementOnly(Statement statement)
focal_class.class_method_signature: JDBC.closeStatementAndConnection(Statement statement)
focal_class.full_signature: public static void closeStatementAndConnection(Statement statement)
focal_class.identifier: closeStatementAndConnection
focal_class.modifiers: public static
focal_class.parameters: (Statement statement)
focal_class.return: void
focal_class.signature: void closeStatementAndConnection(Statement statement)
focal_class.class_method_signature: JDBC.closeResultSetOnly(ResultSet rs)
focal_class.full_signature: public static void closeResultSetOnly(ResultSet rs)
focal_class.identifier: closeResultSetOnly
focal_class.modifiers: public static
focal_class.parameters: (ResultSet rs)
focal_class.return: void
focal_class.signature: void closeResultSetOnly(ResultSet rs)
focal_class.class_method_signature: JDBC.closeResultSetAndConnection(ResultSet rs)
focal_class.full_signature: public static void closeResultSetAndConnection(ResultSet rs)
focal_class.identifier: closeResultSetAndConnection
focal_class.modifiers: public static
focal_class.parameters: (ResultSet rs)
focal_class.return: void
focal_class.signature: void closeResultSetAndConnection(ResultSet rs)
focal_class.class_method_signature: JDBC.closeResultSetAndStatement(ResultSet rs)
focal_class.full_signature: public static void closeResultSetAndStatement(ResultSet rs)
focal_class.identifier: closeResultSetAndStatement
focal_class.modifiers: public static
focal_class.parameters: (ResultSet rs)
focal_class.return: void
focal_class.signature: void closeResultSetAndStatement(ResultSet rs)
focal_class.class_method_signature: JDBC.tryExtractServerString(String url)
focal_class.full_signature: public static String tryExtractServerString(String url)
focal_class.identifier: tryExtractServerString
focal_class.modifiers: public static
focal_class.parameters: (String url)
focal_class.return: String
focal_class.signature: String tryExtractServerString(String url)
focal_class.class_method_signature: JDBC.JDBC()
focal_class.full_signature: protected  JDBC()
focal_class.identifier: JDBC
focal_class.modifiers: protected
focal_class.parameters: ()
focal_class.signature:  JDBC()
focal_method.body: public static String tryExtractServerString(String url) {
          /*
              jdbc:microsoft:sqlserver://<server_name>:<port> -> port is optional
              jdbc:sqlserver://<server_name>:<port>
              jdbc:oracle:thin:@//<host>:<port>/ServiceName
              jdbc:oracle:thin:@<host>:<port>:<SID>
              jdbc:db2://<host>[:<port>]/<database_name>
              jdbc:mysql://<host>:<port>/<database_name>
              jdbc:postgresql://<host>:<port>/<database_name>
              jdbc:h2:tcp://<server>[:<port>]/[<path>]<databaseName>
              jdbc:h2:[file:][<path>]<databaseName>
              jdbc:h2:<url>[;USER=<username>][;PASSWORD=<value>]
  
           */
          if(!Strings.startsWith(url, "jdbc:", true)) {
              return null;
          }
  
          url = Urls.removeQueryString(url);
  
          //removes jdbc:dbtype:
          int index = url.indexOf(':',5);
          if(index < 0) {
              //unknown url
              return null;
          }else{
              url = url.substring(index+1);
          }
  
          //remove parameters like jdbc url : jdbc:h2:<url>[;USER=<username>][;PASSWORD=<value>]
          index = url.indexOf(';');
          if(index > 0) {
              url = url.substring(0, index);
          }
  
          index = url.indexOf("//");
          if(index >= 0) {
              url = url.substring(index + 2);
          }else {
              index = url.indexOf('@');
              if(index >= 0) {
                  url = url.substring(index + 1);
              }
          }
  
          index = url.indexOf('/');
          if(index > 0) {
              url = url.substring(0, index);
          }
  
          String[] parts = Strings.split(url, ':');
          if(parts.length >= 2) {
              return parts[0] + ":" + parts[1];
          }else{
              //hostname or ip address only
              if(url.length() <= 5){
                  return null;
              }
              return url;
          }
      }
focal_method.class_method_signature: JDBC.tryExtractServerString(String url)
focal_method.full_signature: public static String tryExtractServerString(String url)
focal_method.identifier: tryExtractServerString
focal_method.invocations: startsWith removeQueryString indexOf substring indexOf substring indexOf substring indexOf substring indexOf substring split length
focal_method.modifiers: public static
focal_method.parameters: (String url)
focal_method.return: String
focal_method.signature: String tryExtractServerString(String url)