Class UrlParser

java.lang.Object
org.mariadb.jdbc.UrlParser
All Implemented Interfaces:
Cloneable

public class UrlParser extends Object implements 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 Details

    • DISABLE_MYSQL_URL

      private static final String DISABLE_MYSQL_URL
      See Also:
    • URL_PARAMETER

      private static final Pattern URL_PARAMETER
    • AWS_PATTERN

      private static final Pattern AWS_PATTERN
    • database

      private String database
    • options

      private Options options
    • addresses

      private List<HostAddress> addresses
    • haMode

      private HaMode haMode
    • initialUrl

      private String initialUrl
    • multiMaster

      private boolean multiMaster
  • Constructor Details

  • Method Details

    • acceptsUrl

      public static boolean acceptsUrl(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(String url) throws SQLException
      Throws:
      SQLException
    • parse

      public static UrlParser parse(String url, Properties prop) throws SQLException
      Parse url connection string with additional properties.
      Parameters:
      url - connection string
      prop - properties
      Returns:
      UrlParser instance
      Throws:
      SQLException - if parsing exception occur
    • parseInternal

      private static void parseInternal(UrlParser urlParser, String url, Properties properties) throws 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 stored
      url - connection URL
      properties - properties
      Throws:
      SQLException - if format is incorrect
    • defineUrlParserParameters

      private static void defineUrlParserParameters(UrlParser urlParser, Properties properties, String hostAddressesString, String additionalParameters)
      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 stored
      properties - properties
      hostAddressesString - string that holds all the host addresses
      additionalParameters - string that holds all parameters defined for the connection
    • parseHaMode

      private static HaMode parseHaMode(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(String url) throws SQLException
      Parse url connection string.
      Parameters:
      url - connection string
      Throws:
      SQLException - if url format is incorrect
    • getUsername

      public String getUsername()
    • setUsername

      public void setUsername(String username)
    • getPassword

      public String getPassword()
    • setPassword

      public void setPassword(String password)
    • getDatabase

      public String getDatabase()
    • setDatabase

      public void setDatabase(String database)
    • getHostAddresses

      public List<HostAddress> getHostAddresses()
    • setHostAddresses

      public void setHostAddresses(List<HostAddress> addresses)
    • getOptions

      public Options getOptions()
    • setProperties

      protected void setProperties(String urlParameters)
    • toString

      public String toString()
      ToString implementation.
      Overrides:
      toString in class Object
      Returns:
      String value
    • getInitialUrl

      public String getInitialUrl()
    • getHaMode

      public HaMode getHaMode()
    • equals

      public boolean equals(Object parser)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • loadMultiMasterValue

      private void loadMultiMasterValue()
    • isMultiMaster

      public boolean isMultiMaster()
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException