Class 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|replica))][(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.
    example : 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=replica)(host=replica1)/database?user=greg&password=pass

    • 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
      • addresses

        private java.util.List<HostAddress> addresses
      • haMode

        private HaMode haMode
      • initialUrl

        private java.lang.String initialUrl
      • multiMaster

        private boolean multiMaster
    • 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 - database
        addresses - list of hosts
        options - connection option
        haMode - 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 string
        prop - 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 stored
        url - connection URL
        properties - 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 stored
        properties - properties
        hostAddressesString - string that holds all the host addresses
        additionalParameters - 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)
      • toString

        public java.lang.String toString()
        ToString implementation.
        Overrides:
        toString in class java.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 class java.lang.Object
      • hashCode

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

        private void loadMultiMasterValue()
      • isMultiMaster

        public boolean isMultiMaster()
      • clone

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