public class ConnectionUrlParser extends Object implements DatabaseUrlContainer
scheme://authority/path?query#fragment
This results in splitting the connection string URL and processing its internal parts:
| Modifier and Type | Class and Description |
|---|---|
static class |
ConnectionUrlParser.Pair<T,U>
This class is a simple container for two elements.
|
| Modifier and Type | Field and Description |
|---|---|
private static String |
ADDRESS_EQUALS_HOST_INFO_PREFIX |
private static Pattern |
ADDRESS_EQUALS_HOST_PTRN |
private String |
authority |
private String |
baseConnectionString |
private static Pattern |
CONNECTION_STRING_PTRN |
private static String |
DUMMY_SCHEMA |
private static Pattern |
GENERIC_HOST_PTRN |
private static Pattern |
HOST_LIST_PTRN |
private static String |
HOSTS_LIST_CLOSING_MARKERS |
private static String |
HOSTS_LIST_OPENING_MARKERS |
private static String |
HOSTS_SEPARATOR |
private static String |
KEY_VALUE_HOST_INFO_CLOSING_MARKER |
private static String |
KEY_VALUE_HOST_INFO_OPENING_MARKER |
private static Pattern |
KEY_VALUE_HOST_PTRN |
private List<HostInfo> |
parsedHosts |
private Map<String,String> |
parsedProperties |
private String |
path |
private static Pattern |
PROPERTIES_PTRN |
private String |
query |
private String |
scheme |
private static Pattern |
SCHEME_PTRN |
private static String |
USER_HOST_SEPARATOR |
private static String |
USER_PASS_SEPARATOR |
| Modifier | Constructor and Description |
|---|---|
private |
ConnectionUrlParser(String connString)
Constructs a connection string parser for the given connection string.
|
| Modifier and Type | Method and Description |
|---|---|
private HostInfo |
buildHostInfoForEmptyHost(String user,
String password,
String hostInfo)
Builds an
HostInfo instance for empty host authority segments. |
private HostInfo |
buildHostInfoResortingToAddressEqualsSyntaxParser(String user,
String password,
String hostInfo)
Parses the host information using the alternate syntax "address=(key1=value1)(key2=value2)...".
|
private HostInfo |
buildHostInfoResortingToGenericSyntaxParser(String user,
String password,
String hostInfo)
Parses the host information using the generic syntax "host:port".
|
private HostInfo |
buildHostInfoResortingToKeyValueSyntaxParser(String user,
String password,
String hostInfo)
Parses the host information using the alternate syntax "(key1=value1, key2=value2, ...)".
|
private List<HostInfo> |
buildHostInfoResortingToSubHostsListParser(String user,
String password,
String hostInfo)
Parses the host information using the alternate sub hosts lists syntax "[host1, host2, ...]".
|
private HostInfo |
buildHostInfoResortingToUriParser(String user,
String password,
String hostInfo)
Parses the host information resorting to a URI object.
|
private static String |
decode(String text)
URL-decode the given string.
|
private static String |
decodeSkippingPlusSign(String text)
URL-decode the given string skipping all occurrences of the plus sign.
|
String |
getAuthority()
Returns the authority section.
|
String |
getDatabaseUrl()
Returns the original database URL that produced this connection string parser.
|
List<HostInfo> |
getHosts()
Returns the hosts information.
|
String |
getPath()
Returns the path section.
|
Map<String,String> |
getProperties()
Returns the properties map contained in this connection string.
|
String |
getQuery()
Returns the query section.
|
String |
getScheme()
Returns the scheme section.
|
static boolean |
isConnectionStringSupported(String connString)
Checks if the scheme part of given connection string matches one of the
ConnectionUrl.Types supported by Connector/J. |
private void |
parseAuthoritySection()
Parses the authority section (user and/or host identification) of the connection string URI.
|
private void |
parseAuthoritySegment(String authSegment)
Parses the given sub authority segment, which can take one of the following syntaxes:
_user_:_password_@_host_:_port_
_user_:_password_@(key1=value1,key2=value2,...)
_user_:_password_@address=(key1=value1)(key2=value2)...
|
private void |
parseConnectionString()
Splits the connection string in its main sections.
|
static ConnectionUrlParser |
parseConnectionString(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 a
ConnectionUrlParser.Pair |
private void |
parseQuerySection()
Parses the connection properties section and stores the extracted key/value pairs into a local map.
|
static ConnectionUrlParser.Pair<String,String> |
parseUserInfo(String userInfo)
Parses the given user information which is formed by the parts [user][:password].
|
private Map<String,String> |
processKeyValuePattern(Pattern pattern,
String input)
Takes a two-matching-groups (respectively named "key" and "value") pattern which is successively tested against the given string and produces a key/value
map with the matched values.
|
private ConnectionUrlParser.Pair<String,String> |
splitByUserInfoAndHostInfo(String authSegment)
Splits the given authority segment in the user information part and the host part.
|
String |
toString()
Returns a string representation of this object.
|
private static final String DUMMY_SCHEMA
private static final String USER_PASS_SEPARATOR
private static final String USER_HOST_SEPARATOR
private static final String HOSTS_SEPARATOR
private static final String KEY_VALUE_HOST_INFO_OPENING_MARKER
private static final String KEY_VALUE_HOST_INFO_CLOSING_MARKER
private static final String HOSTS_LIST_OPENING_MARKERS
private static final String HOSTS_LIST_CLOSING_MARKERS
private static final String ADDRESS_EQUALS_HOST_INFO_PREFIX
private static final Pattern CONNECTION_STRING_PTRN
private static final Pattern SCHEME_PTRN
private static final Pattern HOST_LIST_PTRN
private static final Pattern GENERIC_HOST_PTRN
private static final Pattern KEY_VALUE_HOST_PTRN
private static final Pattern ADDRESS_EQUALS_HOST_PTRN
private static final Pattern PROPERTIES_PTRN
private final String baseConnectionString
private String scheme
private String authority
private String path
private String query
private ConnectionUrlParser(String connString)
connString - the connection string to parsepublic static ConnectionUrlParser parseConnectionString(String connString)
connString - The connection string to parse.ConnectionUrlParserpublic static boolean isConnectionStringSupported(String connString)
ConnectionUrl.Types supported by Connector/J.
Throws WrongArgumentException if connString is null.connString - connection stringprivate void parseConnectionString()
private void parseAuthoritySection()
private void parseAuthoritySegment(String authSegment)
authSegment - the string containing the authority segmentprivate HostInfo buildHostInfoForEmptyHost(String user, String password, String hostInfo)
HostInfo instance for empty host authority segments.private HostInfo buildHostInfoResortingToUriParser(String user, String password, String hostInfo)
private List<HostInfo> buildHostInfoResortingToSubHostsListParser(String user, String password, String hostInfo)
user - the user to include in all the resulting HostInfopassword - the password to include in all the resulting HostInfohostInfo - the string containing the host information partHostInfo instances containing the parsed information or null if unable to parse the host informationprivate HostInfo buildHostInfoResortingToKeyValueSyntaxParser(String user, String password, String hostInfo)
private HostInfo buildHostInfoResortingToAddressEqualsSyntaxParser(String user, String password, String hostInfo)
private HostInfo buildHostInfoResortingToGenericSyntaxParser(String user, String password, String hostInfo)
private ConnectionUrlParser.Pair<String,String> splitByUserInfoAndHostInfo(String authSegment)
authSegment - the string containing the authority segment, i.e., the user and host information partsConnectionUrlParser.Pair containing the user information in the left side and the host information in the rightpublic static ConnectionUrlParser.Pair<String,String> parseUserInfo(String userInfo)
userInfo - the string containing the user informationConnectionUrlParser.Pair containing the user and password information or null if the user information can't be parsedpublic static ConnectionUrlParser.Pair<String,Integer> parseHostPortPair(String hostInfo)
ConnectionUrlParser.PairhostInfo - the host:pair to parseConnectionUrlParser.Pair containing the host and port information or null if the host information can't be parsedprivate void parseQuerySection()
private Map<String,String> processKeyValuePattern(Pattern pattern, String input)
pattern - the regular expression pattern to match against toinput - the input stringprivate static String decode(String text)
text - the string to decodeprivate static String decodeSkippingPlusSign(String text)
text - the string to decodepublic String getDatabaseUrl()
getDatabaseUrl in interface DatabaseUrlContainerpublic String getScheme()
public String getAuthority()
public String getPath()
public String getQuery()
public List<HostInfo> getHosts()
public Map<String,String> getProperties()