Skip to content

Commit

Permalink
refactor: use PGProperty enum instead of text ref for targetServerTyp…
Browse files Browse the repository at this point in the history
…e, hostRecheckSeconds, loadBalanceHosts (#912) (#915)
  • Loading branch information
zemian authored and vlsi committed Aug 10, 2017
1 parent 50d5dd3 commit b0cfc33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ public QueryExecutor openConnectionImpl(HostSpec[] hostSpecs, String user, Strin


// - the targetServerType setting // - the targetServerType setting
HostRequirement targetServerType; HostRequirement targetServerType;
String targetServerTypeStr = PGProperty.TARGET_SERVER_TYPE.get(info);
try { try {
targetServerType = targetServerType = HostRequirement.valueOf(targetServerTypeStr);
HostRequirement.valueOf(info.getProperty("targetServerType", HostRequirement.any.name()));
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
throw new PSQLException( throw new PSQLException(
GT.tr("Invalid targetServerType value: {0}", info.getProperty("targetServerType")), GT.tr("Invalid targetServerType value: {0}", targetServerTypeStr),
PSQLState.CONNECTION_UNABLE_TO_CONNECT); PSQLState.CONNECTION_UNABLE_TO_CONNECT);
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


package org.postgresql.hostchooser; 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.Arrays.asList;
import static java.util.Collections.shuffle; import static java.util.Collections.shuffle;
import static java.util.Collections.sort; import static java.util.Collections.sort;


import org.postgresql.PGProperty;
import org.postgresql.hostchooser.GlobalHostStatusTracker.HostSpecStatus; import org.postgresql.hostchooser.GlobalHostStatusTracker.HostSpecStatus;
import org.postgresql.util.HostSpec; import org.postgresql.util.HostSpec;
import org.postgresql.util.PSQLException;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
Expand All @@ -33,8 +33,12 @@ protected MultiHostChooser(HostSpec[] hostSpecs, HostRequirement targetServerTyp
Properties info) { Properties info) {
this.hostSpecs = hostSpecs; this.hostSpecs = hostSpecs;
this.targetServerType = targetServerType; this.targetServerType = targetServerType;
hostRecheckTime = parseInt(info.getProperty("hostRecheckSeconds", "10")) * 1000; try {
loadBalance = parseBoolean(info.getProperty("loadBalanceHosts", "false")); hostRecheckTime = PGProperty.HOST_RECHECK_SECONDS.getInt(info) * 1000;
loadBalance = PGProperty.LOAD_BALANCE_HOSTS.getBoolean(info);
} catch (PSQLException e) {
throw new RuntimeException(e);
}
} }


@Override @Override
Expand Down

0 comments on commit b0cfc33

Please sign in to comment.