类 ConnectionUrlParser
- java.lang.Object
-
- com.mysql.cj.conf.ConnectionUrlParser
-
- 所有已实现的接口:
DatabaseUrlContainer
public class ConnectionUrlParser extends Object implements DatabaseUrlContainer
This class parses a connection string using the general URI structure defined in RFC 3986. Instead of using a URI instance to ensure the correct syntax of the connection string, this implementation uses regular expressions which is faster but also less strict in terms of validations. This actually works better because database URLs don't exactly stick to the RFC 3986 rules.scheme://authority/path?query#fragment
This results in splitting the connection string URL and processing its internal parts:
- scheme
- The protocol and subprotocol identification. Usually "jdbc:mysql:" or "mysqlx:".
- authority
- Contains information about the user credentials and/or the host and port information. Unlike its definition in the RFC 3986 specification, there can be multiple authority sections separated by a single comma (,) in a connection string. It is also possible to use an alternative syntax for the user and/or host identification, that also allows setting per host connection properties, in the form of "[user[:password]@]address=(key1=value)[(key2=value)]...[,address=(key3=value)[(key4=value)]...]...".
- path
- Corresponds to the database identification.
- query
- The connection properties, written as "propertyName1[=[propertyValue1]][&propertyName2[=[propertyValue2]]]..."
- fragment
- The fragment section is ignored in Connector/J connection strings.
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classConnectionUrlParser.Pair<T,U>This class is a simple container for two elements.
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 StringgetAuthority()Returns the authority section.StringgetDatabaseUrl()Returns the original database URL that produced this connection string parser.List<HostInfo>getHosts()Returns the hosts information.StringgetPath()Returns the path section.Map<String,String>getProperties()Returns the properties map contained in this connection string.StringgetQuery()Returns the query section.StringgetScheme()Returns the scheme section.static booleanisConnectionStringSupported(String connString)Checks if the scheme part of given connection string matches one of theConnectionUrl.Types supported by Connector/J.static ConnectionUrlParserparseConnectionString(String connString)Static factory method for constructing instances of this class.static ConnectionUrlParser.Pair<String,Integer>parseHostPortPair(String hostInfo)Parses a host:port pair and returns the two elements in aConnectionUrlParser.Pairstatic ConnectionUrlParser.Pair<String,String>parseUserInfo(String userInfo)Parses the given user information which is formed by the parts [user][:password].StringtoString()Returns a string representation of this object.
-
-
-
方法详细资料
-
parseConnectionString
public static ConnectionUrlParser parseConnectionString(String connString)
Static factory method for constructing instances of this class.- 参数:
connString- The connection string to parse.- 返回:
- an instance of
ConnectionUrlParser
-
isConnectionStringSupported
public static boolean isConnectionStringSupported(String connString)
Checks if the scheme part of given connection string matches one of theConnectionUrl.Types supported by Connector/J. ThrowsWrongArgumentExceptionif connString is null.- 参数:
connString- connection string- 返回:
- true if supported
-
parseUserInfo
public static ConnectionUrlParser.Pair<String,String> parseUserInfo(String userInfo)
Parses the given user information which is formed by the parts [user][:password].- 参数:
userInfo- the string containing the user information- 返回:
- a
ConnectionUrlParser.Paircontaining the user and password information or null if the user information can't be parsed
-
parseHostPortPair
public static ConnectionUrlParser.Pair<String,Integer> parseHostPortPair(String hostInfo)
Parses a host:port pair and returns the two elements in aConnectionUrlParser.Pair- 参数:
hostInfo- the host:pair to parse- 返回:
- a
ConnectionUrlParser.Paircontaining the host and port information or null if the host information can't be parsed
-
getDatabaseUrl
public String getDatabaseUrl()
Returns the original database URL that produced this connection string parser.- 指定者:
getDatabaseUrl在接口中DatabaseUrlContainer- 返回:
- the original database URL
-
getScheme
public String getScheme()
Returns the scheme section.- 返回:
- the scheme section
-
getAuthority
public String getAuthority()
Returns the authority section.- 返回:
- the authority section
-
getPath
public String getPath()
Returns the path section.- 返回:
- the path section
-
getQuery
public String getQuery()
Returns the query section.- 返回:
- the query section
-
getProperties
public Map<String,String> getProperties()
Returns the properties map contained in this connection string.- 返回:
- the properties map
-
-