Permalink
Browse files

refactor: use PGProperty enum instead of text ref for targetServerTyp…

…e, hostRecheckSeconds, loadBalanceHosts (#912) (#915)
  • Loading branch information...
zemian authored and vlsi committed Aug 10, 2017
1 parent 50d5dd3 commit b0cfc33483759ed3583b57cd845311d17670524f
@@ -117,12 +117,12 @@ public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, Strin
// - the targetServerType setting
HostRequirement targetServerType;
String targetServerTypeStr = PGProperty.TARGET_SERVER_TYPE.get(info);
try {
targetServerType =
HostRequirement.valueOf(info.getProperty("targetServerType", HostRequirement.any.name()));
targetServerType = HostRequirement.valueOf(targetServerTypeStr);
} catch (IllegalArgumentException ex) {
throw new PSQLException(
GT.tr("Invalid targetServerType value: {0}", info.getProperty("targetServerType")),
GT.tr("Invalid targetServerType value: {0}", targetServerTypeStr),
PSQLState.CONNECTION_UNABLE_TO_CONNECT);
}
@@ -5,14 +5,14 @@
package org.postgresql.hostchooser;
import static java.lang.Boolean.parseBoolean;
import static java.lang.Integer.parseInt;
import static java.util.Arrays.asList;
import static java.util.Collections.shuffle;
import static java.util.Collections.sort;
import org.postgresql.PGProperty;
import org.postgresql.hostchooser.GlobalHostStatusTracker.HostSpecStatus;
import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLException;
import java.util.ArrayList;
import java.util.Comparator;
@@ -33,8 +33,12 @@ protected MultiHostChooser(HostSpec[] hostSpecs, HostRequirement targetServerTyp
Properties info) {
this.hostSpecs = hostSpecs;
this.targetServerType = targetServerType;
hostRecheckTime = parseInt(info.getProperty("hostRecheckSeconds", "10")) * 1000;
loadBalance = parseBoolean(info.getProperty("loadBalanceHosts", "false"));
try {
hostRecheckTime = PGProperty.HOST_RECHECK_SECONDS.getInt(info) * 1000;
loadBalance = PGProperty.LOAD_BALANCE_HOSTS.getBoolean(info);
} catch (PSQLException e) {
throw new RuntimeException(e);
}
}
@Override

0 comments on commit b0cfc33

Please sign in to comment.