Permalink
Browse files

honour PGPORT, PGHOST, PGDBNAME in connection properties (#862)

* honour PGPORT, PGHOST, PGDBNAME in connection properties
  • Loading branch information...
davecramer committed Jul 25, 2017
1 parent 5334cb6 commit 2951a9583b8ea1b1b0e933896ff4be95628f834e
@@ -577,9 +577,19 @@ public static Properties parseURL(String url, Properties defaults) {
urlProps.setProperty("PGPORT", ports.toString());
urlProps.setProperty("PGHOST", hosts.toString());
} else {
urlProps.setProperty("PGPORT", "/*$mvn.project.property.template.default.pg.port$*/");
urlProps.setProperty("PGHOST", "localhost");
urlProps.setProperty("PGDBNAME", URLDecoder.decode(l_urlServer));
/*
if there are no defaults set or any one of PORT, HOST, DBNAME not set
then set it to default
*/
if (defaults == null || !defaults.containsKey("PGPORT")) {
urlProps.setProperty("PGPORT", "/*$mvn.project.property.template.default.pg.port$*/");
}
if (defaults == null || !defaults.containsKey("PGHOST")) {
urlProps.setProperty("PGHOST", "localhost");
}
if (defaults == null || !defaults.containsKey("PGDBNAME")) {
urlProps.setProperty("PGDBNAME", URLDecoder.decode(l_urlServer));
}
}
// parse the args part of the url
@@ -12,6 +12,7 @@
import static org.junit.Assert.fail;
import org.postgresql.Driver;
import org.postgresql.PGProperty;
import org.postgresql.test.TestUtil;
import org.postgresql.util.NullOutputStream;
import org.postgresql.util.WriterHandler;
@@ -76,9 +77,9 @@ private void verifyUrl(Driver drv, String url, String hosts, String ports, Strin
drv.getClass().getDeclaredMethod("parseURL", String.class, Properties.class);
parseMethod.setAccessible(true);
Properties p = (Properties) parseMethod.invoke(drv, url, null);
assertEquals(url, dbName, p.getProperty("PGDBNAME"));
assertEquals(url, hosts, p.getProperty("PGHOST"));
assertEquals(url, ports, p.getProperty("PGPORT"));
assertEquals(url, dbName, p.getProperty(PGProperty.PG_DBNAME.getName()));
assertEquals(url, hosts, p.getProperty(PGProperty.PG_HOST.getName()));
assertEquals(url, ports, p.getProperty(PGProperty.PG_PORT.getName()));
}
/**

0 comments on commit 2951a95

Please sign in to comment.