postgresql-jdbc.git / summary / log / commit / refs

commit    a7f42ead0f6a9031b4e5bb79d689aaa682a92335
Author:   Dave Cramer <davecramer@gmail.com>
Commit:   GitHub <noreply@github.com>
Date:     Wed Feb 16 17:57:10 2022 +0000

    fix: Use PGProperty instead of the property names directly (#2444)
    
    * fix: Use PGProperty instead of the property names directly
    
    * fix: Added LOCAL_SOCKET_ADDRESS PGProperty


pgjdbc/src/main/java/org/postgresql/Driver.java | 6 +++--- pgjdbc/src/main/java/org/postgresql/PGProperty.java | 9 +++++++++ .../java/org/postgresql/ds/common/BaseDataSource.java | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pgjdbc/src/main/java/org/postgresql/Driver.java b/pgjdbc/src/main/java/org/postgresql/Driver.java index b97f7a97..b3b069de 100644 --- a/pgjdbc/src/main/java/org/postgresql/Driver.java +++ b/pgjdbc/src/main/java/org/postgresql/Driver.java @@ -656,9 +656,9 @@ public class Driver implements java.sql.Driver { * @return the address portion of the URL */ private static HostSpec[] hostSpecs(Properties props) { - String[] hosts = castNonNull(props.getProperty("PGHOST")).split(","); - String[] ports = castNonNull(props.getProperty("PGPORT")).split(","); - String localSocketAddress = props.getProperty("localSocketAddress"); + String[] hosts = castNonNull(PGProperty.PG_HOST.get(props)).split(","); + String[] ports = castNonNull(PGProperty.PG_PORT.get(props)).split(","); + String localSocketAddress = PGProperty.LOCAL_SOCKET_ADDRESS.get(props); HostSpec[] hostSpecs = new HostSpec[hosts.length]; for (int i = 0; i < hostSpecs.length; ++i) { hostSpecs[i] = new HostSpec(hosts[i], Integer.parseInt(ports[i]), localSocketAddress); diff --git a/pgjdbc/src/main/java/org/postgresql/PGProperty.java b/pgjdbc/src/main/java/org/postgresql/PGProperty.java index f234c2a2..4a87ac2f 100644 --- a/pgjdbc/src/main/java/org/postgresql/PGProperty.java +++ b/pgjdbc/src/main/java/org/postgresql/PGProperty.java @@ -292,6 +292,15 @@ public enum PGProperty { "false", "If disabled hosts are connected in the given order. If enabled hosts are chosen randomly from the set of suitable candidates"), + /** + * <p>If this is set then the client side will bind to this address. This is useful if you need + * to choose which interface to connect to.</p> + */ + LOCAL_SOCKET_ADDRESS( + "localSocketAddress", + null, + "Local Socket address, if set bind the client side of the socket to this address"), + /** * This property is no longer used by the driver and will be ignored. * Logging is configured via java.util.logging. diff --git a/pgjdbc/src/main/java/org/postgresql/ds/common/BaseDataSource.java b/pgjdbc/src/main/java/org/postgresql/ds/common/BaseDataSource.java index 83fc385e..384d40fb 100644 --- a/pgjdbc/src/main/java/org/postgresql/ds/common/BaseDataSource.java +++ b/pgjdbc/src/main/java/org/postgresql/ds/common/BaseDataSource.java @@ -1207,6 +1207,22 @@ public abstract class BaseDataSource implements CommonDataSource, Referenceable return PGProperty.REPLICATION.get(properties); } + /** + * @return the localSocketAddress + * @see PGProperty#LOCAL_SOCKET_ADDRESS + */ + public @Nullable String getLocalSocketAddress() { + return PGProperty.LOCAL_SOCKET_ADDRESS.get(properties); + } + + /** + * @param localSocketAddress local address to bind client side to + * @see PGProperty#LOCAL_SOCKET_ADDRESS + */ + public void setLocalSocketAddress( String localSocketAddress ) { + PGProperty.LOCAL_SOCKET_ADDRESS.set(properties,localSocketAddress); + } + /** * This property is no longer used by the driver and will be ignored. * @return loggerLevel in properties [parent: 50f6d510a882]