public abstract class ConnectionUrl extends java.lang.Object implements DatabaseUrlContainer
| Modifier and Type | Class and Description |
|---|---|
static class |
ConnectionUrl.HostsCardinality
The rules describing the number of hosts a database URL may contain.
|
static class |
ConnectionUrl.Type
The database URL type which is determined by the scheme section of the connection string.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_HOST |
static int |
DEFAULT_PORT |
protected java.util.List<HostInfo> |
hosts |
protected java.lang.String |
originalConnStr |
protected java.lang.String |
originalDatabase |
protected java.util.Map<java.lang.String,java.lang.String> |
properties |
protected ConnectionUrl.Type |
type |
| Modifier | Constructor and Description |
|---|---|
protected |
ConnectionUrl()
Empty constructor.
|
protected |
ConnectionUrl(ConnectionUrlParser connStrParser,
java.util.Properties info)
Constructs an instance of
ConnectionUrl, performing all the required initializations. |
|
ConnectionUrl(java.lang.String origUrl)
Constructor for unsupported URLs
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
acceptsUrl(java.lang.String connString)
Checks if this
ConnectionUrl is able to process the given database URL. |
protected HostInfo |
buildHostInfo(java.lang.String host,
int port,
java.lang.String user,
java.lang.String password,
boolean isDefaultPwd,
java.util.Map<java.lang.String,java.lang.String> hostProps)
Creates a new
HostInfo structure with the given components, passing through the properties transformer if there is one defined in this connection
string; |
protected void |
collectHostsInfo(ConnectionUrlParser connStrParser)
Collects the hosts information from the
ConnectionUrlParser. |
protected void |
collectProperties(ConnectionUrlParser connStrParser,
java.util.Properties info)
Joins the connection arguments from the connection string with the ones from the given connection arguments map collecting them in a single map.
|
protected void |
expandPropertiesFromConfigFiles(java.util.Map<java.lang.String,java.lang.String> props)
Expands the connection argument "useConfig" by reading the mentioned configuration files.
|
protected HostInfo |
fixHostInfo(HostInfo hi)
Fixes the host information by moving data around and filling in missing data.
|
protected void |
fixProtocolDependencies(java.util.Map<java.lang.String,java.lang.String> hostProps)
Fixes the protocol (TCP vs PIPE) dependencies for the given host properties map.
|
java.util.Properties |
getConnectionArgumentsAsProperties()
Returns a
Properties instance containing the connection arguments extracted from the URL query section, i.e., per host attributes are excluded. |
static ConnectionUrl |
getConnectionUrlInstance(java.lang.String connString,
java.util.Properties info)
Static factory method that returns either a new instance of a
ConnectionUrl or a cached one. |
java.lang.String |
getDatabase()
Returns the database from this connection URL.
|
java.lang.String |
getDatabaseUrl()
Returns the original database URL that produced this connection string.
|
java.lang.String |
getDefaultHost()
Returns the default host.
|
java.lang.String |
getDefaultPassword()
Returns the default password.
|
int |
getDefaultPort()
Returns the default port.
|
java.lang.String |
getDefaultUser()
Returns the default user.
|
HostInfo |
getHostOrSpawnIsolated(java.lang.String hostPortPair)
Returns an existing host info with the same host:port part or spawns a new isolated host info based on this connection URL if none was found.
|
HostInfo |
getHostOrSpawnIsolated(java.lang.String hostPortPair,
java.util.List<HostInfo> hostsList)
Returns an existing host info with the same host:port part or spawns a new isolated host info based on this connection URL if none was found.
|
java.util.List<HostInfo> |
getHostsList()
Returns a list of the hosts in this connection URL.
|
java.util.List<HostInfo> |
getHostsList(HostsListView view)
Returns a list of the hosts in this connection URL, filtered for the given view.
|
java.util.List<HostInfo> |
getHostsListFromDnsSrv(HostInfo srvHost)
Returns a hosts list built from the result of the DNS SRV lookup for the original host name.
|
HostInfo |
getMainHost()
Returns the single or first host info structure.
|
java.util.Map<java.lang.String,java.lang.String> |
getOriginalProperties()
Returns the original (common to all hosts) connection arguments as provided in the connection string query section.
|
static java.util.Properties |
getPropertiesFromConfigFiles(java.lang.String configFiles)
Returns a map containing the properties read from the given configuration files.
|
ConnectionUrl.Type |
getType()
Returns this connection URL type.
|
int |
hostsCount()
Returns the number of hosts in this connection URL.
|
protected void |
injectPerTypeProperties(java.util.Map<java.lang.String,java.lang.String> props)
Subclasses must override this method if they need to inject additional properties in the connection arguments map while it's being constructed.
|
protected void |
preprocessPerTypeHostProperties(java.util.Map<java.lang.String,java.lang.String> hostProps)
Subclasses should override this to perform any required pre-processing on the host information properties.
|
protected void |
replaceLegacyPropertyValues(java.util.Map<java.lang.String,java.lang.String> props)
Some acceptable property values have changed in c/J 8.0 but old values remain hardcoded in a widely used software.
|
protected void |
setupPropertiesTransformer()
Sets up the
ConnectionPropertiesTransform if one was provided. |
java.lang.String |
toString()
Returns a string representation of this object.
|
public static final java.lang.String DEFAULT_HOST
public static final int DEFAULT_PORT
protected ConnectionUrl.Type type
protected java.lang.String originalConnStr
protected java.lang.String originalDatabase
protected java.util.List<HostInfo> hosts
protected java.util.Map<java.lang.String,java.lang.String> properties
protected ConnectionUrl()
public ConnectionUrl(java.lang.String origUrl)
origUrl - URLsprotected ConnectionUrl(ConnectionUrlParser connStrParser, java.util.Properties info)
ConnectionUrl, performing all the required initializations.connStrParser - a ConnectionUrlParser instance containing the parsed version of the original connection stringinfo - the connection arguments mappublic static ConnectionUrl getConnectionUrlInstance(java.lang.String connString, java.util.Properties info)
ConnectionUrl or a cached one.
Returns "null" it can't handle the connection string.connString - the connection stringinfo - the connection arguments mapConnectionUrl or "null" if isn't able to handle the connection stringpublic static boolean acceptsUrl(java.lang.String connString)
ConnectionUrl is able to process the given database URL.connString - the connection stringprotected void collectProperties(ConnectionUrlParser connStrParser, java.util.Properties info)
connStrParser - the ConnectionUrlParser from where to collect the propertiesinfo - the connection arguments mapprotected void setupPropertiesTransformer()
ConnectionPropertiesTransform if one was provided.protected void expandPropertiesFromConfigFiles(java.util.Map<java.lang.String,java.lang.String> props)
props - a connection arguments map from where to read the "useConfig" property and where to save the loaded properties.public static java.util.Properties getPropertiesFromConfigFiles(java.lang.String configFiles)
configFiles - the list of the configuration files to readprotected void injectPerTypeProperties(java.util.Map<java.lang.String,java.lang.String> props)
props - the properties already containing all known connection argumentsprotected void replaceLegacyPropertyValues(java.util.Map<java.lang.String,java.lang.String> props)
props - the host properties map to fixprotected void collectHostsInfo(ConnectionUrlParser connStrParser)
ConnectionUrlParser.connStrParser - the ConnectionUrlParser from where to collect the hosts informationprotected HostInfo fixHostInfo(HostInfo hi)
ConnectionPropertiesTransform was declared in the connection arguments.hi - the host information data to fixHostInfo with all required dataprotected void preprocessPerTypeHostProperties(java.util.Map<java.lang.String,java.lang.String> hostProps)
hostProps - the host properties map to processpublic java.lang.String getDefaultHost()
public int getDefaultPort()
public java.lang.String getDefaultUser()
DriverManager.getConnection(String, String, String) or as connection argument.public java.lang.String getDefaultPassword()
DriverManager.getConnection(String, String, String) or as connection
argument.protected void fixProtocolDependencies(java.util.Map<java.lang.String,java.lang.String> hostProps)
hostProps - the host properties map to fixpublic ConnectionUrl.Type getType()
public java.lang.String getDatabaseUrl()
getDatabaseUrl in interface DatabaseUrlContainerpublic java.lang.String getDatabase()
public int hostsCount()
public HostInfo getMainHost()
public java.util.List<HostInfo> getHostsList()
public java.util.List<HostInfo> getHostsList(HostsListView view)
view - the type of the view to use in the returned list of hosts. This argument is ignored in this implementation.public HostInfo getHostOrSpawnIsolated(java.lang.String hostPortPair)
hostPortPair - the host:port part to search forpublic HostInfo getHostOrSpawnIsolated(java.lang.String hostPortPair, java.util.List<HostInfo> hostsList)
hostPortPair - the host:port part to search forhostsList - the hosts list from where to search the host listprotected HostInfo buildHostInfo(java.lang.String host, int port, java.lang.String user, java.lang.String password, boolean isDefaultPwd, java.util.Map<java.lang.String,java.lang.String> hostProps)
HostInfo structure with the given components, passing through the properties transformer if there is one defined in this connection
string;host - the hostport - the portuser - the user namepassword - the passwordisDefaultPwd - no password was provided in the connection URL or arguments?hostProps - the host properties mapHostInfopublic java.util.Map<java.lang.String,java.lang.String> getOriginalProperties()
public java.util.Properties getConnectionArgumentsAsProperties()
Properties instance containing the connection arguments extracted from the URL query section, i.e., per host attributes are excluded.
Applies properties transformations to the collected properties if ConnectionPropertiesTransform was declared in the connection arguments.Properties instance containing the common connection arguments.public java.util.List<HostInfo> getHostsListFromDnsSrv(HostInfo srvHost)
srvHost - the HostInfo from where to get the DNS SRV service name to lookup.public java.lang.String toString()
toString in class java.lang.Object