Package com.mysql.cj.conf
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 intNO_PORT -
Constructor Summary
Constructors Constructor Description HostInfo()Constructs an emptyHostInfoinstance.HostInfo(DatabaseUrlContainer url, java.lang.String host, int port, java.lang.String user, java.lang.String password)Constructs aHostInfoinstance 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 aHostInfoinstance 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 aHostInfoinstance initialized with the provided host, port, user, password and connection arguments. -
Method Summary
Modifier and Type Method Description booleanequalHostPortPair(HostInfo hi)java.util.PropertiesexposeAsProperties()Exposes this host info as a single properties instance.java.lang.StringgetDatabase()Shortcut to the database connection argument.java.lang.StringgetDatabaseUrl()Returns the original database URL that produced this host info.java.lang.StringgetHost()Returns the host.java.lang.StringgetHostPortPair()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.StringgetPassword()Returns the password.intgetPort()Returns the port.java.lang.StringgetProperty(java.lang.String key)Returns the connection argument for the given key.java.lang.StringgetUser()Returns the user name.booleanisPasswordless()Returns true if the is the default one, i.e., no password was provided in the connection URL or arguments.java.lang.StringtoString()Returns a string representation of this object.
-
Field Details
-
NO_PORT
public static final int NO_PORT- See Also:
- Constant Field Values
-
-
Constructor Details
-
HostInfo
public HostInfo()Constructs an emptyHostInfoinstance. -
HostInfo
public HostInfo(DatabaseUrlContainer url, java.lang.String host, int port, java.lang.String user, java.lang.String password)Constructs aHostInfoinstance initialized with the provided host, port and user info.- Parameters:
url- a reference to the original database URL that produced this host infohost- the host ip or nameport- the portuser- the user namepassword- 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 aHostInfoinstance initialized with the provided host, port, user, password and connection arguments.- Parameters:
url- a reference to the original database URL that produced this host infohost- the host ip or nameport- the portuser- the user namepassword- this user's passwordproperties- 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 aHostInfoinstance initialized with the provided host, port, user, password and connection arguments.- Parameters:
url- a reference to the original database URL that produced this host infohost- the host ip or nameport- the portuser- the user namepassword- this user's passwordisPasswordless- 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
Propertiesinstance containing the full host information.
-
getDatabaseUrl
public java.lang.String getDatabaseUrl()Returns the original database URL that produced this host info.- Specified by:
getDatabaseUrlin interfaceDatabaseUrlContainer- Returns:
- the original database URL
-
equalHostPortPair
- Parameters:
hi- theHostInfoto compare with.- Returns:
trueif both objects have equal host and port pairs,falseotherwise.
-
toString
public java.lang.String toString()Returns a string representation of this object.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of this object
-