Skip to content

Commit 8461b3c

Browse files
committed
Merge branch 'release/3.1.1'
2 parents 37c3a43 + 15ab4cc commit 8461b3c

File tree

14 files changed

+250
-117
lines changed

14 files changed

+250
-117
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
# Change Log
2+
## [3.1.1](https://github.com/mariadb-corporation/mariadb-connector-j/tree/3.1.1) (Jan 2023)
3+
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/3.1.0...3.1.1)
4+
5+
- 3.0.10 bug fix:
6+
- CONJ-1023 Connector/J doesn't set SSL cap bit in Handshake Response Packet
7+
- CONJ-1026 timezone=auto option failure on non-fixed-offset zone machine
8+
- CONJ-1032 Compatibility for deprecated arguments is case sensitive now
9+
- CONJ-1036 org.mariadb.jdbc.client.socket.impl.PacketWriter.writeAscii() broken in 3.1.0
10+
11+
12+
## [3.0.10](https://github.com/mariadb-corporation/mariadb-connector-j/tree/3.0.10) (Jan 2023)
13+
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/3.0.9...3.0.10)
14+
15+
* CONJ-1023 Connector/J doesn't set SSL cap bit in Handshake Response Packet
16+
* CONJ-1026 timezone=auto option failure on non-fixed-offset zone machine
17+
* CONJ-1032 Compatibility for deprecated arguments is case sensitive now
218

319
## [3.1.0](https://github.com/mariadb-corporation/mariadb-connector-j/tree/3.1.0) (Nov 2022)
420
[Full Changelog](https://github.com/mariadb-corporation/mariadb-connector-j/compare/3.0.9...3.1.0)

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>mariadb-java-client</artifactId>
88
<packaging>jar</packaging>
99
<name>mariadb-java-client</name>
10-
<version>3.1.0</version>
10+
<version>3.1.1</version>
1111
<description>JDBC driver for MariaDB and MySQL</description>
1212
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>
1313

src/main/java/org/mariadb/jdbc/Configuration.java

+49-40
Original file line numberDiff line numberDiff line change
@@ -617,55 +617,64 @@ private static void mapPropertiesToOption(Builder builder, Properties properties
617617
// loop on properties,
618618
// - check DefaultOption to check that property value correspond to type (and range)
619619
// - set values
620-
for (final Object keyObj : properties.keySet()) {
621-
String realKey = OptionAliases.OPTIONS_ALIASES.get(keyObj);
622-
if (realKey == null) realKey = keyObj.toString();
623-
final Object propertyValue = properties.get(keyObj);
624-
625-
if (propertyValue != null && realKey != null) {
626-
try {
627-
final Field field = Builder.class.getDeclaredField(realKey);
628-
field.setAccessible(true);
629-
if (field.getGenericType().equals(String.class)
630-
&& !propertyValue.toString().isEmpty()) {
631-
field.set(builder, propertyValue);
632-
} else if (field.getGenericType().equals(Boolean.class)) {
633-
switch (propertyValue.toString().toLowerCase()) {
634-
case "":
635-
case "1":
636-
case "true":
637-
field.set(builder, Boolean.TRUE);
638-
break;
639-
640-
case "0":
641-
case "false":
642-
field.set(builder, Boolean.FALSE);
643-
break;
644-
645-
default:
620+
Properties remainingProperties = new Properties();
621+
properties.forEach((key, val) -> remainingProperties.put(key, val));
622+
623+
for (Field field : Builder.class.getDeclaredFields()) {
624+
if (remainingProperties.isEmpty()) break;
625+
for (final Object keyObj : remainingProperties.keySet()) {
626+
String realKey =
627+
OptionAliases.OPTIONS_ALIASES.get(keyObj.toString().toLowerCase(Locale.ROOT));
628+
if (realKey == null) realKey = keyObj.toString();
629+
final Object propertyValue = remainingProperties.get(keyObj);
630+
631+
if (propertyValue != null && realKey != null) {
632+
if (realKey.toLowerCase(Locale.ROOT).equals(field.getName().toLowerCase(Locale.ROOT))) {
633+
field.setAccessible(true);
634+
remainingProperties.remove(keyObj);
635+
636+
if (field.getGenericType().equals(String.class)
637+
&& !propertyValue.toString().isEmpty()) {
638+
field.set(builder, propertyValue);
639+
} else if (field.getGenericType().equals(Boolean.class)) {
640+
switch (propertyValue.toString().toLowerCase()) {
641+
case "":
642+
case "1":
643+
case "true":
644+
field.set(builder, Boolean.TRUE);
645+
break;
646+
647+
case "0":
648+
case "false":
649+
field.set(builder, Boolean.FALSE);
650+
break;
651+
652+
default:
653+
throw new IllegalArgumentException(
654+
String.format(
655+
"Optional parameter %s must be boolean (true/false or 0/1) was '%s'",
656+
keyObj, propertyValue));
657+
}
658+
} else if (field.getGenericType().equals(Integer.class)) {
659+
try {
660+
final Integer value = Integer.parseInt(propertyValue.toString());
661+
field.set(builder, value);
662+
} catch (NumberFormatException n) {
646663
throw new IllegalArgumentException(
647664
String.format(
648-
"Optional parameter %s must be boolean (true/false or 0/1) was '%s'",
665+
"Optional parameter %s must be Integer, was '%s'",
649666
keyObj, propertyValue));
650-
}
651-
} else if (field.getGenericType().equals(Integer.class)) {
652-
try {
653-
final Integer value = Integer.parseInt(propertyValue.toString());
654-
field.set(builder, value);
655-
} catch (NumberFormatException n) {
656-
throw new IllegalArgumentException(
657-
String.format(
658-
"Optional parameter %s must be Integer, was '%s'", keyObj, propertyValue));
667+
}
659668
}
660669
}
661-
} catch (NoSuchFieldException nfe) {
662-
// keep unknown option:
663-
// those might be used in authentication or identity plugin
664-
nonMappedOptions.put(keyObj, propertyValue);
665670
}
666671
}
667672
}
668673

674+
// keep unknown option:
675+
// those might be used in authentication or identity plugin
676+
remainingProperties.forEach((key, val) -> nonMappedOptions.put(key, val));
677+
669678
// for compatibility with 2.x
670679
if (isSet("useSsl", nonMappedOptions) || isSet("useSSL", nonMappedOptions)) {
671680
Properties deprecatedDesc = new Properties();

src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java

+3
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ public static long initializeClientCapabilities(
217217
capabilities |= Capabilities.CONNECT_WITH_DB;
218218
}
219219

220+
if (configuration.sslMode() != SslMode.DISABLE) {
221+
capabilities |= Capabilities.SSL;
222+
}
220223
return capabilities & serverCapabilities;
221224
}
222225

src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public String createSessionVariableQuery(String serverTz) {
441441
sessionCommands.add("time_zone='" + zoneOffset.getId() + "'");
442442
}
443443
} else {
444-
sessionCommands.add("time_zone='" + conf.timezone() + "'");
444+
sessionCommands.add("time_zone='" + clientZoneId.normalized() + "'");
445445
}
446446
}
447447
}

src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ public void writeAscii(String str) throws IOException {
347347
if (len > buf.length - pos) {
348348
byte[] arr = str.getBytes(StandardCharsets.US_ASCII);
349349
writeBytes(arr, 0, arr.length);
350+
return;
350351
}
351352
for (int off = 0; off < len; ) {
352353
this.buf[this.pos++] = (byte) str.charAt(off++);

src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java

+14-6
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ public static String hex(byte[] bytes, int offset, int dataLength, int trunkLeng
5656
hexaValue[8] = ' ';
5757

5858
int pos = offset;
59+
int line = 1;
5960
int posHexa = 0;
6061
int logLength = Math.min(dataLength, trunkLength);
6162
StringBuilder sb = new StringBuilder(logLength * 3);
6263
sb.append(
63-
"+--------------------------------------------------+\n"
64-
+ "| 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
65-
+ "+--------------------------------------------------+------------------+\n| ");
64+
" +--------------------------------------------------+\n"
65+
+ " | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
66+
+ "+------+--------------------------------------------------+------------------+\n|000000| ");
6667

6768
while (pos < logLength + offset) {
6869
int byteValue = bytes[pos] & 0xFF;
@@ -75,7 +76,8 @@ public static String hex(byte[] bytes, int offset, int dataLength, int trunkLeng
7576
}
7677
if (posHexa == 16) {
7778
sb.append("| ").append(hexaValue).append(" |\n");
78-
if (pos + 1 != logLength + offset) sb.append("| ");
79+
if (pos + 1 != logLength + offset)
80+
sb.append("|").append(mediumIntTohexa(line++)).append("| ");
7981
posHexa = 0;
8082
}
8183
pos++;
@@ -101,13 +103,19 @@ public static String hex(byte[] bytes, int offset, int dataLength, int trunkLeng
101103
sb.append("| ").append(hexaValue).append(" |\n");
102104
}
103105
if (dataLength > trunkLength) {
104-
sb.append("+-------------------truncated----------------------+------------------+\n");
106+
sb.append("+------+-------------------truncated----------------------+------------------+\n");
105107
} else {
106-
sb.append("+--------------------------------------------------+------------------+\n");
108+
sb.append("+------+--------------------------------------------------+------------------+\n");
107109
}
108110
return sb.toString();
109111
}
110112

113+
private static String mediumIntTohexa(int value) {
114+
String st = Integer.toHexString(value * 16);
115+
while (st.length() < 6) st = "0" + st;
116+
return st;
117+
}
118+
111119
/**
112120
* return a string containing hexa displayable value of arrays
113121
*

src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ public final class OptionAliases {
1515

1616
static {
1717
OPTIONS_ALIASES = new HashMap<>();
18-
OPTIONS_ALIASES.put("enabledSSLCipherSuites", "enabledSslCipherSuites");
19-
OPTIONS_ALIASES.put("serverRSAPublicKeyFile", "serverRsaPublicKeyFile");
20-
OPTIONS_ALIASES.put("clientCertificateKeyStoreUrl", "keyStore");
21-
OPTIONS_ALIASES.put("clientCertificateKeyStorePassword", "keyStorePassword");
22-
OPTIONS_ALIASES.put("clientCertificateKeyStoreType", "keyStoreType");
18+
OPTIONS_ALIASES.put("clientcertificatekeystoreurl", "keyStore");
19+
OPTIONS_ALIASES.put("clientcertificatekeystorepassword", "keyStorePassword");
20+
OPTIONS_ALIASES.put("clientcertificatekeystoretype", "keyStoreType");
2321
}
2422
}

src/test/java/org/mariadb/jdbc/integration/LoggingTest.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,26 @@ void basicLogging() throws Exception {
8282
try {
8383
String contents = new String(Files.readAllBytes(Paths.get(tempFile.getPath())));
8484
String selectOne =
85-
"+--------------------------------------------------+\n"
86-
+ "| 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
87-
+ "+--------------------------------------------------+------------------+\n"
88-
+ "| 09 00 00 00 03 53 45 4C 45 43 54 20 31 | .....SELECT 1 |\n"
89-
+ "+--------------------------------------------------+------------------+\n";
85+
" +--------------------------------------------------+\n"
86+
+ " | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
87+
+ "+------+--------------------------------------------------+------------------+\n"
88+
+ "|000000| 09 00 00 00 03 53 45 4C 45 43 54 20 31 | .....SELECT 1 |\n"
89+
+ "+------+--------------------------------------------------+------------------+\n";
9090
Assertions.assertTrue(
9191
contents.contains(selectOne) || contents.contains(selectOne.replace("\r\n", "\n")),
9292
contents);
9393
String rowResult =
94-
"+--------------------------------------------------+\n"
95-
+ "| 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
96-
+ "+--------------------------------------------------+------------------+\n"
97-
+ "| 02 00 00 03 01 31 | .....1 |\n"
98-
+ "+--------------------------------------------------+------------------+\n";
94+
" +--------------------------------------------------+\n"
95+
+ " | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
96+
+ "+------+--------------------------------------------------+------------------+\n"
97+
+ "|000000| 02 00 00 03 01 31 | .....1 |\n"
98+
+ "+------+--------------------------------------------------+------------------+\n";
9999
String rowResultWithEof =
100-
"+--------------------------------------------------+\n"
101-
+ "| 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
102-
+ "+--------------------------------------------------+------------------+\n"
103-
+ "| 02 00 00 04 01 31 | .....1 |\n"
104-
+ "+--------------------------------------------------+------------------+\n";
100+
" +--------------------------------------------------+\n"
101+
+ " | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
102+
+ "+------+--------------------------------------------------+------------------+\n"
103+
+ "|000000| 02 00 00 04 01 31 | .....1 |\n"
104+
+ "+------+--------------------------------------------------+------------------+\n";
105105
Assertions.assertTrue(
106106
contents.contains(rowResult)
107107
|| contents.contains(rowResult.replace("\r\n", "\n"))

src/test/java/org/mariadb/jdbc/integration/SslTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void beforeAll2() throws SQLException {
4545

4646
Statement stmt = sharedConn.createStatement();
4747
// mysql 8.0.31 broken public key retrieval, so avoid FLUSHING for now
48-
Assumptions.assumeTrue(!isMariaDBServer() && !exactVersion(8, 0, 31));
48+
Assumptions.assumeTrue(isMariaDBServer() || (!isMariaDBServer() && !exactVersion(8, 0, 31)));
4949
stmt.execute("FLUSH PRIVILEGES");
5050
sslPort =
5151
System.getenv("TEST_MAXSCALE_TLS_PORT") == null

src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java

+56
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ public void getDateTimezoneTest() throws SQLException {
408408
try (Connection conGmtm8 = createCon("timezone=auto")) {
409409
getDateTimezoneTestGmtm8(conGmtm8, getPrepare(conGmtm8), TimeZone.getTimeZone("GMT-8"));
410410
}
411+
TimeZone.setDefault(initialTz);
412+
try (Connection conAuto = createCon("timezone=auto")) {
413+
getDateTimezoneTestNormal(conAuto, getPrepare(conAuto));
414+
}
415+
411416
} finally {
412417
TimeZone.setDefault(initialTz);
413418
}
@@ -565,6 +570,57 @@ public void getDateTimezoneTestGmtm8(Connection conGmt8, ResultSet rs, TimeZone
565570
conGmt8.rollback();
566571
}
567572

573+
public void getDateTimezoneTestNormal(Connection conAuto, ResultSet rs) throws SQLException {
574+
575+
assertEquals("2010-01-12 01:55:12.0", rs.getObject(1, Timestamp.class).toString());
576+
577+
conAuto.createStatement().execute("TRUNCATE TABLE DateTimeCodec3");
578+
try (PreparedStatement prep =
579+
conAuto.prepareStatement("INSERT INTO DateTimeCodec3 values (?,?)")) {
580+
prep.setInt(1, 5);
581+
prep.setString(2, "2010-01-12 01:55:12");
582+
prep.execute();
583+
584+
prep.setInt(1, 6);
585+
prep.setObject(2, "2010-01-12 11:55:12");
586+
prep.execute();
587+
}
588+
conAuto.commit();
589+
590+
java.sql.Statement stmt = conAuto.createStatement();
591+
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
592+
try (PreparedStatement prepStmt =
593+
conAuto.prepareStatement("select * from DateTimeCodec3 order by id")) {
594+
rs = prepStmt.executeQuery();
595+
rs.next();
596+
assertEquals(5, rs.getInt(1));
597+
assertEquals("2010-01-12T01:55:12", rs.getObject(2, LocalDateTime.class).toString());
598+
assertEquals("2010-01-12 01:55:12.000000", rs.getString(2));
599+
600+
rs.next();
601+
602+
Timestamp tt = Timestamp.valueOf("2010-01-12 01:55:12");
603+
int offset = TimeZone.getDefault().getOffset(tt.getTime());
604+
int offsetHour = offset / (3_600_000);
605+
if (offsetHour < 0) offsetHour = offsetHour * -1;
606+
607+
// test might fail if run in timezone with offset not rounded to hours
608+
if (offsetHour == 0) {
609+
assertEquals("2010-01-12T11:55:12Z", rs.getObject(2, OffsetDateTime.class).toString());
610+
} else {
611+
assertEquals(
612+
"2010-01-12T11:55:12"
613+
+ ((offset < 0) ? "-" : "+")
614+
+ ((offsetHour < 10) ? "0" : offsetHour / 10)
615+
+ (offsetHour % 10)
616+
+ ":00",
617+
rs.getObject(2, OffsetDateTime.class).toString());
618+
}
619+
assertEquals("2010-01-12 11:55:12.0", rs.getTimestamp(2).toString());
620+
}
621+
conAuto.rollback();
622+
}
623+
568624
@Test
569625
public void getTime() throws SQLException {
570626
getTime(get());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.mariadb.jdbc.unit.client.socket;
2+
3+
import java.io.IOException;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
import org.mariadb.jdbc.client.socket.impl.PacketWriter;
7+
8+
public class PackerWriterTest {
9+
10+
@Test
11+
public void growBuffer() throws IOException {
12+
PacketWriter pw = new PacketWriter(null, 0, 0xffffff, null, null);
13+
Assertions.assertEquals(4, pw.pos());
14+
pw.writeBytes(new byte[8190], 0, 8190);
15+
pw.writeAscii("abcdefghij");
16+
Assertions.assertEquals(8200, pw.pos() - 4);
17+
18+
for (int i = 0; i < 8190; i++) {
19+
Assertions.assertEquals(0, pw.buf()[i + 4]);
20+
}
21+
for (int i = 0; i < 10; i++) {
22+
Assertions.assertEquals('a' + i, pw.buf()[i + 8194]);
23+
}
24+
}
25+
}

src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,21 @@ public void testOptionParse() throws Throwable {
306306
assertEquals("toto", conf.password());
307307
}
308308

309+
@Test
310+
public void nonCaseSensitiveOptions() throws Throwable {
311+
Configuration conf =
312+
Configuration.parse(
313+
"jdbc:mariadb://localhost/test?useR=root&paSsword=toto&createdb=true"
314+
+ "&autoReConnect=true&prepStMtCacheSize=2&ConnectTimeout=5&socketTimeout=20");
315+
assertEquals(5, conf.connectTimeout());
316+
assertEquals(20, conf.socketTimeout());
317+
assertEquals(2, conf.prepStmtCacheSize());
318+
assertEquals("true", conf.nonMappedOptions().get("createdb"));
319+
assertEquals("true", conf.nonMappedOptions().get("autoReConnect"));
320+
assertEquals("root", conf.user());
321+
assertEquals("toto", conf.password());
322+
}
323+
309324
@Test
310325
public void wrongTypeParsing() {
311326
Common.assertThrowsContains(

0 commit comments

Comments
 (0)