Package com.mysql.cj.conf
Class ConnectionUrlParser
java.lang.Object
com.mysql.cj.conf.ConnectionUrlParser
- All Implemented Interfaces:
DatabaseUrlContainer
public class ConnectionUrlParser extends java.lang.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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConnectionUrlParser.Pair<T,U>
This class is a simple container for two elements. -
Method Summary
Modifier and Type Method Description java.lang.String
getAuthority()
Returns the authority section.java.lang.String
getDatabaseUrl()
Returns the original database URL that produced this connection string parser.java.util.List<HostInfo>
getHosts()
Returns the hosts information.java.lang.String
getPath()
Returns the path section.java.util.Map<java.lang.String,java.lang.String>
getProperties()
Returns the properties map contained in this connection string.java.lang.String
getQuery()
Returns the query section.java.lang.String
getScheme()
Returns the scheme section.static boolean
isConnectionStringSupported(java.lang.String connString)
Checks if the scheme part of given connection string matches one of theConnectionUrl.Type
s supported by Connector/J.static ConnectionUrlParser
parseConnectionString(java.lang.String connString)
Static factory method for constructing instances of this class.static ConnectionUrlParser.Pair<java.lang.String,java.lang.Integer>
parseHostPortPair(java.lang.String hostInfo)
Parses a host:port pair and returns the two elements in aConnectionUrlParser.Pair
static ConnectionUrlParser.Pair<java.lang.String,java.lang.String>
parseUserInfo(java.lang.String userInfo)
Parses the given user information which is formed by the parts [user][:password].java.lang.String
toString()
Returns a string representation of this object.
-
Method Details
-
parseConnectionString
Static factory method for constructing instances of this class.- Parameters:
connString
- The connection string to parse.- Returns:
- an instance of
ConnectionUrlParser
-
isConnectionStringSupported
public static boolean isConnectionStringSupported(java.lang.String connString)Checks if the scheme part of given connection string matches one of theConnectionUrl.Type
s supported by Connector/J. ThrowsWrongArgumentException
if connString is null.- Parameters:
connString
- connection string- Returns:
- true if supported
-
parseUserInfo
public static ConnectionUrlParser.Pair<java.lang.String,java.lang.String> parseUserInfo(java.lang.String userInfo)Parses the given user information which is formed by the parts [user][:password].- Parameters:
userInfo
- the string containing the user information- Returns:
- a
ConnectionUrlParser.Pair
containing the user and password information or null if the user information can't be parsed
-
parseHostPortPair
public static ConnectionUrlParser.Pair<java.lang.String,java.lang.Integer> parseHostPortPair(java.lang.String hostInfo)Parses a host:port pair and returns the two elements in aConnectionUrlParser.Pair
- Parameters:
hostInfo
- the host:pair to parse- Returns:
- a
ConnectionUrlParser.Pair
containing the host and port information or null if the host information can't be parsed
-
getDatabaseUrl
public java.lang.String getDatabaseUrl()Returns the original database URL that produced this connection string parser.- Specified by:
getDatabaseUrl
in interfaceDatabaseUrlContainer
- Returns:
- the original database URL
-
getScheme
public java.lang.String getScheme()Returns the scheme section.- Returns:
- the scheme section
-
getAuthority
public java.lang.String getAuthority()Returns the authority section.- Returns:
- the authority section
-
getPath
public java.lang.String getPath()Returns the path section.- Returns:
- the path section
-
getQuery
public java.lang.String getQuery()Returns the query section.- Returns:
- the query section
-
getHosts
Returns the hosts information.- Returns:
- the hosts information
-
getProperties
public java.util.Map<java.lang.String,java.lang.String> getProperties()Returns the properties map contained in this connection string.- Returns:
- the properties map
-
toString
public java.lang.String toString()Returns a string representation of this object.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this object
-