in src/main/core-impl/java/com/mysql/cj/conf/url/ReplicationDnsSrvConnectionUrl.java [58:124]
public ReplicationDnsSrvConnectionUrl(ConnectionUrlParser connStrParser, Properties info) {
super(connStrParser, info);
this.type = Type.REPLICATION_DNS_SRV_CONNECTION;
// Split sources and replicas:
LinkedList<HostInfo> undefinedHosts = new LinkedList<>();
for (HostInfo hi : this.hosts) {
Map<String, String> hostProperties = hi.getHostProperties();
if (hostProperties.containsKey(PropertyKey.TYPE.getKeyName())) {
if (TYPE_SOURCE.equalsIgnoreCase(hostProperties.get(PropertyKey.TYPE.getKeyName()))) {
this.sourceHosts.add(hi);
} else if (TYPE_REPLICA.equalsIgnoreCase(hostProperties.get(PropertyKey.TYPE.getKeyName()))) {
this.replicaHosts.add(hi);
} else {
undefinedHosts.add(hi);
}
} else {
undefinedHosts.add(hi);
}
}
if (!undefinedHosts.isEmpty()) {
if (this.sourceHosts.isEmpty()) {
this.sourceHosts.add(undefinedHosts.removeFirst());
}
this.replicaHosts.addAll(undefinedHosts);
}
/*
* Validate the hosts list:
* 1. Exactly two hosts (SRV service name) must be provided.
* 2. No more than one host (SRV service name) per type can be provided.
* 3. No port can be provided, i.e., port number must be equals to DEFAULT_PORT.
* 4. If property 'dnsSrv' is set then it cannot be "false".
* 5. Property 'protocol' cannot be "PIPE".
* 6. Property 'replicationConnectionGroup' cannot be set.
*/
HostInfo srvHostSource = this.sourceHosts.isEmpty() ? null : this.sourceHosts.get(0);
Map<String, String> hostPropsSource = srvHostSource == null ? Collections.emptyMap() : srvHostSource.getHostProperties();
HostInfo srvHostReplica = this.replicaHosts.isEmpty() ? null : this.replicaHosts.get(0);
Map<String, String> hostPropsReplica = srvHostReplica == null ? Collections.emptyMap() : srvHostReplica.getHostProperties();
if (srvHostSource == null || srvHostReplica == null || DEFAULT_HOST.equals(srvHostSource.getHost()) || DEFAULT_HOST.equals(srvHostReplica.getHost())) {
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class, Messages.getString("ConnectionString.20"));
}
if (this.sourceHosts.size() != 1 || this.replicaHosts.size() != 1) {
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class, Messages.getString("ConnectionString.21"));
}
if (srvHostSource.getPort() != DEFAULT_PORT || srvHostReplica.getPort() != DEFAULT_PORT) {
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class, Messages.getString("ConnectionString.22"));
}
if (hostPropsSource.containsKey(PropertyKey.dnsSrv.getKeyName()) || hostPropsReplica.containsKey(PropertyKey.dnsSrv.getKeyName())) {
if (!BooleanPropertyDefinition.booleanFrom(PropertyKey.dnsSrv.getKeyName(), hostPropsSource.get(PropertyKey.dnsSrv.getKeyName()), null)
|| !BooleanPropertyDefinition.booleanFrom(PropertyKey.dnsSrv.getKeyName(), hostPropsReplica.get(PropertyKey.dnsSrv.getKeyName()), null)) {
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class,
Messages.getString("ConnectionString.23", new Object[] { PropertyKey.dnsSrv.getKeyName() }));
}
}
if (hostPropsSource.containsKey(PropertyKey.PROTOCOL.getKeyName()) && hostPropsSource.get(PropertyKey.PROTOCOL.getKeyName()).equalsIgnoreCase("PIPE")
|| hostPropsReplica.containsKey(PropertyKey.PROTOCOL.getKeyName())
&& hostPropsReplica.get(PropertyKey.PROTOCOL.getKeyName()).equalsIgnoreCase("PIPE")) {
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class, Messages.getString("ConnectionString.24"));
}
if (hostPropsSource.containsKey(PropertyKey.replicationConnectionGroup.getKeyName())
|| hostPropsReplica.containsKey(PropertyKey.replicationConnectionGroup.getKeyName())) {
throw ExceptionFactory.createException(InvalidConnectionAttributeException.class,
Messages.getString("ConnectionString.25", new Object[] { PropertyKey.replicationConnectionGroup.getKeyName() }));
}
}