diff --git a/src/main/core-api/java/com/mysql/cj/conf/ConnectionUrl.java b/src/main/core-api/java/com/mysql/cj/conf/ConnectionUrl.java index d15506a78..27417cf9e 100644 --- a/src/main/core-api/java/com/mysql/cj/conf/ConnectionUrl.java +++ b/src/main/core-api/java/com/mysql/cj/conf/ConnectionUrl.java @@ -372,6 +372,11 @@ protected void collectProperties(ConnectionUrlParser connStrParser, Properties i setupPropertiesTransformer(); expandPropertiesFromConfigFiles(this.properties); injectPerTypeProperties(this.properties); + + // Fix protocol dependencies in global properties (e.g., set socketFactory when protocol=PIPE). + fixProtocolDependencies(this.properties); + // Workaround for zeroDateTimeBehavior=convertToNull hard-coded in NetBeans + replaceLegacyPropertyValues(this.properties); } /** diff --git a/src/test/java/com/mysql/cj/ConnectionUrlTest.java b/src/test/java/com/mysql/cj/ConnectionUrlTest.java index 5fba34a69..c56c6ae33 100644 --- a/src/test/java/com/mysql/cj/ConnectionUrlTest.java +++ b/src/test/java/com/mysql/cj/ConnectionUrlTest.java @@ -1206,6 +1206,39 @@ public void testReplaceLegacyPropertyValues() throws Exception { } } + @Test + public void testReplaceLegacyPropertyValuesInGlobalPropsForMultiHost() throws Exception { + // URL-level legacy value + String cs1 = "jdbc:mysql://host1:3306,host2:3306/db?zeroDateTimeBehavior=convertToNull"; + ConnectionUrl url1 = ConnectionUrl.getConnectionUrlInstance(cs1, null); + assertEquals(ZeroDatetimeBehavior.CONVERT_TO_NULL.name(), + url1.getConnectionArgumentsAsProperties().getProperty(PropertyKey.zeroDateTimeBehavior.getKeyName())); + // Info map legacy value + String cs2 = "jdbc:mysql://host1:3306,host2:3306/db"; + Properties p2 = new Properties(); + p2.setProperty(PropertyKey.zeroDateTimeBehavior.getKeyName(), "convertToNull"); + ConnectionUrl url2 = ConnectionUrl.getConnectionUrlInstance(cs2, p2); + assertEquals(ZeroDatetimeBehavior.CONVERT_TO_NULL.name(), + url2.getConnectionArgumentsAsProperties().getProperty(PropertyKey.zeroDateTimeBehavior.getKeyName())); + // Mixed: URL has unrelated params, info has legacy value + String cs3 = "jdbc:mysql://host1:3306,host2:3306/db?useSSL=false&allowPublicKeyRetrieval=true"; + Properties p3 = new Properties(); + p3.setProperty(PropertyKey.zeroDateTimeBehavior.getKeyName(), "convertToNull"); + ConnectionUrl url3 = ConnectionUrl.getConnectionUrlInstance(cs3, p3); + assertEquals(ZeroDatetimeBehavior.CONVERT_TO_NULL.name(), + url3.getConnectionArgumentsAsProperties().getProperty(PropertyKey.zeroDateTimeBehavior.getKeyName())); + } + + @Test + public void testFixProtocolDependenciesAppliedToGlobalProps() { + // When protocol=pipe is specified globally, socketFactory should be auto-set in global props too + String cs = "jdbc:mysql://host1:3306,host2:3306/db?protocol=pipe"; + ConnectionUrl url = ConnectionUrl.getConnectionUrlInstance(cs, null); + Properties props = url.getConnectionArgumentsAsProperties(); + assertEquals("com.mysql.cj.protocol.NamedPipeSocketFactory", + props.getProperty(PropertyKey.socketFactory.getKeyName())); + } + /** * Tests jdbc:mysql+srv: connection strings. */