Class HostInfo

java.lang.Object
com.mysql.cj.conf.HostInfo
All Implemented Interfaces:
DatabaseUrlContainer

public class HostInfo
extends java.lang.Object
implements DatabaseUrlContainer
This class holds the following MySQL host information:
  • host: an IP or host name.
  • port: the port number or 0 if not known.
  • user info: a structure containing the user name and password.
  • host properties: host specific connection arguments.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static int NO_PORT  
  • Constructor Summary

    Constructors 
    Constructor Description
    HostInfo()
    Constructs an empty HostInfo instance.
    HostInfo​(DatabaseUrlContainer url, java.lang.String host, int port, java.lang.String user, java.lang.String password)
    Constructs a HostInfo instance initialized with the provided host, port and user info.
    HostInfo​(DatabaseUrlContainer url, java.lang.String host, int port, java.lang.String user, java.lang.String password, boolean isPasswordless, java.util.Map<java.lang.String,​java.lang.String> properties)
    Constructs a HostInfo instance initialized with the provided host, port, user, password and connection arguments.
    HostInfo​(DatabaseUrlContainer url, java.lang.String host, int port, java.lang.String user, java.lang.String password, java.util.Map<java.lang.String,​java.lang.String> properties)
    Constructs a HostInfo instance initialized with the provided host, port, user, password and connection arguments.
  • Method Summary

    Modifier and Type Method Description
    boolean equalHostPortPair​(HostInfo hi)
    Checks if this HostInfo has the same host and port pair as the given HostInfo.
    java.util.Properties exposeAsProperties()
    Exposes this host info as a single properties instance.
    java.lang.String getDatabase()
    Shortcut to the database connection argument.
    java.lang.String getDatabaseUrl()
    Returns the original database URL that produced this host info.
    java.lang.String getHost()
    Returns the host.
    java.lang.String getHostPortPair()
    Returns a host:port representation of this host.
    java.util.Map<java.lang.String,​java.lang.String> getHostProperties()
    Returns the properties specific to this host.
    java.lang.String getPassword()
    Returns the password.
    int getPort()
    Returns the port.
    java.lang.String getProperty​(java.lang.String key)
    Returns the connection argument for the given key.
    java.lang.String getUser()
    Returns the user name.
    boolean isPasswordless()
    Returns true if the is the default one, i.e., no password was provided in the connection URL or arguments.
    java.lang.String toString()
    Returns a string representation of this object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • HostInfo

      public HostInfo()
      Constructs an empty HostInfo instance.
    • HostInfo

      public HostInfo​(DatabaseUrlContainer url, java.lang.String host, int port, java.lang.String user, java.lang.String password)
      Constructs a HostInfo instance initialized with the provided host, port and user info.
      Parameters:
      url - a reference to the original database URL that produced this host info
      host - the host ip or name
      port - the port
      user - the user name
      password - the user's password
    • HostInfo

      public HostInfo​(DatabaseUrlContainer url, java.lang.String host, int port, java.lang.String user, java.lang.String password, java.util.Map<java.lang.String,​java.lang.String> properties)
      Constructs a HostInfo instance initialized with the provided host, port, user, password and connection arguments.
      Parameters:
      url - a reference to the original database URL that produced this host info
      host - the host ip or name
      port - the port
      user - the user name
      password - this user's password
      properties - a connection arguments map.
    • HostInfo

      public HostInfo​(DatabaseUrlContainer url, java.lang.String host, int port, java.lang.String user, java.lang.String password, boolean isPasswordless, java.util.Map<java.lang.String,​java.lang.String> properties)
      Constructs a HostInfo instance initialized with the provided host, port, user, password and connection arguments.
      Parameters:
      url - a reference to the original database URL that produced this host info
      host - the host ip or name
      port - the port
      user - the user name
      password - this user's password
      isPasswordless - no password was provided in the connection URL or arguments?
      properties - a connection arguments map.
  • Method Details

    • getHost

      public java.lang.String getHost()
      Returns the host.
      Returns:
      the host
    • getPort

      public int getPort()
      Returns the port.
      Returns:
      the port
    • getHostPortPair

      public java.lang.String getHostPortPair()
      Returns a host:port representation of this host.
      Returns:
      the host:port representation of this host
    • getUser

      public java.lang.String getUser()
      Returns the user name.
      Returns:
      the user name
    • getPassword

      public java.lang.String getPassword()
      Returns the password.
      Returns:
      the password
    • isPasswordless

      public boolean isPasswordless()
      Returns true if the is the default one, i.e., no password was provided in the connection URL or arguments.
      Returns:
      true if no password was provided in the connection URL or arguments.
    • getHostProperties

      public java.util.Map<java.lang.String,​java.lang.String> getHostProperties()
      Returns the properties specific to this host.
      Returns:
      this host specific properties
    • getProperty

      public java.lang.String getProperty​(java.lang.String key)
      Returns the connection argument for the given key.
      Parameters:
      key - key
      Returns:
      the connection argument for the given key
    • getDatabase

      public java.lang.String getDatabase()
      Shortcut to the database connection argument.
      Returns:
      the database name
    • exposeAsProperties

      public java.util.Properties exposeAsProperties()
      Exposes this host info as a single properties instance. The values for host, port, user and password are added to the properties map with their standard keys.
      Returns:
      a Properties instance containing the full host information.
    • getDatabaseUrl

      public java.lang.String getDatabaseUrl()
      Returns the original database URL that produced this host info.
      Specified by:
      getDatabaseUrl in interface DatabaseUrlContainer
      Returns:
      the original database URL
    • equalHostPortPair

      public boolean equalHostPortPair​(HostInfo hi)
      Checks if this HostInfo has the same host and port pair as the given HostInfo.
      Parameters:
      hi - the HostInfo to compare with.
      Returns:
      true if both objects have equal host and port pairs, false otherwise.
    • toString

      public java.lang.String toString()
      Returns a string representation of this object.
      Overrides:
      toString in class java.lang.Object
      Returns:
      a string representation of this object