Class UrlParser
- java.lang.Object
-
- org.mariadb.jdbc.UrlParser
-
- All Implemented Interfaces:
java.lang.Cloneable
public class UrlParser extends java.lang.Object implements java.lang.Cloneable
parse and verification of URL.basic syntax :
jdbc:(mysql|mariadb):[replication:|failover|loadbalance:|aurora:]//<hostDescription>[,<hostDescription>]/[database>] [?<key1>=<value1>[&<key2>=<value2>]]
hostDescription:
- simple :
<host>:<portnumber>
(for example localhost:3306)
- complex :
address=[(type=(master|slave))][(port=<portnumber>)](host=<host>)
type is by default master
port is by default 3306
host can be dns name, ipv4 or ipv6.
in case of ipv6 and simple host description, the ip must be written inside bracket.
exemple :jdbc:mariadb://[2001:0660:7401:0200:0000:0000:0edf:bdd7]:3306
Some examples :
jdbc:mariadb://localhost:3306/database?user=greg&password=pass
jdbc:mariadb://address=(type=master)(host=master1),address=(port=3307)(type=slave)(host=slave1)/database?user=greg&password=pass
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<HostAddress>
addresses
private static java.util.regex.Pattern
AWS_PATTERN
private CredentialPlugin
credentialPlugin
private java.lang.String
database
private static java.lang.String
DISABLE_MYSQL_URL
private HaMode
haMode
private java.lang.String
initialUrl
private boolean
multiMaster
private Options
options
private static java.util.regex.Pattern
URL_PARAMETER
-
Constructor Summary
Constructors Modifier Constructor Description private
UrlParser()
UrlParser(java.lang.String database, java.util.List<HostAddress> addresses, Options options, HaMode haMode)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static boolean
acceptsUrl(java.lang.String url)
Tell if mariadb driver accept url string.UrlParser
auroraPipelineQuirks()
Permit to set parameters not forced.java.lang.Object
clone()
private static void
defineUrlParserParameters(UrlParser urlParser, java.util.Properties properties, java.lang.String hostAddressesString, java.lang.String additionalParameters)
Sets the parameters of the UrlParser instance: addresses, database and options.boolean
equals(java.lang.Object parser)
CredentialPlugin
getCredentialPlugin()
java.lang.String
getDatabase()
HaMode
getHaMode()
java.util.List<HostAddress>
getHostAddresses()
java.lang.String
getInitialUrl()
Options
getOptions()
java.lang.String
getPassword()
java.lang.String
getUsername()
int
hashCode()
boolean
isAurora()
Detection of Aurora.boolean
isMultiMaster()
private void
loadMultiMasterValue()
static UrlParser
parse(java.lang.String url)
static UrlParser
parse(java.lang.String url, java.util.Properties prop)
Parse url connection string with additional properties.private static HaMode
parseHaMode(java.lang.String url, int separator)
private static void
parseInternal(UrlParser urlParser, java.lang.String url, java.util.Properties properties)
Parses the connection URL in order to set the UrlParser instance with all the information provided through the URL.void
parseUrl(java.lang.String url)
Parse url connection string.void
setDatabase(java.lang.String database)
private static void
setDefaultHostAddressType(UrlParser urlParser)
private void
setInitialUrl()
void
setPassword(java.lang.String password)
protected void
setProperties(java.lang.String urlParameters)
void
setUsername(java.lang.String username)
java.lang.String
toString()
ToString implementation.
-
-
-
Field Detail
-
DISABLE_MYSQL_URL
private static final java.lang.String DISABLE_MYSQL_URL
- See Also:
- Constant Field Values
-
URL_PARAMETER
private static final java.util.regex.Pattern URL_PARAMETER
-
AWS_PATTERN
private static final java.util.regex.Pattern AWS_PATTERN
-
database
private java.lang.String database
-
options
private Options options
-
addresses
private java.util.List<HostAddress> addresses
-
haMode
private HaMode haMode
-
initialUrl
private java.lang.String initialUrl
-
multiMaster
private boolean multiMaster
-
credentialPlugin
private CredentialPlugin credentialPlugin
-
-
Constructor Detail
-
UrlParser
private UrlParser()
-
UrlParser
public UrlParser(java.lang.String database, java.util.List<HostAddress> addresses, Options options, HaMode haMode) throws java.sql.SQLException
Constructor.- Parameters:
database
- databaseaddresses
- list of hostsoptions
- connection optionhaMode
- High availability mode- Throws:
java.sql.SQLException
- if credential plugin cannot be loaded
-
-
Method Detail
-
acceptsUrl
public static boolean acceptsUrl(java.lang.String url)
Tell if mariadb driver accept url string. (Correspond to interface java.jdbc.Driver.acceptsURL() method)- Parameters:
url
- url String- Returns:
- true if url string correspond.
-
parse
public static UrlParser parse(java.lang.String url) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
parse
public static UrlParser parse(java.lang.String url, java.util.Properties prop) throws java.sql.SQLException
Parse url connection string with additional properties.- Parameters:
url
- connection stringprop
- properties- Returns:
- UrlParser instance
- Throws:
java.sql.SQLException
- if parsing exception occur
-
parseInternal
private static void parseInternal(UrlParser urlParser, java.lang.String url, java.util.Properties properties) throws java.sql.SQLException
Parses the connection URL in order to set the UrlParser instance with all the information provided through the URL.- Parameters:
urlParser
- object instance in which all data from the connection url is storedurl
- connection URLproperties
- properties- Throws:
java.sql.SQLException
- if format is incorrect
-
defineUrlParserParameters
private static void defineUrlParserParameters(UrlParser urlParser, java.util.Properties properties, java.lang.String hostAddressesString, java.lang.String additionalParameters) throws java.sql.SQLException
Sets the parameters of the UrlParser instance: addresses, database and options. It parses through the additional parameters given in order to extract the database and the options for the connection.- Parameters:
urlParser
- object instance in which all data from the connection URL is storedproperties
- propertieshostAddressesString
- string that holds all the host addressesadditionalParameters
- string that holds all parameters defined for the connection- Throws:
java.sql.SQLException
- if credential plugin cannot be loaded
-
parseHaMode
private static HaMode parseHaMode(java.lang.String url, int separator)
-
setDefaultHostAddressType
private static void setDefaultHostAddressType(UrlParser urlParser)
-
setInitialUrl
private void setInitialUrl()
-
auroraPipelineQuirks
public UrlParser auroraPipelineQuirks()
Permit to set parameters not forced. if options useBatchMultiSend and usePipelineAuth are not explicitly set in connection string, value will default to true or false according if aurora detection.- Returns:
- UrlParser for easy testing
-
isAurora
public boolean isAurora()
Detection of Aurora.Aurora rely on MySQL, then cannot be identified by protocol. But Aurora doesn't permit some behaviour normally working with MySQL : pipelining. So Driver must identified if server is Aurora to disable pipeline options that are enable by default.
- Returns:
- true if aurora.
-
parseUrl
public void parseUrl(java.lang.String url) throws java.sql.SQLException
Parse url connection string.- Parameters:
url
- connection string- Throws:
java.sql.SQLException
- if url format is incorrect
-
getUsername
public java.lang.String getUsername()
-
setUsername
public void setUsername(java.lang.String username)
-
getPassword
public java.lang.String getPassword()
-
setPassword
public void setPassword(java.lang.String password)
-
getDatabase
public java.lang.String getDatabase()
-
setDatabase
public void setDatabase(java.lang.String database)
-
getHostAddresses
public java.util.List<HostAddress> getHostAddresses()
-
getOptions
public Options getOptions()
-
setProperties
protected void setProperties(java.lang.String urlParameters)
-
getCredentialPlugin
public CredentialPlugin getCredentialPlugin()
-
toString
public java.lang.String toString()
ToString implementation.- Overrides:
toString
in classjava.lang.Object
- Returns:
- String value
-
getInitialUrl
public java.lang.String getInitialUrl()
-
getHaMode
public HaMode getHaMode()
-
equals
public boolean equals(java.lang.Object parser)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
loadMultiMasterValue
private void loadMultiMasterValue()
-
isMultiMaster
public boolean isMultiMaster()
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
-