public abstract class ConnectionUrl extends Object implements DatabaseUrlContainer
Modifier and Type | Class | 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 | Description |
---|---|---|
private static LRUCache<String,ConnectionUrl> |
connectionUrlCache |
|
static String |
DEFAULT_HOST |
|
static int |
DEFAULT_PORT |
|
protected List<HostInfo> |
hosts |
|
protected String |
originalConnStr |
|
protected String |
originalDatabase |
|
protected Map<String,String> |
properties |
|
(package private) ConnectionPropertiesTransform |
propertiesTransformer |
|
private static ReadWriteLock |
rwLock |
|
protected ConnectionUrl.Type |
type |
Modifier | Constructor | Description |
---|---|---|
protected |
ConnectionUrl() |
Empty constructor.
|
protected |
ConnectionUrl(ConnectionUrlParser connStrParser,
Properties info) |
Constructs an instance of
ConnectionUrl , performing all the required initializations. |
|
ConnectionUrl(String origUrl) |
Constructor for unsupported URLs
|
Modifier and Type | Method | Description |
---|---|---|
static boolean |
acceptsUrl(String connString) |
Checks if this
ConnectionUrl is able to process the given database URL. |
private static String |
buildConnectionStringCacheKey(String connString,
Properties info) |
Builds a connection URL cache map key based on the connection string itself plus the string representation of the given connection properties.
|
protected HostInfo |
buildHostInfo(String host,
int port,
String user,
String password,
Map<String,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,
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(Map<String,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(Map<String,String> hostProps) |
Fixes the protocol (TCP vs PIPE) dependencies for the given host properties map.
|
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(String connString,
Properties info) |
Static factory method that returns either a new instance of a
ConnectionUrl or a cached one. |
String |
getDatabase() |
Returns the database from this connection URL.
|
String |
getDatabaseUrl() |
Returns the original database URL that produced this connection string.
|
String |
getDefaultHost() |
Returns the default host.
|
String |
getDefaultPassword() |
Returns the default password.
|
int |
getDefaultPort() |
Returns the default port.
|
String |
getDefaultUser() |
Returns the default user.
|
HostInfo |
getHostOrSpawnIsolated(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(String hostPortPair,
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.
|
List<HostInfo> |
getHostsList() |
Returns a list of the hosts in this connection URL.
|
List<HostInfo> |
getHostsList(HostsListView view) |
Returns a list of the hosts in this connection URL, filtered for the given view.
|
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.
|
Map<String,String> |
getOriginalProperties() |
Returns the original (common to all hosts) connection arguments as provided in the connection string query section.
|
static Properties |
getPropertiesFromConfigFiles(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(Map<String,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(Map<String,String> hostProps) |
Subclasses should override this to perform any required pre-processing on the host information properties.
|
protected void |
replaceLegacyPropertyValues(Map<String,String> props) |
Some acceptable property values have changed in c/J 8.0 but old values remain hard-coded in widely used software.
|
protected void |
setupPropertiesTransformer() |
Sets up the
ConnectionPropertiesTransform if one was provided. |
private List<HostInfo> |
srvRecordsToHostsList(List<DnsSrv.SrvRecord> srvRecords,
HostInfo baseHostInfo) |
Converts a list of DNS SRV records into a hosts list.
|
String |
toString() |
Returns a string representation of this object.
|
public static final String DEFAULT_HOST
public static final int DEFAULT_PORT
private static final LRUCache<String,ConnectionUrl> connectionUrlCache
private static final ReadWriteLock rwLock
protected ConnectionUrl.Type type
protected String originalConnStr
protected String originalDatabase
ConnectionPropertiesTransform propertiesTransformer
protected ConnectionUrl()
public ConnectionUrl(String origUrl)
origUrl
- URLsprotected ConnectionUrl(ConnectionUrlParser connStrParser, 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(String connString, 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 stringprivate static String buildConnectionStringCacheKey(String connString, Properties info)
connString
- the connection stringinfo
- the connection arguments mappublic static boolean acceptsUrl(String connString)
ConnectionUrl
is able to process the given database URL.connString
- the connection stringprotected void collectProperties(ConnectionUrlParser connStrParser, 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(Map<String,String> props)
props
- a connection arguments map from where to read the "useConfig" property and where to save the loaded properties.public static Properties getPropertiesFromConfigFiles(String configFiles)
configFiles
- the list of the configuration files to readprotected void injectPerTypeProperties(Map<String,String> props)
props
- the properties already containing all known connection argumentsprotected void replaceLegacyPropertyValues(Map<String,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(Map<String,String> hostProps)
hostProps
- the host properties map to processpublic String getDefaultHost()
public int getDefaultPort()
public String getDefaultUser()
DriverManager.getConnection(String, String, String)
or as connection argument.public String getDefaultPassword()
DriverManager.getConnection(String, String, String)
or as connection
argument.protected void fixProtocolDependencies(Map<String,String> hostProps)
hostProps
- the host properties map to fixpublic ConnectionUrl.Type getType()
public String getDatabaseUrl()
getDatabaseUrl
in interface DatabaseUrlContainer
public String getDatabase()
public int hostsCount()
public HostInfo getMainHost()
public List<HostInfo> getHostsList()
public 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(String hostPortPair)
hostPortPair
- the host:port part to search forpublic HostInfo getHostOrSpawnIsolated(String hostPortPair, List<HostInfo> hostsList)
hostPortPair
- the host:port part to search forhostsList
- the hosts list from where to search the host listprotected HostInfo buildHostInfo(String host, int port, String user, String password, Map<String,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 passwordhostProps
- the host properties mapHostInfo
public Map<String,String> getOriginalProperties()
public 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 List<HostInfo> getHostsListFromDnsSrv(HostInfo srvHost)
srvHost
- the HostInfo
from where to get the DNS SRV service name to lookup.private List<HostInfo> srvRecordsToHostsList(List<DnsSrv.SrvRecord> srvRecords, HostInfo baseHostInfo)
srvRecords
- the list of DNS SRV records.baseHostInfo
- the HostInfo
to use as source of all common host specific options.