Splits the given jdbc connection url into its components and puts them into
a hash map using the <code>PROPERTY_</code> constants.

@param jdbcConnectionUrl The connection url
@return The properties
336724
public HashMap parseConnectionUrl(String jdbcConnectionUrl)
    {
        HashMap result = new HashMap();

        if (jdbcConnectionUrl == null)
        {
            return result;
        }

        int pos = jdbcConnectionUrl.indexOf(':');
        int lastPos;

        result.put(PROPERTY_PROTOCOL, jdbcConnectionUrl.substring(0, pos));

        lastPos = pos;
        pos     = jdbcConnectionUrl.indexOf(':', lastPos + 1);

        String subProtocol = jdbcConnectionUrl.substring(lastPos + 1, pos);

        // there are a few jdbc drivers that have a subprotocol containing one or more ':'
        if ("inetpool".equals(subProtocol))
        {
            // Possible forms are:
            //   inetpool:<subprotocol>
            //   inetpool:jdbc:<subprotocol>   (where we'll remove the 'jdbc' part)
            
            int tmpPos = jdbcConnectionUrl.indexOf(':', pos + 1);

            if ("inetpool:jdbc".equals(jdbcConnectionUrl.substring(lastPos + 1, tmpPos)))
            {
                pos    = tmpPos;
                tmpPos = jdbcConnectionUrl.indexOf(':', pos + 1);
            }
            subProtocol += ":" + jdbcConnectionUrl.substring(pos + 1, tmpPos);
        }
        else if ("jtds".equals(subProtocol) ||
                 "microsoft".equals(subProtocol) ||
                 "sybase".equals(subProtocol))
        {
            pos         = jdbcConnectionUrl.indexOf(':', pos + 1);
            subProtocol = ":" + jdbcConnectionUrl.substring(lastPos + 1, pos);
        }

        result.put(PROPERTY_SUBPROTOCOL, subProtocol);
        result.put(PROPERTY_DBALIAS, jdbcConnectionUrl.substring(pos + 1));

        return result;
    }
377195
public static synchronized boolean canConnect(String url) {
        boolean result = false;
        HttpURLConnection conn = null;
        try {
            conn = getNormalCon(formatUrl(url));
            conn.connect();

            int resultCode = conn.getResponseCode();
            result = (200 == resultCode);

                /*
            if (!result) {
                Log.d("canConnect", resultCode + "|" + url);
            }
            // */

        } catch (IOException e) {
            result = false;
//            Log.e("canConnect", url + "|error:" + e.toString());
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }

        return result;
    }
117967
public Map<String,Object> getServiceProperties()
    {
        Map<String,Object> properties = Utility.propertiesToMap(this.getProperties());
        if (properties == null)
        	properties = new HashMap<String,Object>();
        properties = addConfigProperty(properties, DBParams.LOCAL, null); // Remote Server ALWAYS uses Jdbc
        properties = addConfigProperty(properties, DBParams.REMOTE, null);
        properties = addConfigProperty(properties, DBParams.TABLE, null);
        return properties;
    }
1135296
public static UrlBuilder parse(URL url) {
        final UrlBuilder result = new UrlBuilder();

        if (url != null) {
            final String protocol = url.getProtocol();
            if (protocol != null && !protocol.isEmpty()) {
                result.withScheme(protocol);
            }

            final String host = url.getHost();
            if (host != null && !host.isEmpty()) {
                result.withHost(host);
            }

            final int port = url.getPort();
            if (port != -1) {
                result.withPort(port);
            }

            final String path = url.getPath();
            if (path != null && !path.isEmpty()) {
                result.withPath(path);
            }

            final String query = url.getQuery();
            if (query != null && !query.isEmpty()) {
                result.withQuery(query);
            }
        }

        return result;
    }
700223
public static DatabaseType getDatabaseType(final String url) {
        switch (getDriverClassName(url)) {
            case "com.mysql.cj.jdbc.Driver":
            case "com.mysql.jdbc.Driver":
                return DatabaseType.MySQL;
            case "org.postgresql.Driver":
                return DatabaseType.PostgreSQL;
            case "oracle.jdbc.driver.OracleDriver":
                return DatabaseType.Oracle;
            case "com.microsoft.sqlserver.jdbc.SQLServerDriver":
                return DatabaseType.SQLServer;
            case "org.h2.Driver":
                return DatabaseType.H2;
            default:
                throw new ShardingException("Cannot resolve JDBC url `%s`", url);
        }
    }
337839
private static URLConnection getConnection(String url, final ProxyConfig proxy) throws IOException {
        URLConnection conn = null;

        if (proxy != null && proxy.getProxyUser() != null) {
            Authenticator.setDefault(new Authenticator() {
                @Override
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(proxy.getProxyUser(), proxy.getProxyPassword().toCharArray());
                }

            });
        }

        if (proxy != null) {
            Proxy thisProxy = new Proxy(proxy.getProxyType(), new InetSocketAddress(proxy.getProxyHost(), proxy.getProxyPort()));
            conn = new URL(url).openConnection(thisProxy);
        } else {
            conn = new URL(url).openConnection();
        }

        return conn;
    }
843237
public String getUrl() {
    StringBuilder url = new StringBuilder(100);
    url.append("jdbc:postgresql://");
    url.append(serverName);
    if (portNumber != 0) {
      url.append(":").append(portNumber);
    }
    url.append("/").append(URLCoder.encode(databaseName));

    StringBuilder query = new StringBuilder(100);
    for (PGProperty property : PGProperty.values()) {
      if (property.isPresent(properties)) {
        if (query.length() != 0) {
          query.append("&");
        }
        query.append(property.getName());
        query.append("=");
        query.append(URLCoder.encode(property.get(properties)));
      }
    }

    if (query.length() > 0) {
      url.append("?");
      url.append(query);
    }

    return url.toString();
  }
1194933
public static Map<URLParts, String> splitURL(String URLString) {
        try {
            return splitURL(new URL(URLString));
        } 
        catch (MalformedURLException ex) {
            throw new RuntimeException(ex);
        }
    }
117229
public static Set<String> getIndexNames(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName) throws SQLException {

		DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
		try (Connection connection = dataSource.getConnection()) {
			return theConnectionProperties.getTxTemplate().execute(t -> {
				DatabaseMetaData metadata;
				try {
					metadata = connection.getMetaData();
					ResultSet indexes = metadata.getIndexInfo(connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theTableName), false, true);

					Set<String> indexNames = new HashSet<>();
					while (indexes.next()) {

						ourLog.debug("*** Next index: {}", new ColumnMapRowMapper().mapRow(indexes, 0));

						String indexName = indexes.getString("INDEX_NAME");
						indexName = toUpperCase(indexName, Locale.US);
						indexNames.add(indexName);
					}

					return indexNames;
				} catch (SQLException e) {
					throw new InternalErrorException(e);
				}
			});
		}
	}
379710
private Connection getConnection() throws JspException, SQLException {
	// Fix: Add all other mechanisms
	Connection conn = null;
	isPartOfTransaction = false;

        TransactionTagSupport parent = (TransactionTagSupport)
	    findAncestorWithClass(this, TransactionTagSupport.class);
	if (parent != null) {
            if (dataSourceSpecified) {
                throw new JspTagException(
                    Resources.getMessage("ERROR_NESTED_DATASOURCE"));
            }
	    conn = parent.getSharedConnection();
            isPartOfTransaction = true;
	} else {
	    if ((rawDataSource == null) && dataSourceSpecified) {
		throw new JspException(
		    Resources.getMessage("SQL_DATASOURCE_NULL"));
	    }
	    DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
								 pageContext);
            try {
                conn = dataSource.getConnection();
            } catch (Exception ex) {
                throw new JspException(
                    Resources.getMessage("DATASOURCE_INVALID",
					 ex.toString()));
            }
	}

	return conn;
    }
1177858
public static Map<String, String> splitUrlQuery(String query) {
        Map<String, String> result = new HashMap<String, String>();

        String[] pairs = query.split("&");
        if (pairs != null && pairs.length > 0) {
            for (String pair : pairs) {
                String[] param = pair.split("=", 2);
                if (param != null && param.length == 2) {
                    result.put(param[0], param[1]);
                }
            }
        }

        return result;
    }
147815
public static Set<String> getColumnNames(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName) throws SQLException {
		DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
		try (Connection connection = dataSource.getConnection()) {
			return theConnectionProperties.getTxTemplate().execute(t -> {
				DatabaseMetaData metadata;
				try {
					metadata = connection.getMetaData();
					ResultSet indexes = metadata.getColumns(connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theTableName), null);

					Set<String> columnNames = new HashSet<>();
					while (indexes.next()) {
						String tableName = toUpperCase(indexes.getString("TABLE_NAME"), Locale.US);
						if (!theTableName.equalsIgnoreCase(tableName)) {
							continue;
						}

						String columnName = indexes.getString("COLUMN_NAME");
						columnName = toUpperCase(columnName, Locale.US);
						columnNames.add(columnName);
					}

					return columnNames;
				} catch (SQLException e) {
					throw new InternalErrorException(e);
				}
			});
		}
	}
1345633
private Map<String, Object> getConnectionInfo() {
        String[] hostnames = (String[]) props.get(HOST_NAMES);
        int[] ports = (int[]) props.get(PORTS);

        String hostname = (hostnames == null || hostnames.length < 1) ? null : hostnames[0];
        String port = (ports == null || ports.length < 1) ? null : String.valueOf(ports[0]);

        return sslHelper.getConnectionInfo(hostname, port);
    }
1273379
public Connection getConnection() throws IOException {
		Connection conn = null;
		try {
			if (this.datasource != null) {
				try {
					Class.forName(datasource.get("driver"));
				} catch (ClassNotFoundException e) {
					throw new IOException("Load jdbc driver fail: " + datasource.get("driver"));
				}
				String url = datasource.get("url");
				String user = datasource.get("user");
				String password = datasource.get("password");
				if (StringUtils.isNoneBlank(user)) {
					conn = DriverManager.getConnection(url, user, password);
				} else {
					conn = DriverManager.getConnection(url);
				}
				conn.setAutoCommit(datasource.getBoolean("auto_commit", true));
			}
		} catch (Exception e) {
			throw new IOException(e);
		}
		return conn;
	}
204155
public Table url(URL url) throws IOException {
	URLConnection connection = url.openConnection();
	String contentType = connection.getContentType();
	String[] pair = contentType.split(";");
	String mimeType = pair[0].trim();
	Charset charset = pair.length == 0 ? Charset.defaultCharset() : Charset.forName(pair[1].split("=")[1].trim());
	DataReader<?> reader = registry.getReaderForMimeType(mimeType);
	return reader.read(new Source(connection.getInputStream(), charset));
    }
206172
public static UroboroSQLBuilder builder(final String url, final String user, final String password,
			final String schema) {
		return builder().setConnectionSupplier(new JdbcConnectionSupplierImpl(url, user, password, schema));
	}
71550
public static Dialect guessDialect(Connection jdbcConnection) {
		String databaseName;
		String driverName;
		int majorVersion;
		int minorVersion;
		try {
			DatabaseMetaData meta = jdbcConnection.getMetaData();
			driverName = meta.getDriverName();
			databaseName = meta.getDatabaseProductName();
			majorVersion = meta.getDatabaseMajorVersion();
			minorVersion = meta.getDatabaseMinorVersion();
		} catch (SQLException e) {
			return (Dialect) DialectException.throwEX(e);
		}
		return guessDialect(driverName, databaseName, majorVersion, minorVersion);
	}