executeInternalBatchStandard() throws SQLException {
*
* @param val string value to enquote
* @return enquoted string value
- * @throws SQLException -not possible-
*/
@Override
- public String enquoteLiteral(String val) throws SQLException {
+ public String enquoteLiteral(String val) {
Matcher matcher = escapePattern.matcher(val);
- StringBuffer escapedVal = new StringBuffer("'");
+ StringBuilder escapedVal = new StringBuilder("'");
while (matcher.find()) {
matcher.appendReplacement(escapedVal, mapper.get(matcher.group()));
@@ -1626,10 +1640,9 @@ public String enquoteIdentifier(String identifier, boolean alwaysQuote) throws S
* @param identifier identifier
* @return true if identifier doesn't have to be quoted
* @see mariadb identifier name
- * @throws SQLException exception
*/
@Override
- public boolean isSimpleIdentifier(String identifier) throws SQLException {
+ public boolean isSimpleIdentifier(String identifier) {
return identifier != null
&& !identifier.isEmpty()
&& identifierPattern.matcher(identifier).matches();
@@ -1640,10 +1653,9 @@ public boolean isSimpleIdentifier(String identifier) throws SQLException {
*
* @param val value to enquote
* @return enquoted String value
- * @throws SQLException - not possible -
*/
@Override
- public String enquoteNCharLiteral(String val) throws SQLException {
+ public String enquoteNCharLiteral(String val) {
return "N'" + val.replace("'", "''") + "'";
}
}
diff --git a/src/main/java/org/mariadb/jdbc/TransactionIsolation.java b/src/main/java/org/mariadb/jdbc/TransactionIsolation.java
index a910ecbd8..d69f9338a 100644
--- a/src/main/java/org/mariadb/jdbc/TransactionIsolation.java
+++ b/src/main/java/org/mariadb/jdbc/TransactionIsolation.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc;
import java.sql.Connection;
@@ -45,24 +44,6 @@ public enum TransactionIsolation {
this.level = level;
}
- /**
- * Get transaction isolation command
- *
- * @return transaction isolation command
- */
- public String getValue() {
- return value;
- }
-
- /**
- * Get transaction isolation level
- *
- * @return transaction isolation level
- */
- public int getLevel() {
- return level;
- }
-
/**
* Get TransactionIsolation from value
*
@@ -81,4 +62,22 @@ public static TransactionIsolation from(String value) {
throw new IllegalArgumentException(
String.format("Wrong argument value '%s' for TransactionIsolation", value));
}
+
+ /**
+ * Get transaction isolation command
+ *
+ * @return transaction isolation command
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Get transaction isolation level
+ *
+ * @return transaction isolation level
+ */
+ public int getLevel() {
+ return level;
+ }
}
diff --git a/src/main/java/org/mariadb/jdbc/client/Client.java b/src/main/java/org/mariadb/jdbc/client/Client.java
index 768a8a698..5da199855 100644
--- a/src/main/java/org/mariadb/jdbc/client/Client.java
+++ b/src/main/java/org/mariadb/jdbc/client/Client.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
import java.sql.SQLException;
@@ -190,4 +189,11 @@ void readStreamingResults(
* @return connection host
*/
HostAddress getHostAddress();
+
+ /**
+ * Get current socket IP or null (for Pipe / unix socket)
+ *
+ * @return Socket current IP
+ */
+ String getSocketIp();
}
diff --git a/src/main/java/org/mariadb/jdbc/client/Column.java b/src/main/java/org/mariadb/jdbc/client/Column.java
index b7bd667c5..43927c228 100644
--- a/src/main/java/org/mariadb/jdbc/client/Column.java
+++ b/src/main/java/org/mariadb/jdbc/client/Column.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
public interface Column {
diff --git a/src/main/java/org/mariadb/jdbc/client/ColumnDecoder.java b/src/main/java/org/mariadb/jdbc/client/ColumnDecoder.java
index d95225f72..a4d63df08 100644
--- a/src/main/java/org/mariadb/jdbc/client/ColumnDecoder.java
+++ b/src/main/java/org/mariadb/jdbc/client/ColumnDecoder.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
import java.nio.charset.StandardCharsets;
@@ -18,6 +17,128 @@
public interface ColumnDecoder extends Column {
+ /**
+ * Decode Column from mysql packet
+ *
+ * @param buf packet
+ * @param extendedInfo is extended datatype information capability enable
+ * @return column
+ */
+ static ColumnDecoder decode(ReadableByteBuf buf, boolean extendedInfo) {
+ // skip first strings
+ int[] stringPos = new int[5];
+ stringPos[0] = buf.skipIdentifier(); // schema pos
+ stringPos[1] = buf.skipIdentifier(); // table alias pos
+ stringPos[2] = buf.skipIdentifier(); // table pos
+ stringPos[3] = buf.skipIdentifier(); // column alias pos
+ stringPos[4] = buf.skipIdentifier(); // column pos
+ buf.skipIdentifier();
+
+ String extTypeName = null;
+ String extTypeFormat = null;
+ if (extendedInfo) {
+ // fast skipping extended info (usually not set)
+ if (buf.readByte() != 0) {
+ // revert position, because has extended info.
+ buf.pos(buf.pos() - 1);
+
+ ReadableByteBuf subPacket = buf.readLengthBuffer();
+ while (subPacket.readableBytes() > 0) {
+ switch (subPacket.readByte()) {
+ case 0:
+ extTypeName = subPacket.readAscii(subPacket.readLength());
+ break;
+ case 1:
+ extTypeFormat = subPacket.readAscii(subPacket.readLength());
+ break;
+ default: // skip data
+ subPacket.skip(subPacket.readLength());
+ break;
+ }
+ }
+ }
+ }
+
+ buf.skip(); // skip length always 0x0c
+ short charset = buf.readShort();
+ int length = buf.readInt();
+ DataType dataType = DataType.of(buf.readUnsignedByte());
+ int flags = buf.readUnsignedShort();
+ byte decimals = buf.readByte();
+ DataType.ColumnConstructor constructor =
+ (extTypeName != null && extTypeName.equals("uuid"))
+ ? UuidColumn::new
+ : (flags & ColumnFlags.UNSIGNED) == 0
+ ? dataType.getColumnConstructor()
+ : dataType.getUnsignedColumnConstructor();
+ return constructor.create(
+ buf, charset, length, dataType, decimals, flags, stringPos, extTypeName, extTypeFormat);
+ }
+
+ /**
+ * Create fake MySQL column definition packet with indicated datatype
+ *
+ * @param name column name
+ * @param type data type
+ * @param flags column flags
+ * @return Column
+ */
+ static ColumnDecoder create(String name, DataType type, int flags) {
+ byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8);
+ byte[] arr = new byte[9 + 2 * nameBytes.length];
+ arr[0] = 3;
+ arr[1] = 'D';
+ arr[2] = 'E';
+ arr[3] = 'F';
+
+ int[] stringPos = new int[5];
+ stringPos[0] = 4; // schema pos
+ stringPos[1] = 5; // table alias pos
+ stringPos[2] = 6; // table pos
+
+ // lenenc_str name
+ // lenenc_str org_name
+ int pos = 7;
+ for (int i = 0; i < 2; i++) {
+ stringPos[i + 3] = pos;
+ arr[pos++] = (byte) nameBytes.length;
+ System.arraycopy(nameBytes, 0, arr, pos, nameBytes.length);
+ pos += nameBytes.length;
+ }
+ int len;
+
+ /* Sensible predefined length - since we're dealing with I_S here, most char fields are 64 char long */
+ switch (type) {
+ case VARCHAR:
+ case VARSTRING:
+ len = 64 * 3; /* 3 bytes per UTF8 char */
+ break;
+ case SMALLINT:
+ len = 5;
+ break;
+ case NULL:
+ len = 0;
+ break;
+ default:
+ len = 1;
+ break;
+ }
+ DataType.ColumnConstructor constructor =
+ (flags & ColumnFlags.UNSIGNED) == 0
+ ? type.getColumnConstructor()
+ : type.getUnsignedColumnConstructor();
+ return constructor.create(
+ new StandardReadableByteBuf(arr, arr.length),
+ 33,
+ len,
+ type,
+ (byte) 0,
+ flags,
+ stringPos,
+ null,
+ null);
+ }
+
/**
* Returns default class name depending on server column datatype
*
@@ -192,6 +313,7 @@ Timestamp decodeTimestampText(final ReadableByteBuf buf, final MutableInt length
*/
Timestamp decodeTimestampBinary(final ReadableByteBuf buf, final MutableInt length, Calendar cal)
throws SQLDataException;
+
/**
* Return boolean text encoded value
*
@@ -213,6 +335,7 @@ boolean decodeBooleanText(final ReadableByteBuf buf, final MutableInt length)
*/
boolean decodeBooleanBinary(final ReadableByteBuf buf, final MutableInt length)
throws SQLDataException;
+
/**
* Parse short text encoded value
*
@@ -222,6 +345,7 @@ boolean decodeBooleanBinary(final ReadableByteBuf buf, final MutableInt length)
* @throws SQLDataException if any decoding error occurs
*/
short decodeShortText(final ReadableByteBuf buf, final MutableInt length) throws SQLDataException;
+
/**
* Parse short binary encoded value
*
@@ -232,6 +356,7 @@ boolean decodeBooleanBinary(final ReadableByteBuf buf, final MutableInt length)
*/
short decodeShortBinary(final ReadableByteBuf buf, final MutableInt length)
throws SQLDataException;
+
/**
* Parse int text encoded value
*
@@ -261,6 +386,7 @@ short decodeShortBinary(final ReadableByteBuf buf, final MutableInt length)
* @throws SQLDataException if any decoding error occurs
*/
long decodeLongText(final ReadableByteBuf buf, final MutableInt length) throws SQLDataException;
+
/**
* Parse long binary encoded value
*
@@ -313,126 +439,4 @@ float decodeFloatBinary(final ReadableByteBuf buf, final MutableInt length)
*/
double decodeDoubleBinary(final ReadableByteBuf buf, final MutableInt length)
throws SQLDataException;
-
- /**
- * Decode Column from mysql packet
- *
- * @param buf packet
- * @param extendedInfo is extended datatype information capability enable
- * @return column
- */
- static ColumnDecoder decode(ReadableByteBuf buf, boolean extendedInfo) {
- // skip first strings
- int[] stringPos = new int[5];
- stringPos[0] = buf.skipIdentifier(); // schema pos
- stringPos[1] = buf.skipIdentifier(); // table alias pos
- stringPos[2] = buf.skipIdentifier(); // table pos
- stringPos[3] = buf.skipIdentifier(); // column alias pos
- stringPos[4] = buf.skipIdentifier(); // column pos
- buf.skipIdentifier();
-
- String extTypeName = null;
- String extTypeFormat = null;
- if (extendedInfo) {
- // fast skipping extended info (usually not set)
- if (buf.readByte() != 0) {
- // revert position, because has extended info.
- buf.pos(buf.pos() - 1);
-
- ReadableByteBuf subPacket = buf.readLengthBuffer();
- while (subPacket.readableBytes() > 0) {
- switch (subPacket.readByte()) {
- case 0:
- extTypeName = subPacket.readAscii(subPacket.readLength());
- break;
- case 1:
- extTypeFormat = subPacket.readAscii(subPacket.readLength());
- break;
- default: // skip data
- subPacket.skip(subPacket.readLength());
- break;
- }
- }
- }
- }
-
- buf.skip(); // skip length always 0x0c
- short charset = buf.readShort();
- int length = buf.readInt();
- DataType dataType = DataType.of(buf.readUnsignedByte());
- int flags = buf.readUnsignedShort();
- byte decimals = buf.readByte();
- DataType.ColumnConstructor constructor =
- (extTypeName != null && extTypeName.equals("uuid"))
- ? UuidColumn::new
- : (flags & ColumnFlags.UNSIGNED) == 0
- ? dataType.getColumnConstructor()
- : dataType.getUnsignedColumnConstructor();
- return constructor.create(
- buf, charset, length, dataType, decimals, flags, stringPos, extTypeName, extTypeFormat);
- }
-
- /**
- * Create fake MySQL column definition packet with indicated datatype
- *
- * @param name column name
- * @param type data type
- * @param flags column flags
- * @return Column
- */
- static ColumnDecoder create(String name, DataType type, int flags) {
- byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8);
- byte[] arr = new byte[9 + 2 * nameBytes.length];
- arr[0] = 3;
- arr[1] = 'D';
- arr[2] = 'E';
- arr[3] = 'F';
-
- int[] stringPos = new int[5];
- stringPos[0] = 4; // schema pos
- stringPos[1] = 5; // table alias pos
- stringPos[2] = 6; // table pos
-
- // lenenc_str name
- // lenenc_str org_name
- int pos = 7;
- for (int i = 0; i < 2; i++) {
- stringPos[i + 3] = pos;
- arr[pos++] = (byte) nameBytes.length;
- System.arraycopy(nameBytes, 0, arr, pos, nameBytes.length);
- pos += nameBytes.length;
- }
- int len;
-
- /* Sensible predefined length - since we're dealing with I_S here, most char fields are 64 char long */
- switch (type) {
- case VARCHAR:
- case VARSTRING:
- len = 64 * 3; /* 3 bytes per UTF8 char */
- break;
- case SMALLINT:
- len = 5;
- break;
- case NULL:
- len = 0;
- break;
- default:
- len = 1;
- break;
- }
- DataType.ColumnConstructor constructor =
- (flags & ColumnFlags.UNSIGNED) == 0
- ? type.getColumnConstructor()
- : type.getUnsignedColumnConstructor();
- return constructor.create(
- new StandardReadableByteBuf(arr, arr.length),
- 33,
- len,
- type,
- (byte) 0,
- flags,
- stringPos,
- null,
- null);
- }
}
diff --git a/src/main/java/org/mariadb/jdbc/client/Completion.java b/src/main/java/org/mariadb/jdbc/client/Completion.java
index 27e7c1a05..3020d552d 100644
--- a/src/main/java/org/mariadb/jdbc/client/Completion.java
+++ b/src/main/java/org/mariadb/jdbc/client/Completion.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
import org.mariadb.jdbc.message.ServerMessage;
diff --git a/src/main/java/org/mariadb/jdbc/client/Context.java b/src/main/java/org/mariadb/jdbc/client/Context.java
index 500e79058..438c0f57a 100644
--- a/src/main/java/org/mariadb/jdbc/client/Context.java
+++ b/src/main/java/org/mariadb/jdbc/client/Context.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
import org.mariadb.jdbc.Configuration;
@@ -16,6 +15,13 @@ public interface Context {
*/
long getThreadId();
+ /**
+ * Indicate server connection Id (not truncated)
+ *
+ * @param connectionId connection id
+ */
+ void setThreadId(long connectionId);
+
/**
* Get connection initial seed
*
@@ -171,20 +177,6 @@ public interface Context {
*/
void addStateFlag(int state);
- /**
- * Indicate server charset change
- *
- * @param charset server charset
- */
- void setCharset(String charset);
-
- /**
- * Indicate server connection Id (not truncated)
- *
- * @param connectionId connection id
- */
- void setThreadId(long connectionId);
-
/** Indicate the number of connection on this server */
void setTreadsConnected(long threadsConnected);
@@ -194,4 +186,11 @@ public interface Context {
* @return current charset
*/
String getCharset();
+
+ /**
+ * Indicate server charset change
+ *
+ * @param charset server charset
+ */
+ void setCharset(String charset);
}
diff --git a/src/main/java/org/mariadb/jdbc/client/DataType.java b/src/main/java/org/mariadb/jdbc/client/DataType.java
index 8a3ca8c5d..b6f307d27 100644
--- a/src/main/java/org/mariadb/jdbc/client/DataType.java
+++ b/src/main/java/org/mariadb/jdbc/client/DataType.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
import org.mariadb.jdbc.client.column.*;
@@ -58,14 +57,14 @@ public enum DataType {
this.unsignedColumnConstructor = unsignedColumnConstructor;
}
- public int get() {
- return mariadbType;
- }
-
public static DataType of(int typeValue) {
return typeMap[typeValue];
}
+ public int get() {
+ return mariadbType;
+ }
+
public ColumnConstructor getColumnConstructor() {
return columnConstructor;
}
diff --git a/src/main/java/org/mariadb/jdbc/client/PrepareCache.java b/src/main/java/org/mariadb/jdbc/client/PrepareCache.java
index 32e5f9dcb..14ff197ea 100644
--- a/src/main/java/org/mariadb/jdbc/client/PrepareCache.java
+++ b/src/main/java/org/mariadb/jdbc/client/PrepareCache.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
import org.mariadb.jdbc.ServerPreparedStatement;
diff --git a/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java b/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java
index e811b38ab..21f5edd54 100644
--- a/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java
+++ b/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
import org.mariadb.jdbc.MariaDbBlob;
@@ -90,19 +89,20 @@ public interface ReadableByteBuf {
short getUnsignedByte();
/**
- * Read encoded length value that cannot be null see
- * https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integers
+ * Read encoded length value that cannot be null
*
+ * @see length
+ * encoded integer
* @return encoded length
*/
long readLongLengthEncodedNotNull();
/**
- * Read encoded length value that cannot be null see
- * https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integers
- *
- * this is readLongLengthEncodedNotNull limited to 32 bits
+ * Read encoded length value that cannot be null
*
+ * @see length
+ * encoded integer
+ *
this is readLongLengthEncodedNotNull limited to 32 bits
* @return encoded length
*/
int readIntLengthEncodedNotNull();
@@ -129,10 +129,12 @@ public interface ReadableByteBuf {
* @return long value
*/
long atoull(int length);
+
/**
- * Read encoded length value see
- * https://mariadb.com/kb/en/protocol-data-types/#length-encoded-integers
+ * Read encoded length value
*
+ * @see length
+ * encoded integer
* @return encoded length
*/
Integer readLength();
diff --git a/src/main/java/org/mariadb/jdbc/client/ServerVersion.java b/src/main/java/org/mariadb/jdbc/client/ServerVersion.java
index e789b2cf2..303dbb928 100644
--- a/src/main/java/org/mariadb/jdbc/client/ServerVersion.java
+++ b/src/main/java/org/mariadb/jdbc/client/ServerVersion.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
public interface ServerVersion {
diff --git a/src/main/java/org/mariadb/jdbc/client/SocketHelper.java b/src/main/java/org/mariadb/jdbc/client/SocketHelper.java
index fc34be30f..7a82308c6 100644
--- a/src/main/java/org/mariadb/jdbc/client/SocketHelper.java
+++ b/src/main/java/org/mariadb/jdbc/client/SocketHelper.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/BigDecimalColumn.java b/src/main/java/org/mariadb/jdbc/client/column/BigDecimalColumn.java
index 1994f71fa..0a436b790 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/BigDecimalColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/BigDecimalColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.math.BigDecimal;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/BitColumn.java b/src/main/java/org/mariadb/jdbc/client/column/BitColumn.java
index 019af86cf..c9fec9cd2 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/BitColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/BitColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/BlobColumn.java b/src/main/java/org/mariadb/jdbc/client/column/BlobColumn.java
index 23477674a..5c9f2123e 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/BlobColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/BlobColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.math.BigDecimal;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/DateColumn.java b/src/main/java/org/mariadb/jdbc/client/column/DateColumn.java
index 59b3ccda9..d51ecaa34 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/DateColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/DateColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
@@ -188,13 +187,22 @@ public Date decodeDateText(ReadableByteBuf buf, MutableInt length, Calendar cal)
return null;
}
- Calendar c = cal == null ? Calendar.getInstance() : cal;
- synchronized (c) {
+ if (cal == null) {
+ Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month - 1);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
return new Date(c.getTimeInMillis());
+ } else {
+ synchronized (cal) {
+ cal.clear();
+ cal.set(Calendar.YEAR, year);
+ cal.set(Calendar.MONTH, month - 1);
+ cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+ return new Date(cal.getTimeInMillis());
+ }
+
}
}
@@ -206,13 +214,21 @@ public Date decodeDateBinary(ReadableByteBuf buf, MutableInt length, Calendar ca
return null;
}
- Calendar c = cal == null ? Calendar.getInstance() : cal;
- synchronized (c) {
+ if (cal == null) {
+ Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR, buf.readShort());
c.set(Calendar.MONTH, buf.readByte() - 1);
c.set(Calendar.DAY_OF_MONTH, buf.readByte());
return new Date(c.getTimeInMillis());
+ } else {
+ synchronized (cal) {
+ cal.clear();
+ cal.set(Calendar.YEAR, buf.readShort());
+ cal.set(Calendar.MONTH, buf.readByte() - 1);
+ cal.set(Calendar.DAY_OF_MONTH, buf.readByte());
+ return new Date(cal.getTimeInMillis());
+ }
}
}
@@ -261,7 +277,6 @@ public Timestamp decodeTimestampBinary(ReadableByteBuf buf, MutableInt length, C
return null;
}
- Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
int year;
int month;
long dayOfMonth;
@@ -276,10 +291,17 @@ public Timestamp decodeTimestampBinary(ReadableByteBuf buf, MutableInt length, C
}
Timestamp timestamp;
- synchronized (cal) {
+ if (calParam == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month - 1, (int) dayOfMonth, 0, 0, 0);
timestamp = new Timestamp(cal.getTimeInMillis());
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.set(year, month - 1, (int) dayOfMonth, 0, 0, 0);
+ timestamp = new Timestamp(calParam.getTimeInMillis());
+ }
}
timestamp.setNanos(0);
return timestamp;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/DoubleColumn.java b/src/main/java/org/mariadb/jdbc/client/column/DoubleColumn.java
index 0291442c1..8511baf90 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/DoubleColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/DoubleColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.math.BigDecimal;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/FloatColumn.java b/src/main/java/org/mariadb/jdbc/client/column/FloatColumn.java
index b4a283975..2fb2a0b80 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/FloatColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/FloatColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.math.BigDecimal;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/GeometryColumn.java b/src/main/java/org/mariadb/jdbc/client/column/GeometryColumn.java
index 9ba3a07d3..c65b9d60f 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/GeometryColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/GeometryColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/JsonColumn.java b/src/main/java/org/mariadb/jdbc/client/column/JsonColumn.java
index d27519810..813d0428e 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/JsonColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/JsonColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedBigIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedBigIntColumn.java
index b6e8b6884..4a0f8f9b1 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/SignedBigIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/SignedBigIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.math.BigInteger;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedIntColumn.java
index 88766d1c8..c364d71c5 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/SignedIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/SignedIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedMediumIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedMediumIntColumn.java
index 62d25fd0a..90346ae10 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/SignedMediumIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/SignedMediumIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedSmallIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedSmallIntColumn.java
index b7299e6a3..6cf59a6ff 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/SignedSmallIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/SignedSmallIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/SignedTinyIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/SignedTinyIntColumn.java
index 5853a5d3a..1457101e6 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/SignedTinyIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/SignedTinyIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/StringColumn.java b/src/main/java/org/mariadb/jdbc/client/column/StringColumn.java
index 17e2388b9..80e90eb29 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/StringColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/StringColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
@@ -260,13 +259,21 @@ public Date decodeDateText(ReadableByteBuf buf, MutableInt length, Calendar cal)
int year = Integer.parseInt(stDatePart[0]);
int month = Integer.parseInt(stDatePart[1]);
int dayOfMonth = Integer.parseInt(stDatePart[2]);
- Calendar c = cal == null ? Calendar.getInstance() : cal;
- synchronized (c) {
+ if (cal == null) {
+ Calendar c = Calendar.getInstance();
c.clear();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month - 1);
c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
return new Date(c.getTimeInMillis());
+ } else {
+ synchronized (cal) {
+ cal.clear();
+ cal.set(Calendar.YEAR, year);
+ cal.set(Calendar.MONTH, month - 1);
+ cal.set(Calendar.DAY_OF_MONTH, dayOfMonth);
+ return new Date(cal.getTimeInMillis());
+ }
}
} catch (NumberFormatException nfe) {
@@ -297,27 +304,45 @@ public Time decodeTimeText(ReadableByteBuf buf, MutableInt length, Calendar cal)
@Override
public Time decodeTimeBinary(ReadableByteBuf buf, MutableInt length, Calendar calParam)
throws SQLDataException {
- Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
int[] parts = LocalTimeCodec.parseTime(buf, length, this);
Time t;
// specific case for TIME, to handle value not in 00:00:00-23:59:59
- synchronized (cal) {
+ if (calParam == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.setLenient(true);
if (parts[0] == -1) {
cal.set(
- 1970,
- Calendar.JANUARY,
- 1,
- parts[0] * parts[1],
- parts[0] * parts[2],
- parts[0] * parts[3] - 1);
+ 1970,
+ Calendar.JANUARY,
+ 1,
+ parts[0] * parts[1],
+ parts[0] * parts[2],
+ parts[0] * parts[3] - 1);
t = new Time(cal.getTimeInMillis() + (1000 - parts[4]));
} else {
cal.set(1970, Calendar.JANUARY, 1, parts[1], parts[2], parts[3]);
t = new Time(cal.getTimeInMillis() + parts[4] / 1_000_000);
}
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.setLenient(true);
+ if (parts[0] == -1) {
+ calParam.set(
+ 1970,
+ Calendar.JANUARY,
+ 1,
+ parts[0] * parts[1],
+ parts[0] * parts[2],
+ parts[0] * parts[3] - 1);
+ t = new Time(calParam.getTimeInMillis() + (1000 - parts[4]));
+ } else {
+ calParam.set(1970, Calendar.JANUARY, 1, parts[1], parts[2], parts[3]);
+ t = new Time(calParam.getTimeInMillis() + parts[4] / 1_000_000);
+ }
+ }
}
return t;
}
@@ -379,7 +404,6 @@ public Timestamp decodeTimestampText(ReadableByteBuf buf, MutableInt length, Cal
timestampsPart[4],
timestampsPart[5]);
timestamp = new Timestamp(c.getTime().getTime());
- timestamp.setNanos(timestampsPart[6] * 1000);
} else {
synchronized (calParam) {
calParam.clear();
@@ -391,17 +415,15 @@ public Timestamp decodeTimestampText(ReadableByteBuf buf, MutableInt length, Cal
timestampsPart[4],
timestampsPart[5]);
timestamp = new Timestamp(calParam.getTime().getTime());
- timestamp.setNanos(timestampsPart[6] * 1000);
}
}
+ timestamp.setNanos(timestampsPart[6] * 1000);
return timestamp;
}
@Override
public Timestamp decodeTimestampBinary(ReadableByteBuf buf, MutableInt length, Calendar calParam)
throws SQLDataException {
- Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
-
String val = buf.readString(length.get());
try {
int[] parts = LocalDateTimeCodec.parseTimestamp(val);
@@ -417,10 +439,17 @@ public Timestamp decodeTimestampBinary(ReadableByteBuf buf, MutableInt length, C
int seconds = parts[5];
int microseconds = parts[6] / 1000;
Timestamp timestamp;
- synchronized (cal) {
+ if (calParam == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month - 1, dayOfMonth, hour, minutes, seconds);
timestamp = new Timestamp(cal.getTimeInMillis());
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.set(year, month - 1, dayOfMonth, hour, minutes, seconds);
+ timestamp = new Timestamp(calParam.getTimeInMillis());
+ }
}
timestamp.setNanos(microseconds * 1000);
return timestamp;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/TimeColumn.java b/src/main/java/org/mariadb/jdbc/client/column/TimeColumn.java
index d9d9e28c2..0844788ce 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/TimeColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/TimeColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
@@ -317,8 +316,8 @@ public Timestamp decodeTimestampText(ReadableByteBuf buf, MutableInt length, Cal
Timestamp t;
// specific case for TIME, to handle value not in 00:00:00-23:59:59
- Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
- synchronized (cal) {
+ if (calParam == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.setLenient(true);
if (parts[0] == -1) {
@@ -336,6 +335,26 @@ public Timestamp decodeTimestampText(ReadableByteBuf buf, MutableInt length, Cal
t = new Timestamp(cal.getTimeInMillis());
t.setNanos(parts[4]);
}
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.setLenient(true);
+ if (parts[0] == -1) {
+ calParam.set(
+ 1970,
+ Calendar.JANUARY,
+ 1,
+ parts[0] * parts[1],
+ parts[0] * parts[2],
+ parts[0] * parts[3] - 1);
+ t = new Timestamp(calParam.getTimeInMillis());
+ t.setNanos(1_000_000_000 - parts[4]);
+ } else {
+ calParam.set(1970, Calendar.JANUARY, 1, parts[1], parts[2], parts[3]);
+ t = new Timestamp(calParam.getTimeInMillis());
+ t.setNanos(parts[4]);
+ }
+ }
}
return t;
}
diff --git a/src/main/java/org/mariadb/jdbc/client/column/TimestampColumn.java b/src/main/java/org/mariadb/jdbc/client/column/TimestampColumn.java
index 19f3f3840..e640b22aa 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/TimestampColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/TimestampColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
@@ -297,8 +296,6 @@ public Date decodeDateText(ReadableByteBuf buf, MutableInt length, Calendar cal)
@Override
public Date decodeDateBinary(ReadableByteBuf buf, MutableInt length, Calendar calParam)
throws SQLDataException {
- Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
-
if (length.get() == 0) {
length.set(NULL_LENGTH);
return null;
@@ -334,10 +331,17 @@ public Date decodeDateBinary(ReadableByteBuf buf, MutableInt length, Calendar ca
}
Timestamp timestamp;
- synchronized (cal) {
+ if (calParam == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month - 1, dayOfMonth, hour, minutes, seconds);
timestamp = new Timestamp(cal.getTimeInMillis());
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.set(year, month - 1, dayOfMonth, hour, minutes, seconds);
+ timestamp = new Timestamp(calParam.getTimeInMillis());
+ }
}
timestamp.setNanos((int) (microseconds * 1000));
String st = timestamp.toString();
@@ -362,7 +366,6 @@ public Time decodeTimeBinary(ReadableByteBuf buf, MutableInt length, Calendar ca
length.set(NULL_LENGTH);
return null;
}
- Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
int year = buf.readUnsignedShort();
int month = buf.readByte();
@@ -388,10 +391,17 @@ public Time decodeTimeBinary(ReadableByteBuf buf, MutableInt length, Calendar ca
return null;
}
- synchronized (cal) {
+ if (calParam == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(1970, Calendar.JANUARY, 1, hour, minutes, seconds);
return new Time(cal.getTimeInMillis() + microseconds / 1_000);
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.set(1970, Calendar.JANUARY, 1, hour, minutes, seconds);
+ return new Time(calParam.getTimeInMillis() + microseconds / 1_000);
+ }
}
}
@@ -477,7 +487,6 @@ public Timestamp decodeTimestampBinary(ReadableByteBuf buf, MutableInt length, C
length.set(NULL_LENGTH);
return null;
}
- Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
int year = buf.readUnsignedShort();
int month = buf.readByte();
@@ -509,10 +518,17 @@ public Timestamp decodeTimestampBinary(ReadableByteBuf buf, MutableInt length, C
return null;
}
Timestamp timestamp;
- synchronized (cal) {
+ if (calParam == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month - 1, dayOfMonth, hour, minutes, seconds);
timestamp = new Timestamp(cal.getTimeInMillis());
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.set(year, month - 1, dayOfMonth, hour, minutes, seconds);
+ timestamp = new Timestamp(calParam.getTimeInMillis());
+ }
}
timestamp.setNanos((int) (microseconds * 1000));
return timestamp;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedBigIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedBigIntColumn.java
index b8f231cb9..09bfcb8f6 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedBigIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedBigIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.math.BigInteger;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java
index bf8b574e3..1bdf6ee18 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedMediumIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedMediumIntColumn.java
index 74725fb5f..2e3456e14 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedMediumIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedMediumIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java
index bd0608062..344d84a28 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedSmallIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java
index 040d6671c..8bb83d3ea 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/UnsignedTinyIntColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java b/src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java
index 62093e93e..da465adea 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/UuidColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/column/YearColumn.java b/src/main/java/org/mariadb/jdbc/client/column/YearColumn.java
index fddce5a0d..e7127b54e 100644
--- a/src/main/java/org/mariadb/jdbc/client/column/YearColumn.java
+++ b/src/main/java/org/mariadb/jdbc/client/column/YearColumn.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.column;
import java.sql.*;
@@ -122,30 +121,41 @@ public Date decodeDateBinary(ReadableByteBuf buf, MutableInt length, Calendar ca
@Override
public Timestamp decodeTimestampText(ReadableByteBuf buf, MutableInt length, Calendar calParam)
throws SQLDataException {
- Calendar cal1 = calParam == null ? Calendar.getInstance() : calParam;
-
int year = Integer.parseInt(buf.readAscii(length.get()));
if (columnLength <= 2) year += year >= 70 ? 1900 : 2000;
- synchronized (cal1) {
+
+ if (calParam == null) {
+ Calendar cal1 = Calendar.getInstance();
cal1.clear();
cal1.set(year, Calendar.JANUARY, 1);
return new Timestamp(cal1.getTimeInMillis());
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.set(year, Calendar.JANUARY, 1);
+ return new Timestamp(calParam.getTimeInMillis());
+ }
}
}
@Override
public Timestamp decodeTimestampBinary(ReadableByteBuf buf, MutableInt length, Calendar calParam)
throws SQLDataException {
- Calendar cal = calParam == null ? Calendar.getInstance() : calParam;
-
int year = buf.readUnsignedShort();
if (columnLength <= 2) year += year >= 70 ? 1900 : 2000;
Timestamp timestamp;
- synchronized (cal) {
+ if (calParam == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, 0, 1, 0, 0, 0);
timestamp = new Timestamp(cal.getTimeInMillis());
+ } else {
+ synchronized (calParam) {
+ calParam.clear();
+ calParam.set(year, 0, 1, 0, 0, 0);
+ timestamp = new Timestamp(calParam.getTimeInMillis());
+ }
}
timestamp.setNanos(0);
return timestamp;
diff --git a/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java b/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java
index d5e99a81c..b268e6fd8 100644
--- a/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java
+++ b/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.context;
import static org.mariadb.jdbc.util.constants.Capabilities.STMT_BULK_OPERATIONS;
@@ -18,7 +17,6 @@
/** Context (current connection state) of a connection */
public class BaseContext implements Context {
- private long threadId;
private final long serverCapabilities;
private final long clientCapabilities;
private final byte[] seed;
@@ -29,11 +27,17 @@ public class BaseContext implements Context {
private final Configuration conf;
private final ExceptionFactory exceptionFactory;
- private String charset;
+ /** LRU prepare cache object */
+ private final PrepareCache prepareCache;
+
+ private final HostAddress hostAddress;
/** Server status context */
protected int serverStatus;
+ private long threadId;
+ private String charset;
+
/** Server current database */
private String database;
@@ -43,14 +47,9 @@ public class BaseContext implements Context {
/** Server current warning count */
private int warning;
- /** LRU prepare cache object */
- private final PrepareCache prepareCache;
-
/** Connection state use flag */
private int stateFlag = 0;
- private final HostAddress hostAddress;
-
/**
* Constructor of connection context
*
@@ -61,6 +60,7 @@ public class BaseContext implements Context {
* @param exceptionFactory connection exception factory
* @param prepareCache LRU prepare cache
*/
+ @SuppressWarnings({"this-escape"})
public BaseContext(
HostAddress hostAddress,
InitialHandshakePacket handshake,
@@ -88,6 +88,10 @@ public long getThreadId() {
return threadId;
}
+ public void setThreadId(long connectionId) {
+ threadId = connectionId;
+ }
+
public byte[] getSeed() {
return seed;
}
@@ -180,14 +184,6 @@ public void addStateFlag(int state) {
stateFlag |= state;
}
- public void setCharset(String charset) {
- this.charset = charset;
- }
-
- public void setThreadId(long connectionId) {
- threadId = connectionId;
- }
-
public void setTreadsConnected(long threadsConnected) {
if (hostAddress != null) hostAddress.setThreadsConnected(threadsConnected);
}
@@ -195,4 +191,8 @@ public void setTreadsConnected(long threadsConnected) {
public String getCharset() {
return charset;
}
+
+ public void setCharset(String charset) {
+ this.charset = charset;
+ }
}
diff --git a/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java b/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java
index 43d128e9f..ef39ce3dd 100644
--- a/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java
+++ b/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.context;
import org.mariadb.jdbc.Configuration;
diff --git a/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java b/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java
index fb5ba8b63..90458a122 100644
--- a/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.impl;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java
index 6a288ba70..7eb3ff521 100644
--- a/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.impl;
import java.sql.*;
@@ -36,23 +35,23 @@
* supported proxy class.
*/
public class MultiPrimaryClient implements Client {
- private static final Logger logger = Loggers.getLogger(MultiPrimaryClient.class);
-
/** temporary blacklisted hosts */
protected static final ConcurrentMap denyList = new ConcurrentHashMap<>();
+ private static final Logger logger = Loggers.getLogger(MultiPrimaryClient.class);
+
/** denied timeout */
protected final long deniedListTimeout;
/** configuration */
protected final Configuration conf;
- /** is connections explicitly closed */
- protected boolean closed = false;
-
/** thread locker */
protected final ReentrantLock lock;
+ /** is connections explicitly closed */
+ protected boolean closed = false;
+
/** current client */
protected Client currentClient;
@@ -63,6 +62,7 @@ public class MultiPrimaryClient implements Client {
* @param lock thread locker
* @throws SQLException if fail to connect
*/
+ @SuppressWarnings({"this-escape"})
public MultiPrimaryClient(Configuration conf, ReentrantLock lock) throws SQLException {
this.conf = conf;
this.lock = lock;
@@ -150,8 +150,7 @@ protected Client connectHost(boolean readOnly, boolean failFast) throws SQLExcep
}
}
}
-
- throw lastSqle;
+ throw (lastSqle != null) ? lastSqle : new SQLNonTransientConnectionException("No host");
}
/**
@@ -199,7 +198,8 @@ protected void replayIfPossible(Client oldClient, boolean canRedo) throws SQLExc
// changing exception to SQLTransientConnectionException
throw new SQLTransientConnectionException(
String.format(
- "Driver has reconnect connection after a communications link failure with %s. In progress transaction was lost",
+ "Driver has reconnect connection after a communications link failure with %s. In"
+ + " progress transaction was lost",
oldClient.getHostAddress()),
"25S03");
}
@@ -228,7 +228,8 @@ protected void executeTransactionReplay(Client oldCli) throws SQLException {
ctx.getTransactionSaver().clear();
throw new SQLTransientConnectionException(
String.format(
- "Driver has reconnect connection after a communications link failure with %s. In progress transaction was too big to be replayed, and was lost",
+ "Driver has reconnect connection after a communications link failure with %s. In"
+ + " progress transaction was too big to be replayed, and was lost",
oldCli.getHostAddress()),
"25S03");
}
@@ -276,8 +277,9 @@ public void syncNewState(Client oldCli) throws SQLException {
}
if ((oldCtx.getStateFlag() & ConnectionState.STATE_TRANSACTION_ISOLATION) > 0
- && currentClient.getContext().getTransactionIsolationLevel()
- != oldCtx.getTransactionIsolationLevel()) {
+ && !oldCtx
+ .getTransactionIsolationLevel()
+ .equals(currentClient.getContext().getTransactionIsolationLevel())) {
String query = "SET SESSION TRANSACTION ISOLATION LEVEL";
switch (oldCtx.getTransactionIsolationLevel()) {
case java.sql.Connection.TRANSACTION_READ_UNCOMMITTED:
@@ -360,7 +362,8 @@ public List execute(
if (message instanceof QueryPacket && ((QueryPacket) message).isCommit()) {
throw new SQLTransientConnectionException(
String.format(
- "Driver has reconnect connection after a communications failure with %s during a COMMIT statement",
+ "Driver has reconnect connection after a communications failure with %s during a"
+ + " COMMIT statement",
hostAddress),
"25S03");
}
@@ -537,6 +540,11 @@ public HostAddress getHostAddress() {
return currentClient.getHostAddress();
}
+ @Override
+ public String getSocketIp() {
+ return currentClient.getSocketIp();
+ }
+
public boolean isPrimary() {
return true;
}
diff --git a/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java
index c736136c9..ac4bd7aba 100644
--- a/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.impl;
import java.sql.SQLException;
@@ -47,6 +46,7 @@ public class MultiPrimaryReplicaClient extends MultiPrimaryClient {
* @param lock thread locker
* @throws SQLException if any error occurs
*/
+ @SuppressWarnings({"this-escape"})
public MultiPrimaryReplicaClient(Configuration conf, ReentrantLock lock) throws SQLException {
super(conf, lock);
primaryClient = currentClient;
diff --git a/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java b/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java
index 4e77e2588..37ca2d2c7 100644
--- a/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.impl;
import java.util.LinkedHashMap;
@@ -16,10 +15,12 @@ public final class PrepareCache extends LinkedHashMap executePipeline(
return results;
} catch (SQLException sqlException) {
if (!closed) {
+ results.add(null);
// read remaining results
perMsgCounter++;
for (; perMsgCounter < responseMsg[readCounter - 1]; perMsgCounter++) {
@@ -624,7 +627,7 @@ public List executePipeline(
resultSetType,
closeOnCompletion));
} catch (SQLException e) {
- // eat
+ results.add(null);
}
}
}
@@ -1023,6 +1026,12 @@ public void close() {
}
}
+ public String getSocketIp() {
+ return this.socket.getInetAddress() == null
+ ? null
+ : this.socket.getInetAddress().getHostAddress();
+ }
+
public boolean isPrimary() {
return hostAddress.primary;
}
diff --git a/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java b/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java
index 586d5a25c..2e177017b 100644
--- a/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.impl;
import java.nio.charset.StandardCharsets;
@@ -10,15 +9,15 @@
/** Packet buffer */
public final class StandardReadableByteBuf implements ReadableByteBuf {
- /** row data limit */
- private int limit;
-
/** buffer */
public byte[] buf;
/** current position reading buffer */
public int pos;
+ /** row data limit */
+ private int limit;
+
/**
* Packet buffer constructor
*
@@ -88,7 +87,6 @@ public void skipLengthEncoded() {
return;
default:
pos += len & 0xff;
- return;
}
}
diff --git a/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java b/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java
index ace7eab12..f77c23c2d 100644
--- a/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.impl;
import java.util.Arrays;
diff --git a/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java b/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java
index 100b8b598..11296d997 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.result;
import java.io.ByteArrayOutputStream;
@@ -38,6 +37,7 @@ public class CompleteResult extends Result {
* @throws IOException if Socket error occurs
* @throws SQLException for all other kind of errors
*/
+ @SuppressWarnings({"this-escape"})
public CompleteResult(
Statement stmt,
boolean binaryProtocol,
diff --git a/src/main/java/org/mariadb/jdbc/client/result/Result.java b/src/main/java/org/mariadb/jdbc/client/result/Result.java
index 982f39aa9..a49ccf0a4 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/Result.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/Result.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.result;
import java.io.IOException;
@@ -10,7 +9,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
-import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.sql.*;
import java.sql.Date;
@@ -31,15 +30,11 @@
/** Result-set common */
public abstract class Result implements ResultSet, Completion {
- private static BinaryRowDecoder BINARY_ROW_DECODER = new BinaryRowDecoder();
- private static TextRowDecoder TEXT_ROW_DECODER = new TextRowDecoder();
/** null length value */
public static final int NULL_LENGTH = -1;
- private final int maxIndex;
- private final boolean closeOnCompletion;
- private boolean forceAlias;
- private final boolean traceEnable;
+ private static final BinaryRowDecoder BINARY_ROW_DECODER = new BinaryRowDecoder();
+ private static final TextRowDecoder TEXT_ROW_DECODER = new TextRowDecoder();
/** result-set type */
protected final int resultSetType;
@@ -59,24 +54,22 @@ public abstract class Result implements ResultSet, Completion {
/** binary/text row decoder */
protected final RowDecoder rowDecoder;
+ /** reusable row buffer decoder */
+ protected final StandardReadableByteBuf rowBuf = new StandardReadableByteBuf(null, 0);
+
+ private final int maxIndex;
+ private final boolean closeOnCompletion;
+ private final boolean traceEnable;
+
/** data size */
protected int dataSize = 0;
/** rows */
protected byte[][] data;
- private byte[] nullBitmap;
-
- /** reusable row buffer decoder */
- protected final StandardReadableByteBuf rowBuf = new StandardReadableByteBuf(null, 0);
-
- private MutableInt fieldLength = new MutableInt(0);
-
/** mutable field index */
protected MutableInt fieldIndex = new MutableInt();
- private Map mapper = null;
-
/** is fully loaded */
protected boolean loaded;
@@ -95,6 +88,11 @@ public abstract class Result implements ResultSet, Completion {
/** row number limit */
protected long maxRows;
+ private final MutableInt fieldLength = new MutableInt(0);
+ private boolean forceAlias;
+ private byte[] nullBitmap;
+ private Map mapper = null;
+
/**
* Constructor for server's data
*
@@ -852,6 +850,16 @@ public boolean isBeforeFirst() throws SQLException {
@Override
public abstract int getRow() throws SQLException;
+ /**
+ * set row decoder to current row data
+ *
+ * @param row row
+ */
+ public void setRow(byte[] row) {
+ rowBuf.buf(row, row.length, 0);
+ fieldIndex.set(-1);
+ }
+
@Override
public abstract boolean absolute(int row) throws SQLException;
@@ -870,7 +878,8 @@ public int getFetchDirection() {
public void setFetchDirection(int direction) throws SQLException {
if (direction == FETCH_REVERSE) {
throw exceptionFactory.create(
- "Invalid operation. Allowed direction are ResultSet.FETCH_FORWARD and ResultSet.FETCH_UNKNOWN");
+ "Invalid operation. Allowed direction are ResultSet.FETCH_FORWARD and"
+ + " ResultSet.FETCH_UNKNOWN");
}
}
@@ -1154,7 +1163,8 @@ public Object getObject(int columnIndex, Map> map) throws SQLEx
return getObject(columnIndex);
}
throw exceptionFactory.notSupported(
- "Method ResultSet.getObject(int columnIndex, Map> map) not supported for non empty map");
+ "Method ResultSet.getObject(int columnIndex, Map> map) not supported for"
+ + " non empty map");
}
@Override
@@ -1288,8 +1298,8 @@ public URL getURL(int columnIndex) throws SQLException {
StringCodec.INSTANCE, null, rowBuf, fieldLength, metadataList, fieldIndex);
if (s == null) return null;
try {
- return new URL(s);
- } catch (MalformedURLException e) {
+ return new URI(s).toURL();
+ } catch (Exception e) {
throw exceptionFactory.create(String.format("Could not parse '%s' as URL", s));
}
}
@@ -1680,16 +1690,6 @@ protected void setNullRowBuf() {
rowBuf.buf(null, 0, 0);
}
- /**
- * set row decoder to current row data
- *
- * @param row row
- */
- public void setRow(byte[] row) {
- rowBuf.buf(row, row.length, 0);
- fieldIndex.set(-1);
- }
-
public int findColumn(String label) throws SQLException {
if (label == null) throw new SQLException("null is not a valid label value");
if (mapper == null) {
diff --git a/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java b/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java
index ee49039d4..21fd88adf 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.result;
import java.sql.SQLException;
diff --git a/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java b/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java
index c3c9ce38c..75b3168a9 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.result;
import java.io.IOException;
@@ -60,6 +59,7 @@ public class StreamingResult extends Result {
* @param traceEnable can network log be logged
* @throws SQLException if any error occurs
*/
+ @SuppressWarnings({"this-escape"})
public StreamingResult(
Statement stmt,
boolean binaryProtocol,
diff --git a/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java b/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java
index fc429b700..1352f5cc1 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.result;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/BinaryRowDecoder.java b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/BinaryRowDecoder.java
index 47a36e1dd..a218e87e3 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/BinaryRowDecoder.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/BinaryRowDecoder.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.result.rowdecoder;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
diff --git a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/RowDecoder.java b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/RowDecoder.java
index b39e6fc7d..cafb0ef60 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/RowDecoder.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/RowDecoder.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.result.rowdecoder;
import java.sql.Date;
@@ -120,6 +119,7 @@ boolean decodeBoolean(
StandardReadableByteBuf rowBuf,
MutableInt fieldLength)
throws SQLException;
+
/**
* Decode data according to Date.
*
@@ -138,6 +138,7 @@ Date decodeDate(
MutableInt fieldLength,
Calendar cal)
throws SQLException;
+
/**
* Decode data according to Time.
*
@@ -156,6 +157,7 @@ Time decodeTime(
MutableInt fieldLength,
Calendar cal)
throws SQLException;
+
/**
* Decode data according to Timestamp.
*
@@ -174,6 +176,7 @@ Timestamp decodeTimestamp(
MutableInt fieldLength,
Calendar cal)
throws SQLException;
+
/**
* Decode data according to short.
*
@@ -190,6 +193,7 @@ short decodeShort(
StandardReadableByteBuf rowBuf,
MutableInt fieldLength)
throws SQLException;
+
/**
* Decode data according to int.
*
@@ -206,6 +210,7 @@ int decodeInt(
StandardReadableByteBuf rowBuf,
MutableInt fieldLength)
throws SQLException;
+
/**
* Decode data according to String.
*
@@ -222,6 +227,7 @@ String decodeString(
StandardReadableByteBuf rowBuf,
MutableInt fieldLength)
throws SQLException;
+
/**
* Decode data according to long.
*
@@ -238,6 +244,7 @@ long decodeLong(
StandardReadableByteBuf rowBuf,
MutableInt fieldLength)
throws SQLException;
+
/**
* Decode data according to float.
*
@@ -254,6 +261,7 @@ float decodeFloat(
StandardReadableByteBuf rowBuf,
MutableInt fieldLength)
throws SQLException;
+
/**
* Decode data according to double.
*
diff --git a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/TextRowDecoder.java b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/TextRowDecoder.java
index 42bf6c533..9e7f429df 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/TextRowDecoder.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/rowdecoder/TextRowDecoder.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.result.rowdecoder;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/Reader.java b/src/main/java/org/mariadb/jdbc/client/socket/Reader.java
index 55aef8ecb..61e278673 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/Reader.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/Reader.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/Writer.java b/src/main/java/org/mariadb/jdbc/client/socket/Writer.java
index 4569d52a0..f3d052bce 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/Writer.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/Writer.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java
index 6c75f2ccf..6f96c9330 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import java.io.EOFException;
@@ -23,11 +22,14 @@ public class CompressInputStream extends InputStream {
private int end;
private int pos;
- private byte[] buf;
+ private volatile byte[] buf;
/**
* Constructor. When this handler is used, driver expect packet with 7 byte compression header
*
+ * Implementation doesn't use synchronized/semaphore because all used are already locked by
+ * Statement/PreparedStatement Reentrant lock
+ *
* @param in socket input stream
* @param compressionSequence compression sequence
*/
@@ -88,7 +90,6 @@ public int read(byte[] b, int off, int len) throws IOException {
}
int totalReads = 0;
-
do {
if (end - pos <= 0) {
retrieveBuffer();
@@ -258,7 +259,7 @@ public void close() throws IOException {
* @see InputStream#reset()
*/
@Override
- public synchronized void mark(int readlimit) {
+ public void mark(int readlimit) {
in.mark(readlimit);
}
@@ -300,7 +301,7 @@ public synchronized void mark(int readlimit) {
* @see IOException
*/
@Override
- public synchronized void reset() throws IOException {
+ public void reset() throws IOException {
in.reset();
}
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java
index 7a9b2b8ac..726b636b8 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import java.io.ByteArrayOutputStream;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java
index ad8d980b0..02cb0ef6b 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import com.sun.jna.platform.win32.Kernel32;
@@ -71,8 +70,10 @@ public void connect(SocketAddress endpoint, int timeout) throws IOException {
if (timeout == 0) {
throw new FileNotFoundException(
fileNotFoundException.getMessage()
- + "\nplease consider set connectTimeout option, so connection can retry having access to named pipe. "
- + "\n(Named pipe can throw ERROR_PIPE_BUSY error)");
+ + "\n"
+ + "please consider set connectTimeout option, so connection can retry having"
+ + " access to named pipe. \n"
+ + "(Named pipe can throw ERROR_PIPE_BUSY error)");
}
throw fileNotFoundException;
}
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java
index e7234e2de..cf17d07e6 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import java.io.EOFException;
@@ -20,18 +19,15 @@
/** Packet reader */
public class PacketReader implements Reader {
- private StandardReadableByteBuf readBuf = new StandardReadableByteBuf(null, 0);
-
private static final int REUSABLE_BUFFER_LENGTH = 1024;
private static final int MAX_PACKET_SIZE = 0xffffff;
private static final Logger logger = Loggers.getLogger(PacketReader.class);
-
private final byte[] header = new byte[4];
private final byte[] reusableArray = new byte[REUSABLE_BUFFER_LENGTH];
private final InputStream inputStream;
private final int maxQuerySizeToLog;
-
private final MutableByte sequence;
+ private final StandardReadableByteBuf readBuf = new StandardReadableByteBuf(null, 0);
private String serverThreadLog = "";
/**
@@ -259,7 +255,7 @@ public void skipPacket() throws IOException {
remaining = lastPacketLength;
do {
- remaining -= inputStream.skip(remaining);
+ remaining -= (int) inputStream.skip(remaining);
} while (remaining > 0);
// ***************************************************
@@ -283,7 +279,7 @@ public void skipPacket() throws IOException {
remaining = packetLength;
do {
- remaining -= inputStream.skip(remaining);
+ remaining -= (int) inputStream.skip(remaining);
} while (remaining > 0);
lastPacketLength += packetLength;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java
index 9807bb937..1170972f4 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import java.io.IOException;
@@ -31,24 +30,29 @@ public class PacketWriter implements Writer {
private static final int MEDIUM_BUFFER_SIZE = 128 * 1024;
private static final int LARGE_BUFFER_SIZE = 1024 * 1024;
private static final int MAX_PACKET_LENGTH = 0x00ffffff + 4;
+
+ /** packet sequence */
+ protected final MutableByte sequence;
+
+ /** compressed packet sequence */
+ protected final MutableByte compressSequence;
+
private final int maxQuerySizeToLog;
private final OutputStream out;
- private int maxPacketLength = MAX_PACKET_LENGTH;
- private Integer maxAllowedPacket;
- private long cmdLength;
- private boolean permitTrace = true;
- private String serverThreadLog = "";
- private int mark = -1;
- private boolean bufContainDataAfterMark = false;
+ private final int maxPacketLength = MAX_PACKET_LENGTH;
+ private final Integer maxAllowedPacket;
/** internal buffer */
protected byte[] buf;
+
/** buffer position */
protected int pos = 4;
- /** packet sequence */
- protected final MutableByte sequence;
- /** compressed packet sequence */
- protected final MutableByte compressSequence;
+
+ private long cmdLength;
+ private boolean permitTrace = true;
+ private String serverThreadLog = "";
+ private int mark = -1;
+ private boolean bufContainDataAfterMark = false;
/**
* Common feature to write data into socket, creating MariaDB Packet.
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java
index b58c1f331..e649b3d0a 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import java.io.FilterInputStream;
@@ -22,6 +21,9 @@ public class ReadAheadBufferedStream extends FilterInputStream {
/**
* Constructor
*
+ * Implementation doesn't use synchronized/semaphore because all used are already locked by
+ * Statement/PreparedStatement Reentrant lock
+ *
* @param in socket input stream
*/
public ReadAheadBufferedStream(InputStream in) {
@@ -40,12 +42,11 @@ public ReadAheadBufferedStream(InputStream in) {
* @return number of added bytes
* @throws IOException if exception during socket reading
*/
- public synchronized int read(byte[] externalBuf, int off, int len) throws IOException {
+ public int read(byte[] externalBuf, int off, int len) throws IOException {
if (len == 0) {
return 0;
}
-
int totalReads = 0;
while (true) {
@@ -104,7 +105,7 @@ public void close() throws IOException {
pos = 0;
}
- public synchronized int available() throws IOException {
+ public int available() throws IOException {
return end - pos + super.available();
}
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java
index 99932408c..99a6b19cd 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java
index 17ff0bbaa..a63f0607d 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import com.sun.jna.Platform;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java
index 5bac1f005..3122a7484 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.socket.impl;
import com.sun.jna.LastErrorException;
@@ -57,8 +56,9 @@ public UnixDomainSocket(String path) throws IOException {
/**
* creates an endpoint for communication and returns a file descriptor that refers to that
- * endpoint. see https://man7.org/linux/man-pages/man2/socket.2.html
+ * endpoint.
*
+ * @see Socket
* @param domain domain
* @param type type
* @param protocol protocol
@@ -85,7 +85,8 @@ public static native int connect(int sockfd, SockAddr sockaddr, int addrlen)
* @param fd file descriptor
* @param buffer buffer
* @param count length
- * @param flags flag. see https://man7.org/linux/man-pages/man2/recvmsg.2.html
+ * @param flags flag. @see flags
* @return zero on success. -1 on error
* @throws LastErrorException if error occurs
*/
@@ -98,7 +99,8 @@ public static native int recv(int fd, byte[] buffer, int count, int flags)
* @param fd file descriptor
* @param buffer buffer
* @param count length
- * @param flags flag. see https://man7.org/linux/man-pages/man2/sendmsg.2.html
+ * @param flags flag. @see flags
* @return zero on success. -1 on error
* @throws LastErrorException if error occurs
*/
@@ -158,6 +160,7 @@ public void connect(SocketAddress endpoint, int timeout) throws IOException {
try {
close();
} catch (IOException e) {
+ // eat
}
throw new IOException("native connect() failed : " + formatError(lee));
@@ -202,6 +205,7 @@ public void shutdownOutput() {
public static class SockAddr extends Structure {
/** socket family */
public short sun_family = AF_UNIX;
+
/** pathname */
public byte[] sun_path;
@@ -210,7 +214,9 @@ public static class SockAddr extends Structure {
*
* @param sunPath path
*/
+ @SuppressWarnings({"this-escape"})
public SockAddr(String sunPath) {
+
byte[] arr = sunPath.getBytes();
sun_path = new byte[arr.length + 1];
System.arraycopy(arr, 0, sun_path, 0, Math.min(sun_path.length - 1, arr.length));
diff --git a/src/main/java/org/mariadb/jdbc/client/tls/HostnameVerifier.java b/src/main/java/org/mariadb/jdbc/client/tls/HostnameVerifier.java
index cb0e9aa72..1f952da6c 100644
--- a/src/main/java/org/mariadb/jdbc/client/tls/HostnameVerifier.java
+++ b/src/main/java/org/mariadb/jdbc/client/tls/HostnameVerifier.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.tls;
import java.net.InetAddress;
diff --git a/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509KeyManager.java b/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509KeyManager.java
index de32f5c34..46846ebef 100644
--- a/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509KeyManager.java
+++ b/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509KeyManager.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.tls;
import java.net.Socket;
diff --git a/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509TrustingManager.java b/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509TrustingManager.java
index ff463e2b6..f6026dbf9 100644
--- a/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509TrustingManager.java
+++ b/src/main/java/org/mariadb/jdbc/client/tls/MariaDbX509TrustingManager.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.tls;
import java.security.cert.X509Certificate;
diff --git a/src/main/java/org/mariadb/jdbc/client/util/MutableByte.java b/src/main/java/org/mariadb/jdbc/client/util/MutableByte.java
index fe043e266..f94284163 100644
--- a/src/main/java/org/mariadb/jdbc/client/util/MutableByte.java
+++ b/src/main/java/org/mariadb/jdbc/client/util/MutableByte.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.util;
/** Mutable int, permitting to update packet sequence */
diff --git a/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java b/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java
index e97338ef3..6010e27a5 100644
--- a/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java
+++ b/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.util;
/** Mutable int */
public class MutableInt {
+ private int value;
+
public MutableInt() {
this.value = -1;
}
@@ -14,8 +15,6 @@ public MutableInt(int value) {
this.value = value;
}
- private int value;
-
/**
* Set new sequence value
*
diff --git a/src/main/java/org/mariadb/jdbc/client/util/Parameter.java b/src/main/java/org/mariadb/jdbc/client/util/Parameter.java
index 3b260ee8b..d983cf692 100644
--- a/src/main/java/org/mariadb/jdbc/client/util/Parameter.java
+++ b/src/main/java/org/mariadb/jdbc/client/util/Parameter.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.util;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/client/util/Parameters.java b/src/main/java/org/mariadb/jdbc/client/util/Parameters.java
index 6e8726b28..8273017b2 100644
--- a/src/main/java/org/mariadb/jdbc/client/util/Parameters.java
+++ b/src/main/java/org/mariadb/jdbc/client/util/Parameters.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client.util;
/** Parameters list */
diff --git a/src/main/java/org/mariadb/jdbc/codec/NonNullParameter.java b/src/main/java/org/mariadb/jdbc/codec/NonNullParameter.java
index a7df9f2f8..86570225a 100644
--- a/src/main/java/org/mariadb/jdbc/codec/NonNullParameter.java
+++ b/src/main/java/org/mariadb/jdbc/codec/NonNullParameter.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/codec/Parameter.java b/src/main/java/org/mariadb/jdbc/codec/Parameter.java
index 2e66b4416..69c71ea46 100644
--- a/src/main/java/org/mariadb/jdbc/codec/Parameter.java
+++ b/src/main/java/org/mariadb/jdbc/codec/Parameter.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java b/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java
index 990483b66..0ee9d8c28 100644
--- a/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java
+++ b/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java b/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java
index c85b37948..1c1f5931b 100644
--- a/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java
+++ b/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.export;
import java.sql.*;
@@ -15,6 +14,7 @@
import org.mariadb.jdbc.MariaDbPoolConnection;
import org.mariadb.jdbc.client.Completion;
import org.mariadb.jdbc.message.server.OkPacket;
+import org.mariadb.jdbc.util.ThreadUtils;
/**
* Exception factory. This permit common error logging, with thread id, dump query, and specific
@@ -103,7 +103,7 @@ private static String buildMsgText(
msg.append("\n name:\"")
.append(thread.getName())
.append("\" pid:")
- .append(thread.getId())
+ .append(ThreadUtils.getId(thread))
.append(" status:")
.append(thread.getState());
for (StackTraceElement trace : traces) {
@@ -193,8 +193,6 @@ public BatchUpdateException createBatchUpdate(
public BatchUpdateException createBatchUpdate(
List res, int length, int[] responseMsg, SQLException sqle) {
int[] updateCounts = new int[length];
-
- int responseIncrement = 0;
for (int i = 0; i < length; i++) {
if (i >= responseMsg.length) {
Arrays.fill(updateCounts, i, length, Statement.EXECUTE_FAILED);
@@ -202,10 +200,18 @@ public BatchUpdateException createBatchUpdate(
}
int MsgResponseNo = responseMsg[i];
if (MsgResponseNo < 1) {
- updateCounts[responseIncrement++] = Statement.EXECUTE_FAILED;
+ updateCounts[0] = Statement.EXECUTE_FAILED;
return new BatchUpdateException(updateCounts, sqle);
- } else if (MsgResponseNo == 1 && res.size() > i && res.get(i) instanceof OkPacket) {
- updateCounts[i] = (int) ((OkPacket) res.get(i)).getAffectedRows();
+ } else if (MsgResponseNo == 1) {
+ if (i >= res.size() || res.get(i) == null) {
+ updateCounts[i] = Statement.EXECUTE_FAILED;
+ continue;
+ }
+ if (res.get(i) instanceof OkPacket) {
+ updateCounts[i] = (int) ((OkPacket) res.get(i)).getAffectedRows();
+ continue;
+ }
+ updateCounts[i] = Statement.SUCCESS_NO_INFO;
} else {
// unknown.
updateCounts[i] = Statement.SUCCESS_NO_INFO;
@@ -261,7 +267,8 @@ private SQLException createException(
// 3948 : mysql load data infile disable
if ((errorCode == 4166 || errorCode == 3948 || errorCode == 1148) && !conf.allowLocalInfile()) {
return new SQLException(
- "Local infile is disabled by connector. Enable `allowLocalInfile` to allow local infile commands",
+ "Local infile is disabled by connector. Enable `allowLocalInfile` to allow local infile"
+ + " commands",
sqlState,
errorCode,
cause);
@@ -358,6 +365,7 @@ public SQLException create(String message, String sqlState) {
public SQLException create(String message, String sqlState, Exception cause) {
return createException(message, sqlState, -1, cause);
}
+
/**
* Creation of an exception
*
diff --git a/src/main/java/org/mariadb/jdbc/export/HaMode.java b/src/main/java/org/mariadb/jdbc/export/HaMode.java
index 95d5ee26e..71cd5baff 100644
--- a/src/main/java/org/mariadb/jdbc/export/HaMode.java
+++ b/src/main/java/org/mariadb/jdbc/export/HaMode.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.export;
import java.util.*;
@@ -64,12 +63,6 @@ public Optional getAvailableHost(
this.value = value;
}
- /** For testing purpose only */
- public void resetLast() {
- lastRoundRobinPrimaryHost = null;
- lastRoundRobinSecondaryHost = null;
- }
-
/**
* Get HAMode from values or aliases
*
@@ -201,6 +194,12 @@ public static Optional getAvailableRoundRobinHost(
return Optional.empty();
}
+ /** For testing purpose only */
+ public void resetLast() {
+ lastRoundRobinPrimaryHost = null;
+ lastRoundRobinSecondaryHost = null;
+ }
+
/**
* List of hosts without blacklist entries, ordered according to HA mode
*
diff --git a/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java b/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java
index 23e0da7b4..00036a42f 100644
--- a/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java
+++ b/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.export;
import java.io.IOException;
@@ -13,6 +12,7 @@
public class MaxAllowedPacketException extends IOException {
private static final long serialVersionUID = 5669184960442818475L;
+
/** is connection in wrong state */
private final boolean mustReconnect;
diff --git a/src/main/java/org/mariadb/jdbc/export/Prepare.java b/src/main/java/org/mariadb/jdbc/export/Prepare.java
index de3a86cdb..6c7d997dd 100644
--- a/src/main/java/org/mariadb/jdbc/export/Prepare.java
+++ b/src/main/java/org/mariadb/jdbc/export/Prepare.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.export;
import java.sql.SQLException;
diff --git a/src/main/java/org/mariadb/jdbc/export/SslMode.java b/src/main/java/org/mariadb/jdbc/export/SslMode.java
index fa28d1552..0d1ab2178 100644
--- a/src/main/java/org/mariadb/jdbc/export/SslMode.java
+++ b/src/main/java/org/mariadb/jdbc/export/SslMode.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.export;
/** SSl requirement */
diff --git a/src/main/java/org/mariadb/jdbc/message/ClientMessage.java b/src/main/java/org/mariadb/jdbc/message/ClientMessage.java
index 979832937..1bc5c35fb 100644
--- a/src/main/java/org/mariadb/jdbc/message/ClientMessage.java
+++ b/src/main/java/org/mariadb/jdbc/message/ClientMessage.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message;
import java.io.FileInputStream;
@@ -29,6 +28,45 @@
public interface ClientMessage {
+ /**
+ * Check that file requested correspond to request.
+ *
+ * @param sql current command sql
+ * @param parameters current command parameter
+ * @param fileName file path request
+ * @param context current connection context
+ * @return true if file name correspond to demand and query is a load local infile
+ */
+ static boolean validateLocalFileName(
+ String sql, Parameters parameters, String fileName, Context context) {
+ String reg =
+ "^(\\s*/\\*([^*]|\\*[^/])*\\*/)*\\s*LOAD\\s+(DATA|XML)\\s+((LOW_PRIORITY|CONCURRENT)\\s+)?LOCAL\\s+INFILE\\s+'"
+ + Pattern.quote(fileName.replace("\\", "\\\\"))
+ + "'";
+
+ Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);
+ if (pattern.matcher(sql).find()) {
+ return true;
+ }
+
+ if (parameters != null) {
+ pattern =
+ Pattern.compile(
+ "^(\\s*/\\*([^*]|\\*[^/])*\\*/)*\\s*LOAD\\s+(DATA|XML)\\s+((LOW_PRIORITY|CONCURRENT)\\s+)?LOCAL\\s+INFILE\\s+\\?",
+ Pattern.CASE_INSENSITIVE);
+ if (pattern.matcher(sql).find() && parameters.size() > 0) {
+ String paramString = parameters.get(0).bestEffortStringValue(context);
+ if (paramString != null) {
+ return paramString
+ .toLowerCase()
+ .equals("'" + fileName.replace("\\", "\\\\").toLowerCase() + "'");
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Encode client message to socket.
*
@@ -146,7 +184,9 @@ default Completion readPacket(
.withSql(this.description())
.create(
String.format(
- "LOAD DATA LOCAL INFILE asked for file '%s' that doesn't correspond to initial query %s. Possible malicious proxy changing server answer ! Command interrupted",
+ "LOAD DATA LOCAL INFILE asked for file '%s' that doesn't correspond to"
+ + " initial query %s. Possible malicious proxy changing server"
+ + " answer ! Command interrupted",
fileName, this.description()),
"HY000");
} else {
@@ -206,7 +246,7 @@ default Completion readPacket(
ColumnDecoder[] ci;
boolean canSkipMeta = context.canSkipMeta() && this.canSkipMeta();
- boolean skipMeta = canSkipMeta ? buf.readByte() == 0 : false;
+ boolean skipMeta = canSkipMeta && buf.readByte() == 0;
if (canSkipMeta && skipMeta) {
ci = ((BasePreparedStatement) stmt).getMeta();
} else {
@@ -291,43 +331,4 @@ default InputStream getLocalInfileInputStream() {
default boolean validateLocalFileName(String fileName, Context context) {
return false;
}
-
- /**
- * Check that file requested correspond to request.
- *
- * @param sql current command sql
- * @param parameters current command parameter
- * @param fileName file path request
- * @param context current connection context
- * @return true if file name correspond to demand and query is a load local infile
- */
- static boolean validateLocalFileName(
- String sql, Parameters parameters, String fileName, Context context) {
- String reg =
- "^(\\s*\\/\\*([^\\*]|\\*[^\\/])*\\*\\/)*\\s*LOAD\\s+(DATA|XML)\\s+((LOW_PRIORITY|CONCURRENT)\\s+)?LOCAL\\s+INFILE\\s+'"
- + Pattern.quote(fileName.replace("\\", "\\\\"))
- + "'";
-
- Pattern pattern = Pattern.compile(reg, Pattern.CASE_INSENSITIVE);
- if (pattern.matcher(sql).find()) {
- return true;
- }
-
- if (parameters != null) {
- pattern =
- Pattern.compile(
- "^(\\s*\\/\\*([^\\*]|\\*[^\\/])*\\*\\/)*\\s*LOAD\\s+(DATA|XML)\\s+((LOW_PRIORITY|CONCURRENT)\\s+)?LOCAL\\s+INFILE\\s+\\?",
- Pattern.CASE_INSENSITIVE);
- if (pattern.matcher(sql).find() && parameters.size() > 0) {
- String paramString = parameters.get(0).bestEffortStringValue(context);
- if (paramString != null) {
- return paramString
- .toLowerCase()
- .equals("'" + fileName.replace("\\", "\\\\").toLowerCase() + "'");
- }
- return true;
- }
- }
- return false;
- }
}
diff --git a/src/main/java/org/mariadb/jdbc/message/ServerMessage.java b/src/main/java/org/mariadb/jdbc/message/ServerMessage.java
index 7028c3ebe..58c38321f 100644
--- a/src/main/java/org/mariadb/jdbc/message/ServerMessage.java
+++ b/src/main/java/org/mariadb/jdbc/message/ServerMessage.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message;
public interface ServerMessage {}
diff --git a/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java b/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java
index ad84bce06..68d809030 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java b/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java
index f5b70e984..0deb44072 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
@@ -19,13 +18,14 @@
import org.mariadb.jdbc.message.server.PrepareResultPacket;
/**
- * batch execution. This relies on COM_STMT_BULK_EXECUTE see
- * https://mariadb.com/kb/en/com_stmt_bulk_execute/
+ * batch execution. This relies on COM_STMT_BULK_EXECUTE
+ *
+ * @see documentation
*/
public final class BulkExecutePacket implements RedoableWithPrepareClientMessage {
- private List batchParameterList;
private final String command;
private final ServerPreparedStatement prep;
+ private List batchParameterList;
private Prepare prepareResult;
/**
diff --git a/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java b/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java
index cdceafcc5..f4c525b33 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java b/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java
index 575d6be4b..b49cdbb7b 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java b/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java
index 4f8e9b9eb..68f1528ef 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
@@ -18,15 +17,16 @@
import org.mariadb.jdbc.plugin.codec.ByteArrayCodec;
/**
- * Execute command (COM_STMT_EXECUTE) See https://mariadb.com/kb/en/com_stmt_execute/ for
- * documentation
+ * Execute command (COM_STMT_EXECUTE)
+ *
+ * @see Execute documentation
*/
public final class ExecutePacket implements RedoableWithPrepareClientMessage {
- private Parameters parameters;
private final String command;
private final ServerPreparedStatement prep;
+ private final InputStream localInfileInputStream;
private Prepare prepareResult;
- private InputStream localInfileInputStream;
+ private Parameters parameters;
/**
* Constructor
@@ -107,7 +107,7 @@ public int encode(Writer writer, Context context, Prepare newPrepareResult)
writer.writeByte(p.getBinaryEncodeType());
writer.writeByte(0);
if (p.isNull()) {
- nullBitsBuffer[i / 8] |= (1 << (i % 8));
+ nullBitsBuffer[i / 8] |= (byte) (1 << (i % 8));
}
}
diff --git a/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java b/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java
index 209e53a85..8d8bc3006 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import static org.mariadb.jdbc.util.constants.Capabilities.*;
@@ -16,11 +15,13 @@
import org.mariadb.jdbc.message.ClientMessage;
import org.mariadb.jdbc.plugin.Credential;
import org.mariadb.jdbc.plugin.authentication.standard.NativePasswordPlugin;
+import org.mariadb.jdbc.util.ThreadUtils;
import org.mariadb.jdbc.util.VersionFactory;
/**
- * Server handshake response builder. see
- * https://mariadb.com/kb/en/connection/#client-handshake-response
+ * Server handshake response builder.
+ *
+ * @see documentation
*/
public final class HandshakeResponse implements ClientMessage {
@@ -102,7 +103,7 @@ private static void writeConnectAttributes(
writeStringLength(tmpWriter, System.getProperty("os.name"));
writeStringLengthAscii(tmpWriter, _THREAD);
- writeStringLength(tmpWriter, Long.toString(Thread.currentThread().getId()));
+ writeStringLength(tmpWriter, Long.toString(ThreadUtils.getId(Thread.currentThread())));
writeStringLengthAscii(tmpWriter, _JAVA_VENDOR);
writeStringLength(tmpWriter, System.getProperty("java.vendor"));
diff --git a/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java b/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java
index c54f5ec47..beddc5f82 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java b/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java
index 02870f223..7bc3a34f6 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/PrepareExecutePacket.java b/src/main/java/org/mariadb/jdbc/message/client/PrepareExecutePacket.java
index 8a5023733..cd3d3f55b 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/PrepareExecutePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/PrepareExecutePacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
@@ -28,14 +27,16 @@
/**
* Send a client COM_STMT_PREPARE + COM_STMT_EXECUTE packets see
- * https://mariadb.com/kb/en/com_stmt_prepare/
+ *
+ * @see Prepare packet
*/
public final class PrepareExecutePacket implements RedoableWithPrepareClientMessage {
private final String sql;
- private Parameters parameters;
private final ServerPreparedStatement prep;
+ private final InputStream localInfileInputStream;
private PrepareResultPacket prepareResult;
- private InputStream localInfileInputStream;
+ private Parameters parameters;
+
/**
* Construct prepare packet
*
@@ -102,7 +103,7 @@ public int encode(Writer writer, Context context, Prepare newPrepareResult)
writer.writeByte(p.getBinaryEncodeType());
writer.writeByte(0);
if (p.isNull()) {
- nullBitsBuffer[i / 8] |= (1 << (i % 8));
+ nullBitsBuffer[i / 8] |= (byte) (1 << (i % 8));
}
}
diff --git a/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java b/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java
index e09b9eb99..42dab25ac 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java b/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java
index 133403058..3e0dec19b 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java b/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java
index 62e71faa3..f31e4847e 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
@@ -24,7 +23,7 @@ public final class QueryWithParametersPacket implements RedoableClientMessage {
private final String preSqlCmd;
private final ClientParser parser;
private Parameters parameters;
- private InputStream localInfileInputStream;
+ private final InputStream localInfileInputStream;
/**
* Constructor
diff --git a/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java b/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java
index 211e6ab3e..71cb2d47d 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java b/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java
index d1ec53f07..55afff173 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java b/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java
index 34fa0717a..e07b3894c 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java b/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java
index 64141b391..64458f352 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java b/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java
index 0009a5847..1cb069258 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.client;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java b/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java
index 3beecb895..706e082c9 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.server;
import java.util.Arrays;
@@ -9,8 +8,10 @@
import org.mariadb.jdbc.message.ServerMessage;
/**
- * Authentication switch packet. See
- * https://mariadb.com/kb/en/connection/#authentication-switch-request
+ * Authentication switch packet.
+ *
+ * @see Authentication
+ * switch packet
*/
public class AuthSwitchPacket implements ServerMessage {
@@ -43,6 +44,16 @@ public static AuthSwitchPacket decode(ReadableByteBuf buf) {
return new AuthSwitchPacket(plugin, seed);
}
+ /**
+ * Get truncated seed (seed without ending 0x00 byte)
+ *
+ * @param seed connection seed
+ * @return truncated seed
+ */
+ public static byte[] getTruncatedSeed(byte[] seed) {
+ return (seed.length > 0) ? Arrays.copyOfRange(seed, 0, seed.length - 1) : new byte[0];
+ }
+
/**
* Get authentication switch plugin information
*
@@ -60,14 +71,4 @@ public String getPlugin() {
public byte[] getSeed() {
return seed;
}
-
- /**
- * Get truncated seed (seed without ending 0x00 byte)
- *
- * @param seed connection seed
- * @return truncated seed
- */
- public static byte[] getTruncatedSeed(byte[] seed) {
- return (seed.length > 0) ? Arrays.copyOfRange(seed, 0, seed.length - 1) : new byte[0];
- }
}
diff --git a/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java b/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java
index 4ae9166ec..db3033828 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.server;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java b/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java
index 9ca8ade63..e33b96d91 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.server;
import java.util.Objects;
@@ -15,23 +14,37 @@
/** Column metadata definition */
public class ColumnDefinitionPacket implements Column, ServerMessage {
- private final ReadableByteBuf buf;
/** charset */
protected final int charset;
+
/** column maximum length */
protected final long columnLength;
- /** data type see https://mariadb.com/kb/en/result-set-packets/#field-types */
+
+ /**
+ * data type @see Field
+ * type
+ */
protected final DataType dataType;
+
/** number of decimal */
protected final byte decimals;
- /** flags see https://mariadb.com/kb/en/result-set-packets/#field-details-flag */
- private final int flags;
- /** string offset position in buffer */
- private final int[] stringPos;
+
/** extended type name */
protected final String extTypeName;
+
/** extended type format */
protected final String extTypeFormat;
+
+ private final ReadableByteBuf buf;
+
+ /**
+ * @see flags
+ */
+ private final int flags;
+
+ /** string offset position in buffer */
+ private final int[] stringPos;
+
/** configuration: use alias as name */
private boolean useAliasAsName;
diff --git a/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java b/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java
index 822650897..36bc21228 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.server;
import org.mariadb.jdbc.client.Context;
diff --git a/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java b/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java
index bb1492b20..2efae3ba8 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.server;
import org.mariadb.jdbc.client.ReadableByteBuf;
diff --git a/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java b/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java
index d05fda5d6..d4e8013c4 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.server;
import org.mariadb.jdbc.client.Completion;
diff --git a/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java b/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java
index 982159f12..4a25dd670 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.server;
import java.io.IOException;
@@ -15,9 +14,15 @@
import org.mariadb.jdbc.util.log.Logger;
import org.mariadb.jdbc.util.log.Loggers;
-/** Prepare result packet See https://mariadb.com/kb/en/com_stmt_prepare/#COM_STMT_PREPARE_OK */
+/**
+ * Prepare result packet
+ *
+ * @see Prepare result
+ * packet *
+ */
public class PrepareResultPacket implements Completion, Prepare {
static final ColumnDecoder CONSTANT_PARAMETER;
+ private static final Logger logger = Loggers.getLogger(PrepareResultPacket.class);
static {
byte[] bytes =
@@ -51,13 +56,13 @@ public class PrepareResultPacket implements Completion, Prepare {
ColumnDecoder.decode(new StandardReadableByteBuf(bytes, bytes.length), true);
}
- private static final Logger logger = Loggers.getLogger(PrepareResultPacket.class);
private final ColumnDecoder[] parameters;
- private ColumnDecoder[] columns;
/** prepare statement id */
protected int statementId;
+ private ColumnDecoder[] columns;
+
/**
* Prepare packet constructor (parsing)
*
diff --git a/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java b/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java
index aa8905d8b..8d729ffe8 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.message.server.util;
import org.mariadb.jdbc.client.ServerVersion;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java
index 6f06c3128..4c8fb517e 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/Codec.java b/src/main/java/org/mariadb/jdbc/plugin/Codec.java
index 8df9ee260..75c132541 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/Codec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/Codec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/Credential.java b/src/main/java/org/mariadb/jdbc/plugin/Credential.java
index a5b71ab69..4e8ac1741 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/Credential.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/Credential.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin;
/** basic Credential (couple of user/password) */
diff --git a/src/main/java/org/mariadb/jdbc/plugin/CredentialPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/CredentialPlugin.java
index de25dc904..1042d752e 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/CredentialPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/CredentialPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin;
import java.sql.SQLException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java
index 3c4cb93cd..ae9c978c1 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/AuthenticationPluginLoader.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/AuthenticationPluginLoader.java
index 4a997b7a4..1d2899a07 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/AuthenticationPluginLoader.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/AuthenticationPluginLoader.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication;
import java.sql.SQLException;
@@ -32,13 +31,14 @@ public static AuthenticationPlugin get(String type, Configuration conf) throws S
for (AuthenticationPlugin implClass : loader) {
if (type.equals(implClass.type())) {
- if (conf.restrictedAuth() == null || Arrays.stream(authList).anyMatch(type::contains)) {
+ if (authList == null || Arrays.stream(authList).anyMatch(type::contains)) {
return implClass;
} else {
throw new SQLException(
String.format(
- "Client restrict authentication plugin to a limited set of authentication plugin and doesn't permit requested plugin ('%s'). "
- + "Current list is `restrictedAuth=%s`",
+ "Client restrict authentication plugin to a limited set of authentication plugin"
+ + " and doesn't permit requested plugin ('%s'). Current list is"
+ + " `restrictedAuth=%s`",
type, conf.restrictedAuth()),
"08004",
1251);
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/ClearPasswordPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/ClearPasswordPlugin.java
index 0e4730f9b..bd23dfbe3 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/ClearPasswordPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/ClearPasswordPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.addon;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java
index 8de9e88ba..e40f105a6 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.addon;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssUtility.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssUtility.java
index 07e8436f4..214c1e89d 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssUtility.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssUtility.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.addon.gssapi;
import com.sun.jna.Platform;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssapiAuth.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssapiAuth.java
index 5f970ae88..7d0946268 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssapiAuth.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/GssapiAuth.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.addon.gssapi;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/StandardGssapiAuthentication.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/StandardGssapiAuthentication.java
index 3ce75b9ee..4d81d18c1 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/StandardGssapiAuthentication.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/StandardGssapiAuthentication.java
@@ -1,11 +1,9 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.addon.gssapi;
import java.io.*;
-import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.sql.SQLException;
import javax.security.auth.Subject;
@@ -15,6 +13,7 @@
import org.mariadb.jdbc.client.ReadableByteBuf;
import org.mariadb.jdbc.client.socket.Reader;
import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.util.ThreadUtils;
/** Basic GSSAPI implementation if waffle is not on classpath */
public class StandardGssapiAuthentication implements GssapiAuth {
@@ -35,8 +34,8 @@ public void authenticate(
if ("".equals(servicePrincipalName)) {
throw new SQLException(
- "No principal name defined on server. "
- + "Please set server variable \"gssapi-principal-name\" or set option \"servicePrincipalName\"",
+ "No principal name defined on server. Please set server variable"
+ + " \"gssapi-principal-name\" or set option \"servicePrincipalName\"",
"28000");
}
@@ -103,8 +102,9 @@ public void authenticate(
}
return null;
};
- Subject.doAs(mySubject, action);
- } catch (PrivilegedActionException exception) {
+
+ ThreadUtils.callAs(mySubject, () -> action);
+ } catch (Exception exception) {
throw new SQLException("GSS-API authentication exception", "28000", 1045, exception);
}
} else {
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/WindowsNativeSspiAuthentication.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/WindowsNativeSspiAuthentication.java
index d87c376aa..9f297ae0a 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/WindowsNativeSspiAuthentication.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/addon/gssapi/WindowsNativeSspiAuthentication.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.addon.gssapi;
import com.sun.jna.platform.win32.Sspi;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/CachingSha2PasswordPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/CachingSha2PasswordPlugin.java
index 0dbeeaeec..9c3caddc6 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/CachingSha2PasswordPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/CachingSha2PasswordPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.standard;
import java.io.IOException;
@@ -72,6 +71,83 @@ public static byte[] sha256encryptPassword(final CharSequence password, final by
}
}
+ /**
+ * Read public Key from file.
+ *
+ * @param serverRsaPublicKeyFile RSA public key file
+ * @return public key
+ * @throws SQLException if having an error reading file or file content is not a public key.
+ */
+ public static PublicKey readPublicKeyFromFile(String serverRsaPublicKeyFile) throws SQLException {
+ byte[] keyBytes;
+ try {
+ keyBytes = Files.readAllBytes(Paths.get(serverRsaPublicKeyFile));
+ } catch (IOException ex) {
+ throw new SQLException(
+ "Could not read server RSA public key from file : "
+ + "serverRsaPublicKeyFile="
+ + serverRsaPublicKeyFile,
+ "S1009",
+ ex);
+ }
+ return generatePublicKey(keyBytes);
+ }
+
+ /**
+ * Read public pem key from String.
+ *
+ * @param publicKeyBytes public key bytes value
+ * @return public key
+ * @throws SQLException if key cannot be parsed
+ */
+ public static PublicKey generatePublicKey(byte[] publicKeyBytes) throws SQLException {
+ try {
+ String publicKey =
+ new String(publicKeyBytes, StandardCharsets.US_ASCII)
+ .replaceAll("(-+BEGIN PUBLIC KEY-+\\r?\\n|\\n?-+END PUBLIC KEY-+\\r?\\n?)", "");
+
+ byte[] keyBytes = Base64.getMimeDecoder().decode(publicKey);
+ X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
+ KeyFactory kf = KeyFactory.getInstance("RSA");
+ return kf.generatePublic(spec);
+ } catch (Exception ex) {
+ throw new SQLException("Could read server RSA public key: " + ex.getMessage(), "S1009", ex);
+ }
+ }
+
+ /**
+ * Encode password with seed and public key.
+ *
+ * @param publicKey public key
+ * @param password password
+ * @param seed seed
+ * @return encoded password
+ * @throws SQLException if cannot encode password
+ */
+ public static byte[] encrypt(PublicKey publicKey, String password, byte[] seed)
+ throws SQLException {
+
+ byte[] correctedSeed = Arrays.copyOfRange(seed, 0, seed.length - 1);
+ byte[] bytePwd = password.getBytes(StandardCharsets.UTF_8);
+
+ byte[] nullFinishedPwd = Arrays.copyOf(bytePwd, bytePwd.length + 1);
+ byte[] xorBytes = new byte[nullFinishedPwd.length];
+ int seedLength = correctedSeed.length;
+
+ for (int i = 0; i < xorBytes.length; i++) {
+ xorBytes[i] = (byte) (nullFinishedPwd[i] ^ correctedSeed[i % seedLength]);
+ }
+
+ try {
+ Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
+ cipher.init(Cipher.ENCRYPT_MODE, publicKey);
+ return cipher.doFinal(xorBytes);
+ } catch (Exception ex) {
+ throw new SQLException(
+ "Error encoding password with public key : " + ex.getMessage(), "S1009", ex);
+ }
+ }
+
@Override
public String type() {
return TYPE;
@@ -143,7 +219,8 @@ public ReadableByteBuf process(Writer out, Reader in, Context context)
// read public key from socket
if (!conf.allowPublicKeyRetrieval()) {
throw new SQLException(
- "RSA public key is not available client side (option serverRsaPublicKeyFile not set)",
+ "RSA public key is not available client side (option serverRsaPublicKeyFile"
+ + " not set)",
"S1009");
}
@@ -180,81 +257,4 @@ public ReadableByteBuf process(Writer out, Reader in, Context context)
}
}
}
-
- /**
- * Read public Key from file.
- *
- * @param serverRsaPublicKeyFile RSA public key file
- * @return public key
- * @throws SQLException if having an error reading file or file content is not a public key.
- */
- public static PublicKey readPublicKeyFromFile(String serverRsaPublicKeyFile) throws SQLException {
- byte[] keyBytes;
- try {
- keyBytes = Files.readAllBytes(Paths.get(serverRsaPublicKeyFile));
- } catch (IOException ex) {
- throw new SQLException(
- "Could not read server RSA public key from file : "
- + "serverRsaPublicKeyFile="
- + serverRsaPublicKeyFile,
- "S1009",
- ex);
- }
- return generatePublicKey(keyBytes);
- }
-
- /**
- * Read public pem key from String.
- *
- * @param publicKeyBytes public key bytes value
- * @return public key
- * @throws SQLException if key cannot be parsed
- */
- public static PublicKey generatePublicKey(byte[] publicKeyBytes) throws SQLException {
- try {
- String publicKey =
- new String(publicKeyBytes, StandardCharsets.US_ASCII)
- .replaceAll("(-+BEGIN PUBLIC KEY-+\\r?\\n|\\n?-+END PUBLIC KEY-+\\r?\\n?)", "");
-
- byte[] keyBytes = Base64.getMimeDecoder().decode(publicKey);
- X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
- KeyFactory kf = KeyFactory.getInstance("RSA");
- return kf.generatePublic(spec);
- } catch (Exception ex) {
- throw new SQLException("Could read server RSA public key: " + ex.getMessage(), "S1009", ex);
- }
- }
-
- /**
- * Encode password with seed and public key.
- *
- * @param publicKey public key
- * @param password password
- * @param seed seed
- * @return encoded password
- * @throws SQLException if cannot encode password
- */
- public static byte[] encrypt(PublicKey publicKey, String password, byte[] seed)
- throws SQLException {
-
- byte[] correctedSeed = Arrays.copyOfRange(seed, 0, seed.length - 1);
- byte[] bytePwd = password.getBytes(StandardCharsets.UTF_8);
-
- byte[] nullFinishedPwd = Arrays.copyOf(bytePwd, bytePwd.length + 1);
- byte[] xorBytes = new byte[nullFinishedPwd.length];
- int seedLength = correctedSeed.length;
-
- for (int i = 0; i < xorBytes.length; i++) {
- xorBytes[i] = (byte) (nullFinishedPwd[i] ^ correctedSeed[i % seedLength]);
- }
-
- try {
- Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");
- cipher.init(Cipher.ENCRYPT_MODE, publicKey);
- return cipher.doFinal(xorBytes);
- } catch (Exception ex) {
- throw new SQLException(
- "Error encoding password with public key : " + ex.getMessage(), "S1009", ex);
- }
- }
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/Ed25519PasswordPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/Ed25519PasswordPlugin.java
index 2968b3f04..c963af900 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/Ed25519PasswordPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/Ed25519PasswordPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.standard;
import java.io.IOException;
@@ -47,7 +46,7 @@ private static byte[] ed25519SignWithPassword(final String password, final byte[
final byte[] sm = new byte[64 + mlen];
byte[] az = hash.digest(bytePwd);
- az[0] &= 248;
+ az[0] &= (byte) 248;
az[31] &= 63;
az[31] |= 64;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/NativePasswordPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/NativePasswordPlugin.java
index 3d8721e9b..de7422a77 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/NativePasswordPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/NativePasswordPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.standard;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/SendPamAuthPacket.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/SendPamAuthPacket.java
index a9c40c3e0..93c1270bb 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/SendPamAuthPacket.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/SendPamAuthPacket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.authentication.standard;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/Utils.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/Utils.java
index 650e92569..0c0405333 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/Utils.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/Utils.java
@@ -1,3 +1,6 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2023 MariaDB Corporation Ab
package org.mariadb.jdbc.plugin.authentication.standard.ed25519;
/**
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/Curve.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/Curve.java
index 049f123e4..b96191560 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/Curve.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/Curve.java
@@ -19,6 +19,7 @@ public class Curve implements Serializable {
private final GroupElement zeroP3PrecomputedDouble;
private final GroupElement zeroPrecomp;
+ @SuppressWarnings({"this-escape"})
public Curve(Field f, byte[] d, FieldElement I) {
this.f = f;
this.d = f.fromByteArray(d);
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/Field.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/Field.java
index 2eecde671..a556eb5b3 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/Field.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/Field.java
@@ -7,6 +7,7 @@
*
* @author str4d
*/
+@SuppressWarnings("all")
public class Field implements Serializable {
private static final long serialVersionUID = 8746587465875676L;
@@ -19,13 +20,16 @@ public class Field implements Serializable {
private final int b;
private final FieldElement q;
+
/** q-2 */
private final FieldElement qm2;
+
/** (q-5) / 8 */
private final FieldElement qm5d8;
private final Encoding enc;
+ @SuppressWarnings({"this-escape"})
public Field(int b, byte[] q, Encoding enc) {
this.b = b;
this.enc = enc;
@@ -54,6 +58,18 @@ public int getb() {
return b;
}
+ public FieldElement getQ() {
+ return q;
+ }
+
+ public FieldElement getQm2() {
+ return qm2;
+ }
+
+ public FieldElement getQm5d8() {
+ return qm5d8;
+ }
+
public Encoding getEncoding() {
return enc;
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/GroupElement.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/GroupElement.java
index feb9ffa5b..1df002360 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/GroupElement.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/GroupElement.java
@@ -24,147 +24,15 @@
*
* @author str4d
*/
+@SuppressWarnings("all")
public class GroupElement implements Serializable {
private static final long serialVersionUID = 2395879087349587L;
- /**
- * Available representations for a group element.
- *
- *
- * P2: Projective representation $(X:Y:Z)$ satisfying $x=X/Z, y=Y/Z$.
- * P3: Extended projective representation $(X:Y:Z:T)$ satisfying $x=X/Z, y=Y/Z, XY=ZT$.
- * P3PrecomputedDouble: P3 but with dblPrecmp populated.
- * P1P1: Completed representation $((X:Z), (Y:T))$ satisfying $x=X/Z, y=Y/T$.
- * PRECOMP: Precomputed representation $(y+x, y-x, 2dxy)$.
- * CACHED: Cached representation $(Y+X, Y-X, Z, 2dT)$
- *
- */
- public enum Representation {
- /** Projective ($P^2$): $(X:Y:Z)$ satisfying $x=X/Z, y=Y/Z$ */
- P2,
- /** Extended ($P^3$): $(X:Y:Z:T)$ satisfying $x=X/Z, y=Y/Z, XY=ZT$ */
- P3,
- /** Can only be requested. Results in P3 representation but also populates dblPrecmp. */
- P3PrecomputedDouble,
- /** Completed ($P \times P$): $((X:Z),(Y:T))$ satisfying $x=X/Z, y=Y/T$ */
- P1P1,
- /** Precomputed (Duif): $(y+x,y-x,2dxy)$ */
- PRECOMP,
- /** Cached: $(Y+X,Y-X,Z,2dT)$ */
- CACHED
- }
-
- /**
- * Creates a new group element in P2 representation.
- *
- * @param curve The curve.
- * @param X The $X$ coordinate.
- * @param Y The $Y$ coordinate.
- * @param Z The $Z$ coordinate.
- * @return The group element in P2 representation.
- */
- public static GroupElement p2(
- final Curve curve, final FieldElement X, final FieldElement Y, final FieldElement Z) {
- return new GroupElement(curve, Representation.P2, X, Y, Z, null);
- }
-
- /**
- * Creates a new group element in P3 representation, without pre-computation.
- *
- * @param curve The curve.
- * @param X The $X$ coordinate.
- * @param Y The $Y$ coordinate.
- * @param Z The $Z$ coordinate.
- * @param T The $T$ coordinate.
- * @return The group element in P3 representation.
- */
- public static GroupElement p3(
- final Curve curve,
- final FieldElement X,
- final FieldElement Y,
- final FieldElement Z,
- final FieldElement T) {
- return p3(curve, X, Y, Z, T, false);
- }
-
- /**
- * Creates a new group element in P3 representation, potentially with pre-computation.
- *
- * @param curve The curve.
- * @param X The $X$ coordinate.
- * @param Y The $Y$ coordinate.
- * @param Z The $Z$ coordinate.
- * @param T The $T$ coordinate.
- * @param precomputeDoubleOnly If true, populate dblPrecmp, else set to null.
- * @return The group element in P3 representation.
- */
- public static GroupElement p3(
- final Curve curve,
- final FieldElement X,
- final FieldElement Y,
- final FieldElement Z,
- final FieldElement T,
- final boolean precomputeDoubleOnly) {
- return new GroupElement(curve, Representation.P3, X, Y, Z, T, precomputeDoubleOnly);
- }
-
- /**
- * Creates a new group element in P1P1 representation.
- *
- * @param curve The curve.
- * @param X The $X$ coordinate.
- * @param Y The $Y$ coordinate.
- * @param Z The $Z$ coordinate.
- * @param T The $T$ coordinate.
- * @return The group element in P1P1 representation.
- */
- public static GroupElement p1p1(
- final Curve curve,
- final FieldElement X,
- final FieldElement Y,
- final FieldElement Z,
- final FieldElement T) {
- return new GroupElement(curve, Representation.P1P1, X, Y, Z, T);
- }
-
- /**
- * Creates a new group element in PRECOMP representation.
- *
- * @param curve The curve.
- * @param ypx The $y + x$ value.
- * @param ymx The $y - x$ value.
- * @param xy2d The $2 * d * x * y$ value.
- * @return The group element in PRECOMP representation.
- */
- public static GroupElement precomp(
- final Curve curve, final FieldElement ypx, final FieldElement ymx, final FieldElement xy2d) {
- return new GroupElement(curve, Representation.PRECOMP, ypx, ymx, xy2d, null);
- }
-
- /**
- * Creates a new group element in CACHED representation.
- *
- * @param curve The curve.
- * @param YpX The $Y + X$ value.
- * @param YmX The $Y - X$ value.
- * @param Z The $Z$ coordinate.
- * @param T2d The $2 * d * T$ value.
- * @return The group element in CACHED representation.
- */
- public static GroupElement cached(
- final Curve curve,
- final FieldElement YpX,
- final FieldElement YmX,
- final FieldElement Z,
- final FieldElement T2d) {
- return new GroupElement(curve, Representation.CACHED, YpX, YmX, Z, T2d);
- }
-
/** Variable is package private only so that tests run. */
final Curve curve;
/** Variable is package private only so that tests run. */
- final Representation repr;
+ final GroupElement.Representation repr;
/** Variable is package private only so that tests run. */
final FieldElement X;
@@ -186,7 +54,8 @@ public static GroupElement cached(
final GroupElement[][] precmp;
/**
- * Precomputed table for , filled if necessary.
+ * Precomputed table for {@link #doubleScalarMultiplyVariableTime(GroupElement, byte[], byte[])},
+ * filled if necessary.
*
* Variable is package private only so that tests run.
*/
@@ -202,9 +71,10 @@ public static GroupElement cached(
* @param Z The $Z$ coordinate.
* @param T The $T$ coordinate.
*/
+ @SuppressWarnings({"this-escape"})
public GroupElement(
final Curve curve,
- final Representation repr,
+ final GroupElement.Representation repr,
final FieldElement X,
final FieldElement Y,
final FieldElement Z,
@@ -223,9 +93,10 @@ public GroupElement(
* @param T The $T$ coordinate.
* @param precomputeDouble If true, populate dblPrecmp, else set to null.
*/
+ @SuppressWarnings({"this-escape"})
public GroupElement(
final Curve curve,
- final Representation repr,
+ final GroupElement.Representation repr,
final FieldElement X,
final FieldElement Y,
final FieldElement Z,
@@ -283,6 +154,7 @@ public GroupElement(final Curve curve, final byte[] s) {
* @param precomputeSingleAndDouble If true, populate both precmp and dblPrecmp, else set both to
* null.
*/
+ @SuppressWarnings({"this-escape"})
public GroupElement(final Curve curve, final byte[] s, boolean precomputeSingleAndDouble) {
FieldElement x, y, yy, u, v, v3, vxx, check;
y = curve.getField().fromByteArray(s);
@@ -320,7 +192,7 @@ public GroupElement(final Curve curve, final byte[] s, boolean precomputeSingleA
}
this.curve = curve;
- this.repr = Representation.P3;
+ this.repr = GroupElement.Representation.P3;
this.X = x;
this.Y = y;
this.Z = curve.getField().ONE;
@@ -334,15 +206,248 @@ public GroupElement(final Curve curve, final byte[] s, boolean precomputeSingleA
}
}
+ /**
+ * Creates a new group element in P2 representation.
+ *
+ * @param curve The curve.
+ * @param X The $X$ coordinate.
+ * @param Y The $Y$ coordinate.
+ * @param Z The $Z$ coordinate.
+ * @return The group element in P2 representation.
+ */
+ public static GroupElement p2(
+ final Curve curve, final FieldElement X, final FieldElement Y, final FieldElement Z) {
+ return new GroupElement(curve, GroupElement.Representation.P2, X, Y, Z, null);
+ }
+
+ /**
+ * Creates a new group element in P3 representation, without pre-computation.
+ *
+ * @param curve The curve.
+ * @param X The $X$ coordinate.
+ * @param Y The $Y$ coordinate.
+ * @param Z The $Z$ coordinate.
+ * @param T The $T$ coordinate.
+ * @return The group element in P3 representation.
+ */
+ public static GroupElement p3(
+ final Curve curve,
+ final FieldElement X,
+ final FieldElement Y,
+ final FieldElement Z,
+ final FieldElement T) {
+ return p3(curve, X, Y, Z, T, false);
+ }
+
+ /**
+ * Creates a new group element in P3 representation, potentially with pre-computation.
+ *
+ * @param curve The curve.
+ * @param X The $X$ coordinate.
+ * @param Y The $Y$ coordinate.
+ * @param Z The $Z$ coordinate.
+ * @param T The $T$ coordinate.
+ * @param precomputeDoubleOnly If true, populate dblPrecmp, else set to null.
+ * @return The group element in P3 representation.
+ */
+ public static GroupElement p3(
+ final Curve curve,
+ final FieldElement X,
+ final FieldElement Y,
+ final FieldElement Z,
+ final FieldElement T,
+ final boolean precomputeDoubleOnly) {
+ return new GroupElement(
+ curve, GroupElement.Representation.P3, X, Y, Z, T, precomputeDoubleOnly);
+ }
+
+ /**
+ * Creates a new group element in P1P1 representation.
+ *
+ * @param curve The curve.
+ * @param X The $X$ coordinate.
+ * @param Y The $Y$ coordinate.
+ * @param Z The $Z$ coordinate.
+ * @param T The $T$ coordinate.
+ * @return The group element in P1P1 representation.
+ */
+ public static GroupElement p1p1(
+ final Curve curve,
+ final FieldElement X,
+ final FieldElement Y,
+ final FieldElement Z,
+ final FieldElement T) {
+ return new GroupElement(curve, GroupElement.Representation.P1P1, X, Y, Z, T);
+ }
+
+ /**
+ * Creates a new group element in PRECOMP representation.
+ *
+ * @param curve The curve.
+ * @param ypx The $y + x$ value.
+ * @param ymx The $y - x$ value.
+ * @param xy2d The $2 * d * x * y$ value.
+ * @return The group element in PRECOMP representation.
+ */
+ public static GroupElement precomp(
+ final Curve curve, final FieldElement ypx, final FieldElement ymx, final FieldElement xy2d) {
+ return new GroupElement(curve, GroupElement.Representation.PRECOMP, ypx, ymx, xy2d, null);
+ }
+
+ /**
+ * Creates a new group element in CACHED representation.
+ *
+ * @param curve The curve.
+ * @param YpX The $Y + X$ value.
+ * @param YmX The $Y - X$ value.
+ * @param Z The $Z$ coordinate.
+ * @param T2d The $2 * d * T$ value.
+ * @return The group element in CACHED representation.
+ */
+ public static GroupElement cached(
+ final Curve curve,
+ final FieldElement YpX,
+ final FieldElement YmX,
+ final FieldElement Z,
+ final FieldElement T2d) {
+ return new GroupElement(curve, GroupElement.Representation.CACHED, YpX, YmX, Z, T2d);
+ }
+
+ /**
+ * Convert a to radix 16.
+ *
+ *
Method is package private only so that tests run.
+ *
+ * @param a $= a[0]+256*a[1]+...+256^{31} a[31]$
+ * @return 64 bytes, each between -8 and 7
+ */
+ static byte[] toRadix16(final byte[] a) {
+ final byte[] e = new byte[64];
+ int i;
+ // Radix 16 notation
+ for (i = 0; i < 32; i++) {
+ e[2 * i] = (byte) (a[i] & 15);
+ e[2 * i + 1] = (byte) ((a[i] >> 4) & 15);
+ }
+ /* each e[i] is between 0 and 15 */
+ /* e[63] is between 0 and 7 */
+ int carry = 0;
+ for (i = 0; i < 63; i++) {
+ e[i] += carry;
+ carry = e[i] + 8;
+ carry >>= 4;
+ e[i] -= carry << 4;
+ }
+ e[63] += carry;
+ /* each e[i] is between -8 and 7 */
+ return e;
+ }
+
+ /**
+ * Calculates a sliding-windows base 2 representation for a given value $a$. To learn more about
+ * it see [6] page 8.
+ *
+ *
Output: $r$ which satisfies $a = r0 * 2^0 + r1 * 2^1 + \dots + r255 * 2^{255}$ with $ri$ in
+ * $\{-15, -13, -11, -9, -7, -5, -3, -1, 0, 1, 3, 5, 7, 9, 11, 13, 15\}$
+ *
+ *
Method is package private only so that tests run.
+ *
+ * @param a $= a[0]+256*a[1]+\dots+256^{31} a[31]$.
+ * @return The byte array $r$ in the above described form.
+ */
+ static byte[] slide(final byte[] a) {
+ byte[] r = new byte[256];
+
+ // Put each bit of 'a' into a separate byte, 0 or 1
+ for (int i = 0; i < 256; ++i) {
+ r[i] = (byte) (1 & (a[i >> 3] >> (i & 7)));
+ }
+
+ // Note: r[i] will always be odd.
+ for (int i = 0; i < 256; ++i) {
+ if (r[i] != 0) {
+ for (int b = 1; b <= 6 && i + b < 256; ++b) {
+ // Accumulate bits if possible
+ if (r[i + b] != 0) {
+ if (r[i] + (r[i + b] << b) <= 15) {
+ r[i] += r[i + b] << b;
+ r[i + b] = 0;
+ } else if (r[i] - (r[i + b] << b) >= -15) {
+ r[i] -= r[i + b] << b;
+ for (int k = i + b; k < 256; ++k) {
+ if (r[k] == 0) {
+ r[k] = 1;
+ break;
+ }
+ r[k] = 0;
+ }
+ } else break;
+ }
+ }
+ }
+ }
+
+ return r;
+ }
+
+ /**
+ * Gets the curve of the group element.
+ *
+ * @return The curve.
+ */
+ public Curve getCurve() {
+ return this.curve;
+ }
+
/**
* Gets the representation of the group element.
*
* @return The representation.
*/
- public Representation getRepresentation() {
+ public GroupElement.Representation getRepresentation() {
return this.repr;
}
+ /**
+ * Gets the $X$ value of the group element. This is for most representation the projective $X$
+ * coordinate.
+ *
+ * @return The $X$ value.
+ */
+ public FieldElement getX() {
+ return this.X;
+ }
+
+ /**
+ * Gets the $Y$ value of the group element. This is for most representation the projective $Y$
+ * coordinate.
+ *
+ * @return The $Y$ value.
+ */
+ public FieldElement getY() {
+ return this.Y;
+ }
+
+ /**
+ * Gets the $Z$ value of the group element. This is for most representation the projective $Z$
+ * coordinate.
+ *
+ * @return The $Z$ value.
+ */
+ public FieldElement getZ() {
+ return this.Z;
+ }
+
+ /**
+ * Gets the $T$ value of the group element. This is for most representation the projective $T$
+ * coordinate.
+ *
+ * @return The $T$ value.
+ */
+ public FieldElement getT() {
+ return this.T;
+ }
+
/**
* Converts the group element to an encoded point on the curve.
*
@@ -369,7 +474,7 @@ public byte[] toByteArray() {
* @return The group element in the P2 representation.
*/
public GroupElement toP2() {
- return toRep(Representation.P2);
+ return toRep(GroupElement.Representation.P2);
}
/**
@@ -378,7 +483,7 @@ public GroupElement toP2() {
* @return The group element in the P3 representation.
*/
public GroupElement toP3() {
- return toRep(Representation.P3);
+ return toRep(GroupElement.Representation.P3);
}
/**
@@ -387,7 +492,7 @@ public GroupElement toP3() {
* @return The group element in the P3 representation.
*/
public GroupElement toP3PrecomputeDouble() {
- return toRep(Representation.P3PrecomputedDouble);
+ return toRep(GroupElement.Representation.P3PrecomputedDouble);
}
/**
@@ -396,7 +501,7 @@ public GroupElement toP3PrecomputeDouble() {
* @return The group element in the CACHED representation.
*/
public GroupElement toCached() {
- return toRep(Representation.CACHED);
+ return toRep(GroupElement.Representation.CACHED);
}
/**
@@ -416,13 +521,15 @@ public GroupElement toCached() {
* @param repr The representation to convert to.
* @return A new group element in the given representation.
*/
- private GroupElement toRep(final Representation repr) {
+ private GroupElement toRep(final GroupElement.Representation repr) {
switch (this.repr) {
case P2:
- if (repr == Representation.P2) {
- return p2(this.curve, this.X, this.Y, this.Z);
+ switch (repr) {
+ case P2:
+ return p2(this.curve, this.X, this.Y, this.Z);
+ default:
+ throw new IllegalArgumentException();
}
- throw new IllegalArgumentException();
case P3:
switch (repr) {
case P2:
@@ -466,15 +573,19 @@ private GroupElement toRep(final Representation repr) {
throw new IllegalArgumentException();
}
case PRECOMP:
- if (repr == Representation.PRECOMP) {
- return precomp(this.curve, this.X, this.Y, this.Z);
+ switch (repr) {
+ case PRECOMP:
+ return precomp(this.curve, this.X, this.Y, this.Z);
+ default:
+ throw new IllegalArgumentException();
}
- throw new IllegalArgumentException();
case CACHED:
- if (repr == Representation.CACHED) {
- return cached(this.curve, this.X, this.Y, this.Z, this.T);
+ switch (repr) {
+ case CACHED:
+ return cached(this.curve, this.X, this.Y, this.Z, this.T);
+ default:
+ throw new IllegalArgumentException();
}
- throw new IllegalArgumentException();
default:
throw new UnsupportedOperationException();
}
@@ -505,7 +616,9 @@ private GroupElement[][] precomputeSingle() {
return precmp;
}
- /** Precomputes table for . */
+ /**
+ * Precomputes table for {@link #doubleScalarMultiplyVariableTime(GroupElement, byte[], byte[])}.
+ */
private GroupElement[] precomputeDouble() {
// Precomputation for double scalar multiplication.
// P,3P,5P,7P,9P,11P,13P,15P
@@ -635,8 +748,8 @@ public GroupElement dbl() {
* @return the P1P1 representation of the result.
*/
private GroupElement madd(GroupElement q) {
- if (this.repr != Representation.P3) throw new UnsupportedOperationException();
- if (q.repr != Representation.PRECOMP) throw new IllegalArgumentException();
+ if (this.repr != GroupElement.Representation.P3) throw new UnsupportedOperationException();
+ if (q.repr != GroupElement.Representation.PRECOMP) throw new IllegalArgumentException();
FieldElement YpX, YmX, A, B, C, D;
YpX = this.Y.add(this.X);
@@ -663,8 +776,8 @@ private GroupElement madd(GroupElement q) {
* @return the P1P1 representation of the result.
*/
private GroupElement msub(GroupElement q) {
- if (this.repr != Representation.P3) throw new UnsupportedOperationException();
- if (q.repr != Representation.PRECOMP) throw new IllegalArgumentException();
+ if (this.repr != GroupElement.Representation.P3) throw new UnsupportedOperationException();
+ if (q.repr != GroupElement.Representation.PRECOMP) throw new IllegalArgumentException();
FieldElement YpX, YmX, A, B, C, D;
YpX = this.Y.add(this.X);
@@ -708,8 +821,8 @@ private GroupElement msub(GroupElement q) {
* @return the P1P1 representation of the result.
*/
public GroupElement add(GroupElement q) {
- if (this.repr != Representation.P3) throw new UnsupportedOperationException();
- if (q.repr != Representation.CACHED) throw new IllegalArgumentException();
+ if (this.repr != GroupElement.Representation.P3) throw new UnsupportedOperationException();
+ if (q.repr != GroupElement.Representation.CACHED) throw new IllegalArgumentException();
FieldElement YpX, YmX, A, B, C, ZZ, D;
YpX = this.Y.add(this.X);
@@ -735,8 +848,8 @@ public GroupElement add(GroupElement q) {
* @return the P1P1 representation of the result.
*/
public GroupElement sub(GroupElement q) {
- if (this.repr != Representation.P3) throw new UnsupportedOperationException();
- if (q.repr != Representation.CACHED) throw new IllegalArgumentException();
+ if (this.repr != GroupElement.Representation.P3) throw new UnsupportedOperationException();
+ if (q.repr != GroupElement.Representation.CACHED) throw new IllegalArgumentException();
FieldElement YpX, YmX, A, B, C, ZZ, D;
YpX = Y.add(X);
@@ -757,8 +870,11 @@ public GroupElement sub(GroupElement q) {
* @return The negative of this group element.
*/
public GroupElement negate() {
- if (this.repr != Representation.P3) throw new UnsupportedOperationException();
- return this.curve.getZero(Representation.P3).sub(toCached()).toP3PrecomputeDouble();
+ if (this.repr != GroupElement.Representation.P3) throw new UnsupportedOperationException();
+ return this.curve
+ .getZero(GroupElement.Representation.P3)
+ .sub(toCached())
+ .toP3PrecomputeDouble();
}
@Override
@@ -811,36 +927,6 @@ public boolean equals(Object obj) {
}
}
- /**
- * Convert a to radix 16.
- *
- *
Method is package private only so that tests run.
- *
- * @param a $= a[0]+256*a[1]+...+256^{31} a[31]$
- * @return 64 bytes, each between -8 and 7
- */
- static byte[] toRadix16(final byte[] a) {
- final byte[] e = new byte[64];
- int i;
- // Radix 16 notation
- for (i = 0; i < 32; i++) {
- e[2 * i] = (byte) (a[i] & 15);
- e[2 * i + 1] = (byte) ((a[i] >> 4) & 15);
- }
- /* each e[i] is between 0 and 15 */
- /* e[63] is between 0 and 7 */
- int carry = 0;
- for (i = 0; i < 63; i++) {
- e[i] += carry;
- carry = e[i] + 8;
- carry >>= 4;
- e[i] -= carry << 4;
- }
- e[63] += carry;
- /* each e[i] is between -8 and 7 */
- return e;
- }
-
/**
* Constant-time conditional move.
*
@@ -879,7 +965,7 @@ GroupElement select(final int pos, final int b) {
// 16^i |r_i| B
final GroupElement t =
this.curve
- .getZero(Representation.PRECOMP)
+ .getZero(GroupElement.Representation.PRECOMP)
.cmov(this.precmp[pos][0], Utils.equal(babs, 1))
.cmov(this.precmp[pos][1], Utils.equal(babs, 2))
.cmov(this.precmp[pos][2], Utils.equal(babs, 3))
@@ -910,7 +996,7 @@ public GroupElement scalarMultiply(final byte[] a) {
final byte[] e = toRadix16(a);
- GroupElement h = this.curve.getZero(Representation.P3);
+ GroupElement h = this.curve.getZero(GroupElement.Representation.P3);
for (i = 1; i < 64; i += 2) {
t = select(i / 2, e[i]);
h = h.madd(t).toP3();
@@ -927,52 +1013,59 @@ public GroupElement scalarMultiply(final byte[] a) {
}
/**
- * Calculates a sliding-windows base 2 representation for a given value $a$. To learn more about
- * it see [6] page 8.
- *
- *
Output: $r$ which satisfies $a = r0 * 2^0 + r1 * 2^1 + \dots + r255 * 2^{255}$ with $ri$ in
- * $\{-15, -13, -11, -9, -7, -5, -3, -1, 0, 1, 3, 5, 7, 9, 11, 13, 15\}$
+ * $r = a * A + b * B$ where $a = a[0]+256*a[1]+\dots+256^{31} a[31]$, $b =
+ * b[0]+256*b[1]+\dots+256^{31} b[31]$ and $B$ is this point.
*
- *
Method is package private only so that tests run.
+ *
$A$ must have been previously precomputed.
*
- * @param a $= a[0]+256*a[1]+\dots+256^{31} a[31]$.
- * @return The byte array $r$ in the above described form.
+ * @param A in P3 representation.
+ * @param a $= a[0]+256*a[1]+\dots+256^{31} a[31]$
+ * @param b $= b[0]+256*b[1]+\dots+256^{31} b[31]$
+ * @return the GroupElement
*/
- static byte[] slide(final byte[] a) {
- byte[] r = new byte[256];
+ public GroupElement doubleScalarMultiplyVariableTime(
+ final GroupElement A, final byte[] a, final byte[] b) {
+ // TODO-CR BR: A check that this is the base point is needed.
+ final byte[] aslide = slide(a);
+ final byte[] bslide = slide(b);
- // Put each bit of 'a' into a separate byte, 0 or 1
- for (int i = 0; i < 256; ++i) {
- r[i] = (byte) (1 & (a[i >> 3] >> (i & 7)));
+ GroupElement r = this.curve.getZero(GroupElement.Representation.P2);
+
+ int i;
+ for (i = 255; i >= 0; --i) {
+ if (aslide[i] != 0 || bslide[i] != 0) break;
}
- // Note: r[i] will always be odd.
- for (int i = 0; i < 256; ++i) {
- if (r[i] != 0) {
- for (int b = 1; b <= 6 && i + b < 256; ++b) {
- // Accumulate bits if possible
- if (r[i + b] != 0) {
- if (r[i] + (r[i + b] << b) <= 15) {
- r[i] += r[i + b] << b;
- r[i + b] = 0;
- } else if (r[i] - (r[i + b] << b) >= -15) {
- r[i] -= r[i + b] << b;
- for (int k = i + b; k < 256; ++k) {
- if (r[k] == 0) {
- r[k] = 1;
- break;
- }
- r[k] = 0;
- }
- } else break;
- }
- }
+ for (; i >= 0; --i) {
+ GroupElement t = r.dbl();
+
+ if (aslide[i] > 0) {
+ t = t.toP3().madd(A.dblPrecmp[aslide[i] / 2]);
+ } else if (aslide[i] < 0) {
+ t = t.toP3().msub(A.dblPrecmp[(-aslide[i]) / 2]);
}
+
+ if (bslide[i] > 0) {
+ t = t.toP3().madd(this.dblPrecmp[bslide[i] / 2]);
+ } else if (bslide[i] < 0) {
+ t = t.toP3().msub(this.dblPrecmp[(-bslide[i]) / 2]);
+ }
+
+ r = t.toP2();
}
return r;
}
+ /**
+ * Verify that a point is on its curve.
+ *
+ * @return true if the point lies on its curve.
+ */
+ public boolean isOnCurve() {
+ return isOnCurve(curve);
+ }
+
/**
* Verify that a point is on the curve.
*
@@ -1000,4 +1093,31 @@ public boolean isOnCurve(Curve curve) {
public String toString() {
return "[GroupElement\nX=" + X + "\nY=" + Y + "\nZ=" + Z + "\nT=" + T + "\n]";
}
+
+ /**
+ * Available representations for a group element.
+ *
+ *
+ * P2: Projective representation $(X:Y:Z)$ satisfying $x=X/Z, y=Y/Z$.
+ * P3: Extended projective representation $(X:Y:Z:T)$ satisfying $x=X/Z, y=Y/Z, XY=ZT$.
+ * P3PrecomputedDouble: P3 but with dblPrecmp populated.
+ * P1P1: Completed representation $((X:Z), (Y:T))$ satisfying $x=X/Z, y=Y/T$.
+ * PRECOMP: Precomputed representation $(y+x, y-x, 2dxy)$.
+ * CACHED: Cached representation $(Y+X, Y-X, Z, 2dT)$
+ *
+ */
+ public enum Representation {
+ /** Projective ($P^2$): $(X:Y:Z)$ satisfying $x=X/Z, y=Y/Z$ */
+ P2,
+ /** Extended ($P^3$): $(X:Y:Z:T)$ satisfying $x=X/Z, y=Y/Z, XY=ZT$ */
+ P3,
+ /** Can only be requested. Results in P3 representation but also populates dblPrecmp. */
+ P3PrecomputedDouble,
+ /** Completed ($P \times P$): $((X:Z),(Y:T))$ satisfying $x=X/Z, y=Y/T$ */
+ P1P1,
+ /** Precomputed (Duif): $(y+x,y-x,2dxy)$ */
+ PRECOMP,
+ /** Cached: $(Y+X,Y-X,Z,2dT)$ */
+ CACHED
+ }
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ScalarOps.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ScalarOps.java
index c52b7f26f..2779e4e07 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ScalarOps.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ScalarOps.java
@@ -1,3 +1,6 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2023 MariaDB Corporation Ab
package org.mariadb.jdbc.plugin.authentication.standard.ed25519.math;
public interface ScalarOps {
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519FieldElement.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519FieldElement.java
index 37fb78bab..c2a413a58 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519FieldElement.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519FieldElement.java
@@ -2,8 +2,7 @@
import java.util.Arrays;
import org.mariadb.jdbc.plugin.authentication.standard.ed25519.Utils;
-import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.Field;
-import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.FieldElement;
+import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.*;
/**
* Class to represent a field element of the finite field $p = 2^{255} - 19$ elements.
@@ -16,6 +15,8 @@
*/
public class Ed25519FieldElement extends FieldElement {
private static final long serialVersionUID = -2455098303824960263L;
+ private static final byte[] ZERO = new byte[32];
+
/** Variable is package private for encoding. */
final int[] t;
@@ -31,8 +32,6 @@ public Ed25519FieldElement(Field f, int[] t) {
this.t = t;
}
- private static final byte[] ZERO = new byte[32];
-
/**
* Gets a value indicating whether or not the field element is non-zero.
*
@@ -286,6 +285,16 @@ public FieldElement multiply(FieldElement val) {
long f9g8_19 = t[9] * (long) g8_19;
long f9g9_38 = f9_2 * (long) g9_19;
+ /**
+ * Remember: 2^255 congruent 19 modulo p. h = h0 * 2^0 + h1 * 2^26 + h2 * 2^(26+25) + h3 *
+ * 2^(26+25+26) + ... + h9 * 2^(5*26+5*25). So to get the real number we would have to multiply
+ * the coefficients with the corresponding powers of 2. To get an idea what is going on below,
+ * look at the calculation of h0: h0 is the coefficient to the power 2^0 so it collects (sums)
+ * all products that have the power 2^0. f0 * g0 really is f0 * 2^0 * g0 * 2^0 = (f0 * g0) *
+ * 2^0. f1 * g9 really is f1 * 2^26 * g9 * 2^230 = f1 * g9 * 2^256 = 2 * f1 * g9 * 2^255
+ * congruent 2 * 19 * f1 * g9 * 2^0 modulo p. f2 * g8 really is f2 * 2^51 * g8 * 2^204 = f2 * g8
+ * * 2^255 congruent 19 * f2 * g8 * 2^0 modulo p. and so on...
+ */
long h0 =
f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 + f6g4_19 + f7g3_38 + f8g2_19
+ f9g1_38;
@@ -501,6 +510,11 @@ public FieldElement square() {
long f8f9_38 = f8 * (long) f9_38;
long f9f9_38 = f9 * (long) f9_38;
+ /**
+ * Same procedure as in multiply, but this time we have a higher symmetry leading to less
+ * summands. e.g. f1f9_76 really stands for f1 * 2^26 * f9 * 2^230 + f9 * 2^230 + f1 * 2^26
+ * congruent 2 * 2 * 19 * f1 * f9 2^0 modulo p.
+ */
long h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38;
long h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38;
long h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519LittleEndianEncoding.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519LittleEndianEncoding.java
index 7c171690d..61885e112 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519LittleEndianEncoding.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519LittleEndianEncoding.java
@@ -1,7 +1,6 @@
package org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.ed25519;
-import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.Encoding;
-import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.FieldElement;
+import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.*;
/**
* Helper class for encoding/decoding from/to the 32 byte representation.
@@ -9,6 +8,21 @@
* Reviewed/commented by Bloody Rookie (nemproject@gmx.de)
*/
public class Ed25519LittleEndianEncoding extends Encoding {
+ static int load_3(byte[] in, int offset) {
+ int result = in[offset++] & 0xff;
+ result |= (in[offset++] & 0xff) << 8;
+ result |= (in[offset] & 0xff) << 16;
+ return result;
+ }
+
+ static long load_4(byte[] in, int offset) {
+ int result = in[offset++] & 0xff;
+ result |= (in[offset++] & 0xff) << 8;
+ result |= (in[offset++] & 0xff) << 16;
+ result |= in[offset] << 24;
+ return ((long) result) & 0xffffffffL;
+ }
+
/**
* Encodes a given field element in its 32 byte representation. This is done in two steps:
*
@@ -19,6 +33,8 @@ public class Ed25519LittleEndianEncoding extends Encoding {
*
*
The idea for the modulo $p$ reduction algorithm is as follows:
*
+ *
Assumption:
+ *
*
* $p = 2^{255} - 19$
* $h = h_0 + 2^{25} * h_1 + 2^{(26+25)} * h_2 + \dots + 2^{230} * h_9$ where $0 \le |h_i|
@@ -29,7 +45,7 @@ public class Ed25519LittleEndianEncoding extends Encoding {
*
* Then $q = [2^{-255} * (h + 19 * 2^{-25} * h_9 + 1/2)]$ where $[x] = floor(x)$.
*
- *
Proof:
+ *
Proof:
*
* We begin with some very raw estimation for the bounds of some expressions:
*
@@ -167,21 +183,6 @@ public byte[] encode(FieldElement x) {
return s;
}
- static int load_3(byte[] in, int offset) {
- int result = in[offset++] & 0xff;
- result |= (in[offset++] & 0xff) << 8;
- result |= (in[offset] & 0xff) << 16;
- return result;
- }
-
- static long load_4(byte[] in, int offset) {
- int result = in[offset++] & 0xff;
- result |= (in[offset++] & 0xff) << 8;
- result |= (in[offset++] & 0xff) << 16;
- result |= in[offset] << 24;
- return ((long) result) & 0xffffffffL;
- }
-
/**
* Decodes a given field element in its 10 byte $2^{25.5}$ representation.
*
@@ -190,14 +191,14 @@ static long load_4(byte[] in, int offset) {
*/
public FieldElement decode(byte[] in) {
long h0 = load_4(in, 0);
- long h1 = load_3(in, 4) << 6;
- long h2 = load_3(in, 7) << 5;
- long h3 = load_3(in, 10) << 3;
- long h4 = load_3(in, 13) << 2;
+ long h1 = (long) load_3(in, 4) << 6;
+ long h2 = (long) load_3(in, 7) << 5;
+ long h3 = (long) load_3(in, 10) << 3;
+ long h4 = (long) load_3(in, 13) << 2;
long h5 = load_4(in, 16);
- long h6 = load_3(in, 20) << 7;
- long h7 = load_3(in, 23) << 5;
- long h8 = load_3(in, 26) << 4;
+ long h6 = (long) load_3(in, 20) << 7;
+ long h7 = (long) load_3(in, 23) << 5;
+ long h8 = (long) load_3(in, 26) << 4;
long h9 = (load_3(in, 29) & 0x7FFFFF) << 2;
long carry0;
long carry1;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519ScalarOps.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519ScalarOps.java
index 0f9a518f5..ca892394c 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519ScalarOps.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/math/ed25519/Ed25519ScalarOps.java
@@ -9,6 +9,9 @@
*/
package org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.ed25519;
+import static org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.ed25519.Ed25519LittleEndianEncoding.load_3;
+import static org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.ed25519.Ed25519LittleEndianEncoding.load_4;
+
import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.ScalarOps;
/**
@@ -31,30 +34,30 @@ public class Ed25519ScalarOps implements ScalarOps {
*/
public byte[] reduce(byte[] s) {
// s0,..., s22 have 21 bits, s23 has 29 bits
- long s0 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(s, 0);
- long s1 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 2) >> 5);
- long s2 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(s, 5) >> 2);
- long s3 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 7) >> 7);
- long s4 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 10) >> 4);
- long s5 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(s, 13) >> 1);
- long s6 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 15) >> 6);
- long s7 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(s, 18) >> 3);
- long s8 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(s, 21);
- long s9 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 23) >> 5);
- long s10 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(s, 26) >> 2);
- long s11 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 28) >> 7);
- long s12 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 31) >> 4);
- long s13 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(s, 34) >> 1);
- long s14 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 36) >> 6);
- long s15 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(s, 39) >> 3);
- long s16 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(s, 42);
- long s17 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 44) >> 5);
- long s18 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(s, 47) >> 2);
- long s19 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 49) >> 7);
- long s20 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 52) >> 4);
- long s21 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(s, 55) >> 1);
- long s22 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(s, 57) >> 6);
- long s23 = (Ed25519LittleEndianEncoding.load_4(s, 60) >> 3);
+ long s0 = 0x1FFFFF & load_3(s, 0);
+ long s1 = 0x1FFFFF & (load_4(s, 2) >> 5);
+ long s2 = 0x1FFFFF & (load_3(s, 5) >> 2);
+ long s3 = 0x1FFFFF & (load_4(s, 7) >> 7);
+ long s4 = 0x1FFFFF & (load_4(s, 10) >> 4);
+ long s5 = 0x1FFFFF & (load_3(s, 13) >> 1);
+ long s6 = 0x1FFFFF & (load_4(s, 15) >> 6);
+ long s7 = 0x1FFFFF & (load_3(s, 18) >> 3);
+ long s8 = 0x1FFFFF & load_3(s, 21);
+ long s9 = 0x1FFFFF & (load_4(s, 23) >> 5);
+ long s10 = 0x1FFFFF & (load_3(s, 26) >> 2);
+ long s11 = 0x1FFFFF & (load_4(s, 28) >> 7);
+ long s12 = 0x1FFFFF & (load_4(s, 31) >> 4);
+ long s13 = 0x1FFFFF & (load_3(s, 34) >> 1);
+ long s14 = 0x1FFFFF & (load_4(s, 36) >> 6);
+ long s15 = 0x1FFFFF & (load_3(s, 39) >> 3);
+ long s16 = 0x1FFFFF & load_3(s, 42);
+ long s17 = 0x1FFFFF & (load_4(s, 44) >> 5);
+ long s18 = 0x1FFFFF & (load_3(s, 47) >> 2);
+ long s19 = 0x1FFFFF & (load_4(s, 49) >> 7);
+ long s20 = 0x1FFFFF & (load_4(s, 52) >> 4);
+ long s21 = 0x1FFFFF & (load_3(s, 55) >> 1);
+ long s22 = 0x1FFFFF & (load_4(s, 57) >> 6);
+ long s23 = (load_4(s, 60) >> 3);
long carry0;
long carry1;
long carry2;
@@ -73,6 +76,21 @@ public byte[] reduce(byte[] s) {
long carry15;
long carry16;
+ /**
+ * Lots of magic numbers :) To understand what's going on below, note that
+ *
+ *
(1) q = 2^252 + q0 where q0 = 27742317777372353535851937790883648493. (2) s11 is the
+ * coefficient of 2^(11*21), s23 is the coefficient of 2^(^23*21) and 2^252 = 2^((23-11) * 21)).
+ * (3) 2^252 congruent -q0 modulo q. (4) -q0 = 666643 * 2^0 + 470296 * 2^21 + 654183 * 2^(2*21)
+ * - 997805 * 2^(3*21) + 136657 * 2^(4*21) - 683901 * 2^(5*21)
+ *
+ *
Thus s23 * 2^(23*11) = s23 * 2^(12*21) * 2^(11*21) = s3 * 2^252 * 2^(11*21) congruent s23
+ * * (666643 * 2^0 + 470296 * 2^21 + 654183 * 2^(2*21) - 997805 * 2^(3*21) + 136657 * 2^(4*21) -
+ * 683901 * 2^(5*21)) * 2^(11*21) modulo q = s23 * (666643 * 2^(11*21) + 470296 * 2^(12*21) +
+ * 654183 * 2^(13*21) - 997805 * 2^(14*21) + 136657 * 2^(15*21) - 683901 * 2^(16*21)).
+ *
+ *
The same procedure is then applied for s22,...,s18.
+ */
s11 += s23 * 666643;
s12 += s23 * 470296;
s13 += s23 * 654183;
@@ -127,6 +145,7 @@ public byte[] reduce(byte[] s) {
// not used again
// s18 = 0;
+ /** Time to reduce the coefficient in order not to get an overflow. */
carry6 = (s6 + (1 << 20)) >> 21;
s7 += carry6;
s6 -= carry6 << 21;
@@ -162,6 +181,7 @@ public byte[] reduce(byte[] s) {
s16 += carry15;
s15 -= carry15 << 21;
+ /** Continue with above procedure. */
s5 += s17 * 666643;
s6 += s17 * 470296;
s7 += s17 * 654183;
@@ -216,6 +236,7 @@ public byte[] reduce(byte[] s) {
// set below
// s12 = 0;
+ /** Reduce coefficients again. */
carry0 = (s0 + (1 << 20)) >> 21;
s1 += carry0;
s0 -= carry0 << 21;
@@ -400,42 +421,42 @@ public byte[] reduce(byte[] s) {
*
See the comments in {@link #reduce(byte[])} for an explanation of the algorithm.
*/
public byte[] multiplyAndAdd(byte[] a, byte[] b, byte[] c) {
- long a0 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(a, 0);
- long a1 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(a, 2) >> 5);
- long a2 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(a, 5) >> 2);
- long a3 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(a, 7) >> 7);
- long a4 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(a, 10) >> 4);
- long a5 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(a, 13) >> 1);
- long a6 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(a, 15) >> 6);
- long a7 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(a, 18) >> 3);
- long a8 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(a, 21);
- long a9 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(a, 23) >> 5);
- long a10 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(a, 26) >> 2);
- long a11 = (Ed25519LittleEndianEncoding.load_4(a, 28) >> 7);
- long b0 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(b, 0);
- long b1 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(b, 2) >> 5);
- long b2 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(b, 5) >> 2);
- long b3 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(b, 7) >> 7);
- long b4 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(b, 10) >> 4);
- long b5 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(b, 13) >> 1);
- long b6 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(b, 15) >> 6);
- long b7 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(b, 18) >> 3);
- long b8 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(b, 21);
- long b9 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(b, 23) >> 5);
- long b10 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(b, 26) >> 2);
- long b11 = (Ed25519LittleEndianEncoding.load_4(b, 28) >> 7);
- long c0 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(c, 0);
- long c1 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(c, 2) >> 5);
- long c2 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(c, 5) >> 2);
- long c3 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(c, 7) >> 7);
- long c4 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(c, 10) >> 4);
- long c5 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(c, 13) >> 1);
- long c6 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(c, 15) >> 6);
- long c7 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(c, 18) >> 3);
- long c8 = 0x1FFFFF & Ed25519LittleEndianEncoding.load_3(c, 21);
- long c9 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_4(c, 23) >> 5);
- long c10 = 0x1FFFFF & (Ed25519LittleEndianEncoding.load_3(c, 26) >> 2);
- long c11 = (Ed25519LittleEndianEncoding.load_4(c, 28) >> 7);
+ long a0 = 0x1FFFFF & load_3(a, 0);
+ long a1 = 0x1FFFFF & (load_4(a, 2) >> 5);
+ long a2 = 0x1FFFFF & (load_3(a, 5) >> 2);
+ long a3 = 0x1FFFFF & (load_4(a, 7) >> 7);
+ long a4 = 0x1FFFFF & (load_4(a, 10) >> 4);
+ long a5 = 0x1FFFFF & (load_3(a, 13) >> 1);
+ long a6 = 0x1FFFFF & (load_4(a, 15) >> 6);
+ long a7 = 0x1FFFFF & (load_3(a, 18) >> 3);
+ long a8 = 0x1FFFFF & load_3(a, 21);
+ long a9 = 0x1FFFFF & (load_4(a, 23) >> 5);
+ long a10 = 0x1FFFFF & (load_3(a, 26) >> 2);
+ long a11 = (load_4(a, 28) >> 7);
+ long b0 = 0x1FFFFF & load_3(b, 0);
+ long b1 = 0x1FFFFF & (load_4(b, 2) >> 5);
+ long b2 = 0x1FFFFF & (load_3(b, 5) >> 2);
+ long b3 = 0x1FFFFF & (load_4(b, 7) >> 7);
+ long b4 = 0x1FFFFF & (load_4(b, 10) >> 4);
+ long b5 = 0x1FFFFF & (load_3(b, 13) >> 1);
+ long b6 = 0x1FFFFF & (load_4(b, 15) >> 6);
+ long b7 = 0x1FFFFF & (load_3(b, 18) >> 3);
+ long b8 = 0x1FFFFF & load_3(b, 21);
+ long b9 = 0x1FFFFF & (load_4(b, 23) >> 5);
+ long b10 = 0x1FFFFF & (load_3(b, 26) >> 2);
+ long b11 = (load_4(b, 28) >> 7);
+ long c0 = 0x1FFFFF & load_3(c, 0);
+ long c1 = 0x1FFFFF & (load_4(c, 2) >> 5);
+ long c2 = 0x1FFFFF & (load_3(c, 5) >> 2);
+ long c3 = 0x1FFFFF & (load_4(c, 7) >> 7);
+ long c4 = 0x1FFFFF & (load_4(c, 10) >> 4);
+ long c5 = 0x1FFFFF & (load_3(c, 13) >> 1);
+ long c6 = 0x1FFFFF & (load_4(c, 15) >> 6);
+ long c7 = 0x1FFFFF & (load_3(c, 18) >> 3);
+ long c8 = 0x1FFFFF & load_3(c, 21);
+ long c9 = 0x1FFFFF & (load_4(c, 23) >> 5);
+ long c10 = 0x1FFFFF & (load_3(c, 26) >> 2);
+ long c11 = (load_4(c, 28) >> 7);
long s0;
long s1;
long s2;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/spec/EdDSANamedCurveTable.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/spec/EdDSANamedCurveTable.java
index f15c33858..209d9f96c 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/spec/EdDSANamedCurveTable.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/spec/EdDSANamedCurveTable.java
@@ -42,6 +42,11 @@ public class EdDSANamedCurveTable {
private static volatile HashMap curves = new HashMap<>();
+ static {
+ // RFC 8032
+ defineCurve(ED_25519_CURVE_SPEC);
+ }
+
private static synchronized void putCurve(String name, EdDSANamedCurveSpec curve) {
HashMap newCurves = new HashMap<>(curves);
newCurves.put(name, curve);
@@ -52,11 +57,6 @@ public static void defineCurve(EdDSANamedCurveSpec curve) {
putCurve(curve.getName().toLowerCase(Locale.ENGLISH), curve);
}
- static {
- // RFC 8032
- defineCurve(ED_25519_CURVE_SPEC);
- }
-
public static EdDSANamedCurveSpec getByName(String name) {
return curves.get(name.toLowerCase(Locale.ENGLISH));
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/spec/EdDSAParameterSpec.java b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/spec/EdDSAParameterSpec.java
index 30dfe3440..e81547f11 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/spec/EdDSAParameterSpec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/authentication/standard/ed25519/spec/EdDSAParameterSpec.java
@@ -22,6 +22,7 @@
*
* @author str4d
*/
+@SuppressWarnings("all")
public class EdDSAParameterSpec implements AlgorithmParameterSpec, Serializable {
private static final long serialVersionUID = 8274987108472012L;
private final Curve curve;
@@ -60,7 +61,13 @@ public String getHashAlgorithm() {
return hashAlgo;
}
- /** @return the base (generator) */
+ public ScalarOps getScalarOps() {
+ return sc;
+ }
+
+ /**
+ * @return the base (generator)
+ */
public GroupElement getB() {
return B;
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java
index 01d1fda09..bc475c644 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
@@ -43,6 +42,21 @@ public class BigDecimalCodec implements Codec {
DataType.MEDIUMBLOB,
DataType.LONGBLOB);
+ static BigInteger getBigInteger(ReadableByteBuf buf, ColumnDecoder column) {
+ BigInteger val;
+ if (column.isSigned()) {
+ val = BigInteger.valueOf(buf.readLong());
+ } else {
+ // need BIG ENDIAN, so reverse order
+ byte[] bb = new byte[8];
+ for (int i = 7; i >= 0; i--) {
+ bb[i] = buf.readByte();
+ }
+ val = new BigInteger(1, bb);
+ }
+ return val;
+ }
+
public String className() {
return BigDecimal.class.getName();
}
@@ -196,21 +210,6 @@ public BigDecimal decodeBinary(
}
}
- static BigInteger getBigInteger(ReadableByteBuf buf, ColumnDecoder column) {
- BigInteger val;
- if (column.isSigned()) {
- val = BigInteger.valueOf(buf.readLong());
- } else {
- // need BIG ENDIAN, so reverse order
- byte[] bb = new byte[8];
- for (int i = 7; i >= 0; i--) {
- bb[i] = buf.readByte();
- }
- val = new BigInteger(1, bb);
- }
- return val;
- }
-
@Override
public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long length)
throws IOException {
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java
index fa07f8300..597f33442 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java
index 45855bc5b..b47432b2a 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java
index 3f3107401..852b51dd7 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.ByteArrayOutputStream;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java
index 9f1eca923..ffe6cf924 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java
index fc9dda8f3..070d98cfa 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java
index e2a1cbbc1..befec5b10 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java
index 718abab61..a4f5f6036 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.ByteArrayOutputStream;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java
index f9dceeb55..b8635a22f 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
@@ -80,14 +79,23 @@ public void encodeText(
@Override
public void encodeBinary(Writer encoder, Object value, Calendar providedCal, Long maxLength)
throws IOException {
- Calendar cal = providedCal == null ? Calendar.getInstance() : providedCal;
- synchronized (cal) {
+ if (providedCal == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.setTimeInMillis(((java.util.Date) value).getTime());
encoder.writeByte(4); // length
encoder.writeShort((short) cal.get(Calendar.YEAR));
encoder.writeByte(((cal.get(Calendar.MONTH) + 1) & 0xff));
encoder.writeByte((cal.get(Calendar.DAY_OF_MONTH) & 0xff));
+ } else {
+ synchronized (providedCal) {
+ providedCal.clear();
+ providedCal.setTimeInMillis(((java.util.Date) value).getTime());
+ encoder.writeByte(4); // length
+ encoder.writeShort((short) providedCal.get(Calendar.YEAR));
+ encoder.writeByte(((providedCal.get(Calendar.MONTH) + 1) & 0xff));
+ encoder.writeByte((providedCal.get(Calendar.DAY_OF_MONTH) & 0xff));
+ }
}
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java
index 58fb773dd..d5cca4411 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java
index 5460d0929..b4a23fd18 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java
index 3976a8172..478845649 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java
index ecec9d2cf..ff0c7d21e 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/InstantCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/InstantCodec.java
index cb422f7c1..40acfb46a 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/InstantCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/InstantCodec.java
@@ -1,13 +1,11 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.time.*;
-import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.EnumSet;
import org.mariadb.jdbc.client.*;
@@ -105,21 +103,21 @@ public void encodeBinary(Writer encoder, Object value, Calendar calParam, Long m
int nano = zonedDateTime.getNano();
if (nano > 0) {
encoder.writeByte((byte) 11);
- encoder.writeShort((short) zonedDateTime.get(ChronoField.YEAR));
- encoder.writeByte(zonedDateTime.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(zonedDateTime.get(ChronoField.DAY_OF_MONTH));
- encoder.writeByte(zonedDateTime.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte(zonedDateTime.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte(zonedDateTime.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeShort((short) zonedDateTime.getYear());
+ encoder.writeByte(zonedDateTime.getMonth().getValue());
+ encoder.writeByte(zonedDateTime.getDayOfMonth());
+ encoder.writeByte(zonedDateTime.getHour());
+ encoder.writeByte(zonedDateTime.getMinute());
+ encoder.writeByte(zonedDateTime.getSecond());
encoder.writeInt(nano / 1000);
} else {
encoder.writeByte((byte) 7);
- encoder.writeShort((short) zonedDateTime.get(ChronoField.YEAR));
- encoder.writeByte(zonedDateTime.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(zonedDateTime.get(ChronoField.DAY_OF_MONTH));
- encoder.writeByte(zonedDateTime.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte(zonedDateTime.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte(zonedDateTime.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeShort((short) zonedDateTime.getYear());
+ encoder.writeByte(zonedDateTime.getMonthValue());
+ encoder.writeByte(zonedDateTime.getDayOfMonth());
+ encoder.writeByte(zonedDateTime.getHour());
+ encoder.writeByte(zonedDateTime.getMinute());
+ encoder.writeByte(zonedDateTime.getSecond());
}
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java
index bb5ab8358..0b39cdc77 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java
index 4a942c830..106bd7609 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java
index 55c6ab154..1647af1f9 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
@@ -10,7 +9,6 @@
import java.sql.SQLDataException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.EnumSet;
import org.mariadb.jdbc.client.*;
@@ -276,9 +274,9 @@ public void encodeBinary(Writer encoder, Object value, Calendar providedCal, Lon
throws IOException {
LocalDate val = (LocalDate) value;
encoder.writeByte(7); // length
- encoder.writeShort((short) val.get(ChronoField.YEAR));
- encoder.writeByte(val.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(val.get(ChronoField.DAY_OF_MONTH));
+ encoder.writeShort((short) val.getYear());
+ encoder.writeByte(val.getMonthValue());
+ encoder.writeByte(val.getDayOfMonth());
encoder.writeBytes(new byte[] {0, 0, 0});
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java
index b1d1057b9..64bd62e80 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
@@ -12,7 +11,6 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
-import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.EnumSet;
import org.mariadb.jdbc.client.*;
@@ -330,21 +328,21 @@ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLen
int nano = val.getNano();
if (nano > 0) {
encoder.writeByte((byte) 11);
- encoder.writeShort((short) val.get(ChronoField.YEAR));
- encoder.writeByte(val.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(val.get(ChronoField.DAY_OF_MONTH));
- encoder.writeByte(val.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte(val.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte(val.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeShort((short) val.getYear());
+ encoder.writeByte(val.getMonthValue());
+ encoder.writeByte(val.getDayOfMonth());
+ encoder.writeByte(val.getHour());
+ encoder.writeByte(val.getMinute());
+ encoder.writeByte(val.getSecond());
encoder.writeInt(nano / 1000);
} else {
encoder.writeByte((byte) 7);
- encoder.writeShort((short) val.get(ChronoField.YEAR));
- encoder.writeByte(val.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(val.get(ChronoField.DAY_OF_MONTH));
- encoder.writeByte(val.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte(val.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte(val.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeShort((short) val.getYear());
+ encoder.writeByte(val.getMonthValue());
+ encoder.writeByte(val.getDayOfMonth());
+ encoder.writeByte(val.getHour());
+ encoder.writeByte(val.getMinute());
+ encoder.writeByte(val.getSecond());
}
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java
index 03e37bf08..be68219b2 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import static org.mariadb.jdbc.client.result.Result.NULL_LENGTH;
@@ -12,7 +11,6 @@
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeParseException;
-import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.EnumSet;
import java.util.TimeZone;
@@ -316,17 +314,17 @@ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLen
encoder.writeByte((byte) 12);
encoder.writeByte((byte) 0);
encoder.writeInt(0);
- encoder.writeByte((byte) val.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte((byte) val.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte((byte) val.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeByte((byte) val.getHour());
+ encoder.writeByte((byte) val.getMinute());
+ encoder.writeByte((byte) val.getSecond());
encoder.writeInt(nano / 1000);
} else {
encoder.writeByte((byte) 8);
encoder.writeByte((byte) 0);
encoder.writeInt(0);
- encoder.writeByte((byte) val.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte((byte) val.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte((byte) val.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeByte((byte) val.getHour());
+ encoder.writeByte((byte) val.getMinute());
+ encoder.writeByte((byte) val.getSecond());
}
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java
index 9199baa7e..db44913b3 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java
index ad23a9210..cf403ba95 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java
index 9fe876fe2..7d2cb6e51 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java
index 220ed2861..8aae116bd 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/OffsetDateTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/OffsetDateTimeCodec.java
index 79f454a1f..94e0b5738 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/OffsetDateTimeCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/OffsetDateTimeCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
@@ -9,7 +8,6 @@
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZonedDateTime;
-import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.EnumSet;
import org.mariadb.jdbc.client.*;
@@ -143,21 +141,21 @@ public void encodeBinary(Writer encoder, Object value, Calendar calParam, Long m
int nano = convertedZdt.getNano();
if (nano > 0) {
encoder.writeByte((byte) 11);
- encoder.writeShort((short) convertedZdt.get(ChronoField.YEAR));
- encoder.writeByte(convertedZdt.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(convertedZdt.get(ChronoField.DAY_OF_MONTH));
- encoder.writeByte(convertedZdt.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte(convertedZdt.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte(convertedZdt.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeShort((short) convertedZdt.getYear());
+ encoder.writeByte(convertedZdt.getMonthValue());
+ encoder.writeByte(convertedZdt.getDayOfMonth());
+ encoder.writeByte(convertedZdt.getHour());
+ encoder.writeByte(convertedZdt.getMinute());
+ encoder.writeByte(convertedZdt.getSecond());
encoder.writeInt(nano / 1000);
} else {
encoder.writeByte((byte) 7);
- encoder.writeShort((short) convertedZdt.get(ChronoField.YEAR));
- encoder.writeByte(convertedZdt.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(convertedZdt.get(ChronoField.DAY_OF_MONTH));
- encoder.writeByte(convertedZdt.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte(convertedZdt.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte(convertedZdt.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeShort((short) convertedZdt.getYear());
+ encoder.writeByte(convertedZdt.getMonthValue());
+ encoder.writeByte(convertedZdt.getDayOfMonth());
+ encoder.writeByte(convertedZdt.getHour());
+ encoder.writeByte(convertedZdt.getMinute());
+ encoder.writeByte(convertedZdt.getSecond());
}
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java
index d356c8120..734d9da1d 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java
index fac094439..76ce76b4c 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java
index 38d5d8e1a..9b2ea70db 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.*;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java
index 217096557..323bf5050 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java
index 829e4d4c0..b056cab08 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.*;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java
index b42d34e01..fa6f00019 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java
index 4d4ebf199..78a72077c 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
@@ -21,6 +20,7 @@ public class TimeCodec implements Codec {
/** default instance */
public static final TimeCodec INSTANCE = new TimeCodec();
+
/** reference local date */
public static final LocalDate EPOCH_DATE = LocalDate.of(1970, 1, 1);
@@ -83,8 +83,8 @@ public void encodeText(
@Override
public void encodeBinary(Writer encoder, Object value, Calendar providedCal, Long maxLength)
throws IOException {
- Calendar cal = providedCal == null ? Calendar.getInstance() : providedCal;
- synchronized (cal) {
+ if (providedCal == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.setTime((Time) value);
cal.set(Calendar.DAY_OF_MONTH, 1);
@@ -104,6 +104,28 @@ public void encodeBinary(Writer encoder, Object value, Calendar providedCal, Lon
encoder.writeByte((byte) cal.get(Calendar.MINUTE));
encoder.writeByte((byte) cal.get(Calendar.SECOND));
}
+ } else {
+ synchronized (providedCal) {
+ providedCal.clear();
+ providedCal.setTime((Time) value);
+ providedCal.set(Calendar.DAY_OF_MONTH, 1);
+ if (providedCal.get(Calendar.MILLISECOND) > 0) {
+ encoder.writeByte((byte) 12);
+ encoder.writeByte((byte) 0);
+ encoder.writeInt(0);
+ encoder.writeByte((byte) providedCal.get(Calendar.HOUR_OF_DAY));
+ encoder.writeByte((byte) providedCal.get(Calendar.MINUTE));
+ encoder.writeByte((byte) providedCal.get(Calendar.SECOND));
+ encoder.writeInt(providedCal.get(Calendar.MILLISECOND) * 1000);
+ } else {
+ encoder.writeByte((byte) 8); // length
+ encoder.writeByte((byte) 0);
+ encoder.writeInt(0);
+ encoder.writeByte((byte) providedCal.get(Calendar.HOUR_OF_DAY));
+ encoder.writeByte((byte) providedCal.get(Calendar.MINUTE));
+ encoder.writeByte((byte) providedCal.get(Calendar.SECOND));
+ }
+ }
}
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/TimestampCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/TimestampCodec.java
index 8c2b6cbdc..5446175e8 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/TimestampCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/TimestampCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
@@ -94,8 +93,8 @@ public void encodeText(
public void encodeBinary(Writer encoder, Object value, Calendar providedCal, Long maxLength)
throws IOException {
Timestamp ts = (Timestamp) value;
- Calendar cal = providedCal == null ? Calendar.getInstance() : providedCal;
- synchronized (cal) {
+ if (providedCal == null) {
+ Calendar cal = Calendar.getInstance();
cal.clear();
cal.setTimeInMillis(ts.getTime());
if (ts.getNanos() == 0) {
@@ -116,6 +115,29 @@ public void encodeBinary(Writer encoder, Object value, Calendar providedCal, Lon
encoder.writeByte(cal.get(Calendar.SECOND));
encoder.writeInt(ts.getNanos() / 1000);
}
+ } else {
+ synchronized (providedCal) {
+ providedCal.clear();
+ providedCal.setTimeInMillis(ts.getTime());
+ if (ts.getNanos() == 0) {
+ encoder.writeByte(7); // length
+ encoder.writeShort((short) providedCal.get(Calendar.YEAR));
+ encoder.writeByte((providedCal.get(Calendar.MONTH) + 1));
+ encoder.writeByte(providedCal.get(Calendar.DAY_OF_MONTH));
+ encoder.writeByte(providedCal.get(Calendar.HOUR_OF_DAY));
+ encoder.writeByte(providedCal.get(Calendar.MINUTE));
+ encoder.writeByte(providedCal.get(Calendar.SECOND));
+ } else {
+ encoder.writeByte(11); // length
+ encoder.writeShort((short) providedCal.get(Calendar.YEAR));
+ encoder.writeByte((providedCal.get(Calendar.MONTH) + 1));
+ encoder.writeByte(providedCal.get(Calendar.DAY_OF_MONTH));
+ encoder.writeByte(providedCal.get(Calendar.HOUR_OF_DAY));
+ encoder.writeByte(providedCal.get(Calendar.MINUTE));
+ encoder.writeByte(providedCal.get(Calendar.SECOND));
+ encoder.writeInt(ts.getNanos() / 1000);
+ }
+ }
}
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/UuidCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/UuidCodec.java
index 16847e3c5..1223663d4 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/UuidCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/UuidCodec.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/codec/ZonedDateTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ZonedDateTimeCodec.java
index 77f11420d..e7d2ef99a 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/codec/ZonedDateTimeCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ZonedDateTimeCodec.java
@@ -1,14 +1,12 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
-import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.EnumSet;
import org.mariadb.jdbc.client.*;
@@ -97,21 +95,21 @@ public void encodeBinary(Writer encoder, Object value, Calendar calParam, Long m
int nano = convertedZdt.getNano();
if (nano > 0) {
encoder.writeByte((byte) 11);
- encoder.writeShort((short) convertedZdt.get(ChronoField.YEAR));
- encoder.writeByte(convertedZdt.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(convertedZdt.get(ChronoField.DAY_OF_MONTH));
- encoder.writeByte(convertedZdt.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte(convertedZdt.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte(convertedZdt.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeShort((short) convertedZdt.getYear());
+ encoder.writeByte(convertedZdt.getMonthValue());
+ encoder.writeByte(convertedZdt.getDayOfMonth());
+ encoder.writeByte(convertedZdt.getHour());
+ encoder.writeByte(convertedZdt.getMinute());
+ encoder.writeByte(convertedZdt.getSecond());
encoder.writeInt(nano / 1000);
} else {
encoder.writeByte((byte) 7);
- encoder.writeShort((short) convertedZdt.get(ChronoField.YEAR));
- encoder.writeByte(convertedZdt.get(ChronoField.MONTH_OF_YEAR));
- encoder.writeByte(convertedZdt.get(ChronoField.DAY_OF_MONTH));
- encoder.writeByte(convertedZdt.get(ChronoField.HOUR_OF_DAY));
- encoder.writeByte(convertedZdt.get(ChronoField.MINUTE_OF_HOUR));
- encoder.writeByte(convertedZdt.get(ChronoField.SECOND_OF_MINUTE));
+ encoder.writeShort((short) convertedZdt.getYear());
+ encoder.writeByte(convertedZdt.getMonthValue());
+ encoder.writeByte(convertedZdt.getDayOfMonth());
+ encoder.writeByte(convertedZdt.getHour());
+ encoder.writeByte(convertedZdt.getMinute());
+ encoder.writeByte(convertedZdt.getSecond());
}
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/CredentialPluginLoader.java b/src/main/java/org/mariadb/jdbc/plugin/credential/CredentialPluginLoader.java
index abf733587..ac2f61b5d 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/credential/CredentialPluginLoader.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/credential/CredentialPluginLoader.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.credential;
import java.sql.SQLException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsCredentialGenerator.java b/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsCredentialGenerator.java
index 3c5248ce0..cbac7aafe 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsCredentialGenerator.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsCredentialGenerator.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.credential.aws;
import java.util.Properties;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsIamCredentialPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsIamCredentialPlugin.java
index 1a7a9e86d..02f150e28 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsIamCredentialPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/credential/aws/AwsIamCredentialPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.credential.aws;
import static java.time.LocalDateTime.now;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/env/EnvCredentialPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/credential/env/EnvCredentialPlugin.java
index 46135245b..ace214a71 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/credential/env/EnvCredentialPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/credential/env/EnvCredentialPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.credential.env;
import org.mariadb.jdbc.Configuration;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/credential/system/PropertiesCredentialPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/credential/system/PropertiesCredentialPlugin.java
index 37180658d..9025c56c4 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/credential/system/PropertiesCredentialPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/credential/system/PropertiesCredentialPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.credential.system;
import org.mariadb.jdbc.Configuration;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java b/src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java
index d8a5cd7de..6b7054467 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/tls/TlsSocketPluginLoader.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.tls;
import java.sql.SQLException;
diff --git a/src/main/java/org/mariadb/jdbc/plugin/tls/main/DefaultTlsSocketPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/tls/main/DefaultTlsSocketPlugin.java
index c5f678c93..70ccbcaf9 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/tls/main/DefaultTlsSocketPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/tls/main/DefaultTlsSocketPlugin.java
@@ -1,12 +1,10 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.plugin.tls.main;
import java.io.*;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
import java.security.GeneralSecurityException;
import java.security.KeyManagementException;
import java.security.KeyStore;
@@ -45,11 +43,11 @@ private static KeyManager loadClientCerts(
char[] keyStorePasswordChars =
keyStorePassword == null
? null
- : (keyStorePassword == "") ? null : keyStorePassword.toCharArray();
+ : (keyStorePassword.equals("")) ? null : keyStorePassword.toCharArray();
char[] keyStoreChars =
(keyPassword == null)
? keyStorePasswordChars
- : (keyPassword == "") ? null : keyPassword.toCharArray();
+ : (keyPassword.equals("")) ? null : keyPassword.toCharArray();
KeyStore ks =
KeyStore.getInstance(storeType != null ? storeType : KeyStore.getDefaultType());
ks.load(inStream, keyStorePasswordChars);
@@ -63,12 +61,29 @@ private static KeyManager loadClientCerts(
private static InputStream loadFromUrl(String keyStoreUrl) throws FileNotFoundException {
try {
- return new URL(keyStoreUrl).openStream();
- } catch (IOException ioexception) {
+ return new URI(keyStoreUrl).toURL().openStream();
+ } catch (Exception exception) {
return new FileInputStream(keyStoreUrl);
}
}
+ private static InputStream getInputStreamFromPath(String path) throws IOException {
+ try {
+ return new URI(path).toURL().openStream();
+ } catch (Exception e) {
+ if (path.startsWith("-----")) {
+ return new ByteArrayInputStream(path.getBytes());
+ } else {
+ File f = new File(path);
+ if (f.exists() && !f.isDirectory()) {
+ return f.toURI().toURL().openStream();
+ }
+ throw new IOException(
+ String.format("File not found for option `serverSslCert` (value: '%s')", path), e);
+ }
+ }
+ }
+
@Override
public String type() {
return "DEFAULT";
@@ -177,23 +192,6 @@ public SSLSocketFactory getSocketFactory(Configuration conf, ExceptionFactory ex
}
}
- private static InputStream getInputStreamFromPath(String path) throws IOException {
- try {
- return new URL(path).openStream();
- } catch (MalformedURLException e) {
- if (path.startsWith("-----")) {
- return new ByteArrayInputStream(path.getBytes());
- } else {
- File f = new File(path);
- if (f.exists() && !f.isDirectory()) {
- return f.toURI().toURL().openStream();
- }
- }
- throw new IOException(
- String.format("Wrong value for option `serverSslCert` (value: '%s')", path), e);
- }
- }
-
@Override
public void verify(String host, SSLSession session, long serverThreadId) throws SSLException {
try {
diff --git a/src/main/java/org/mariadb/jdbc/pool/MariaDbInnerPoolConnection.java b/src/main/java/org/mariadb/jdbc/pool/MariaDbInnerPoolConnection.java
index 55639f073..dc0cf4afb 100644
--- a/src/main/java/org/mariadb/jdbc/pool/MariaDbInnerPoolConnection.java
+++ b/src/main/java/org/mariadb/jdbc/pool/MariaDbInnerPoolConnection.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.pool;
import java.util.concurrent.atomic.AtomicLong;
diff --git a/src/main/java/org/mariadb/jdbc/pool/Pool.java b/src/main/java/org/mariadb/jdbc/pool/Pool.java
index 0a03ca2cf..c88778220 100644
--- a/src/main/java/org/mariadb/jdbc/pool/Pool.java
+++ b/src/main/java/org/mariadb/jdbc/pool/Pool.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.pool;
import java.lang.management.ManagementFactory;
@@ -26,7 +25,6 @@
import org.mariadb.jdbc.util.log.Loggers;
/** MariaDB Pool */
-@SuppressWarnings({"unchecked"})
public class Pool implements AutoCloseable, PoolMBean {
private static final Logger logger = Loggers.getLogger(Pool.class);
@@ -57,6 +55,7 @@ public class Pool implements AutoCloseable, PoolMBean {
* @param poolIndex pool index to permit distinction of thread name
* @param poolExecutor pools common executor
*/
+ @SuppressWarnings({"this-escape"})
public Pool(Configuration conf, int poolIndex, ScheduledThreadPoolExecutor poolExecutor) {
this.conf = conf;
@@ -100,9 +99,10 @@ public Pool(Configuration conf, int poolIndex, ScheduledThreadPoolExecutor poolE
}
waitTimeout = 28800;
if (!idleConnections.isEmpty()) {
- Statement stmt = idleConnections.getFirst().getConnection().createStatement();
- ResultSet rs = stmt.executeQuery("SELECT @@wait_timeout");
- if (rs.next()) waitTimeout = rs.getInt(1);
+ try (Statement stmt = idleConnections.getFirst().getConnection().createStatement()) {
+ ResultSet rs = stmt.executeQuery("SELECT @@wait_timeout");
+ if (rs.next()) waitTimeout = rs.getInt(1);
+ }
}
} catch (SQLException sqle) {
logger.error("error initializing pool connection", sqle);
@@ -118,18 +118,17 @@ private void addConnectionRequest() {
// ensure to have one worker if was timeout
connectionAppender.prestartCoreThread();
- boolean unused =
- connectionAppenderQueue.offer(
- () -> {
- if ((totalConnection.get() < conf.minPoolSize() || pendingRequestNumber.get() > 0)
- && totalConnection.get() < conf.maxPoolSize()) {
- try {
- addConnection();
- } catch (SQLException sqle) {
- logger.error("error adding connection to pool", sqle);
- }
- }
- });
+ connectionAppenderQueue.offer(
+ () -> {
+ if ((totalConnection.get() < conf.minPoolSize() || pendingRequestNumber.get() > 0)
+ && totalConnection.get() < conf.maxPoolSize()) {
+ try {
+ addConnection();
+ } catch (SQLException sqle) {
+ logger.error("error adding connection to pool", sqle);
+ }
+ }
+ });
}
}
@@ -216,7 +215,8 @@ public void connectionClosed(ConnectionEvent event) {
totalConnection.decrementAndGet();
silentCloseConnection(item.getConnection());
logger.debug(
- "connection {} removed from pool {} due to error during reset (total:{}, active:{}, pending:{})",
+ "connection {} removed from pool {} due to error during reset (total:{},"
+ + " active:{}, pending:{})",
item.getConnection().getThreadId(),
poolTag,
totalConnection.get(),
@@ -239,7 +239,7 @@ public void connectionErrorOccurred(ConnectionEvent event) {
MariaDbInnerPoolConnection item = ((MariaDbInnerPoolConnection) event.getSource());
totalConnection.decrementAndGet();
- boolean unused = idleConnections.remove(item);
+ idleConnections.remove(item);
// ensure that other connection will be validated before being use
// since one connection failed, better to assume the other might as well
@@ -248,7 +248,8 @@ public void connectionErrorOccurred(ConnectionEvent event) {
silentCloseConnection(item.getConnection());
addConnectionRequest();
logger.debug(
- "connection {} removed from pool {} due to having throw a Connection exception (total:{}, active:{}, pending:{})",
+ "connection {} removed from pool {} due to having throw a Connection exception"
+ + " (total:{}, active:{}, pending:{})",
item.getConnection().getThreadId(),
poolTag,
totalConnection.get(),
@@ -316,7 +317,8 @@ private MariaDbInnerPoolConnection getIdleConnection(long timeout, TimeUnit time
addConnectionRequest();
if (logger.isDebugEnabled()) {
logger.debug(
- "pool {} connection {} removed from pool due to failed validation (total:{}, active:{}, pending:{})",
+ "pool {} connection {} removed from pool due to failed validation (total:{},"
+ + " active:{}, pending:{})",
poolTag,
item.getConnection().getThreadId(),
totalConnection.get(),
@@ -442,7 +444,7 @@ public void close() {
connectionAppender.shutdown();
try {
- boolean unused = connectionAppender.awaitTermination(10, TimeUnit.SECONDS);
+ connectionAppender.awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException i) {
// eat
}
@@ -486,7 +488,7 @@ public void close() {
} catch (Exception exception) {
// eat
}
- boolean unused = connectionRemover.awaitTermination(10, TimeUnit.SECONDS);
+ connectionRemover.awaitTermination(10, TimeUnit.SECONDS);
}
} catch (Exception e) {
// eat
diff --git a/src/main/java/org/mariadb/jdbc/pool/PoolMBean.java b/src/main/java/org/mariadb/jdbc/pool/PoolMBean.java
index ede26387b..3ebbda940 100644
--- a/src/main/java/org/mariadb/jdbc/pool/PoolMBean.java
+++ b/src/main/java/org/mariadb/jdbc/pool/PoolMBean.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.pool;
/** JMX pool bean */
diff --git a/src/main/java/org/mariadb/jdbc/pool/PoolThreadFactory.java b/src/main/java/org/mariadb/jdbc/pool/PoolThreadFactory.java
index b75b5bee0..10c61b01c 100644
--- a/src/main/java/org/mariadb/jdbc/pool/PoolThreadFactory.java
+++ b/src/main/java/org/mariadb/jdbc/pool/PoolThreadFactory.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.pool;
import java.util.concurrent.Executors;
diff --git a/src/main/java/org/mariadb/jdbc/pool/Pools.java b/src/main/java/org/mariadb/jdbc/pool/Pools.java
index f27cb063a..d728602eb 100644
--- a/src/main/java/org/mariadb/jdbc/pool/Pools.java
+++ b/src/main/java/org/mariadb/jdbc/pool/Pools.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.pool;
import java.util.Map;
diff --git a/src/main/java/org/mariadb/jdbc/type/Geometry.java b/src/main/java/org/mariadb/jdbc/type/Geometry.java
index b2fd20937..83b4f7f7b 100644
--- a/src/main/java/org/mariadb/jdbc/type/Geometry.java
+++ b/src/main/java/org/mariadb/jdbc/type/Geometry.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.type;
import java.sql.SQLDataException;
diff --git a/src/main/java/org/mariadb/jdbc/type/GeometryCollection.java b/src/main/java/org/mariadb/jdbc/type/GeometryCollection.java
index 18ea83ce1..db60a9f28 100644
--- a/src/main/java/org/mariadb/jdbc/type/GeometryCollection.java
+++ b/src/main/java/org/mariadb/jdbc/type/GeometryCollection.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.type;
import java.util.Arrays;
diff --git a/src/main/java/org/mariadb/jdbc/type/LineString.java b/src/main/java/org/mariadb/jdbc/type/LineString.java
index bac4bfee9..e1db7bd63 100644
--- a/src/main/java/org/mariadb/jdbc/type/LineString.java
+++ b/src/main/java/org/mariadb/jdbc/type/LineString.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.type;
import java.util.Arrays;
diff --git a/src/main/java/org/mariadb/jdbc/type/MultiLineString.java b/src/main/java/org/mariadb/jdbc/type/MultiLineString.java
index c06fd7b09..5302bbdd9 100644
--- a/src/main/java/org/mariadb/jdbc/type/MultiLineString.java
+++ b/src/main/java/org/mariadb/jdbc/type/MultiLineString.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.type;
import java.util.Arrays;
diff --git a/src/main/java/org/mariadb/jdbc/type/MultiPoint.java b/src/main/java/org/mariadb/jdbc/type/MultiPoint.java
index 29736b804..9e9cc9404 100644
--- a/src/main/java/org/mariadb/jdbc/type/MultiPoint.java
+++ b/src/main/java/org/mariadb/jdbc/type/MultiPoint.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.type;
import java.util.Arrays;
diff --git a/src/main/java/org/mariadb/jdbc/type/MultiPolygon.java b/src/main/java/org/mariadb/jdbc/type/MultiPolygon.java
index d90a1948c..782ed8f55 100644
--- a/src/main/java/org/mariadb/jdbc/type/MultiPolygon.java
+++ b/src/main/java/org/mariadb/jdbc/type/MultiPolygon.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.type;
import java.util.Arrays;
diff --git a/src/main/java/org/mariadb/jdbc/type/Point.java b/src/main/java/org/mariadb/jdbc/type/Point.java
index a84db24ff..2c3830ed8 100644
--- a/src/main/java/org/mariadb/jdbc/type/Point.java
+++ b/src/main/java/org/mariadb/jdbc/type/Point.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.type;
import java.util.Objects;
diff --git a/src/main/java/org/mariadb/jdbc/type/Polygon.java b/src/main/java/org/mariadb/jdbc/type/Polygon.java
index 5e82fbc92..92a9d87aa 100644
--- a/src/main/java/org/mariadb/jdbc/type/Polygon.java
+++ b/src/main/java/org/mariadb/jdbc/type/Polygon.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.type;
import java.util.Arrays;
diff --git a/src/main/java/org/mariadb/jdbc/util/CharsetEncodingLength.java b/src/main/java/org/mariadb/jdbc/util/CharsetEncodingLength.java
index c77e28926..309cab435 100644
--- a/src/main/java/org/mariadb/jdbc/util/CharsetEncodingLength.java
+++ b/src/main/java/org/mariadb/jdbc/util/CharsetEncodingLength.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
import java.util.HashMap;
diff --git a/src/main/java/org/mariadb/jdbc/util/ClientParser.java b/src/main/java/org/mariadb/jdbc/util/ClientParser.java
index 148fc0c36..124a22d58 100644
--- a/src/main/java/org/mariadb/jdbc/util/ClientParser.java
+++ b/src/main/java/org/mariadb/jdbc/util/ClientParser.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
import java.nio.charset.StandardCharsets;
@@ -12,8 +11,8 @@ public final class ClientParser implements PrepareResult {
private final String sql;
private final byte[] query;
- private List paramPositions;
- private int paramCount;
+ private final List paramPositions;
+ private final int paramCount;
private ClientParser(String sql, byte[] query, List paramPositions) {
this.sql = sql;
diff --git a/src/main/java/org/mariadb/jdbc/util/ConfigurableSocketFactory.java b/src/main/java/org/mariadb/jdbc/util/ConfigurableSocketFactory.java
index f2475cb9b..3a57a4e06 100644
--- a/src/main/java/org/mariadb/jdbc/util/ConfigurableSocketFactory.java
+++ b/src/main/java/org/mariadb/jdbc/util/ConfigurableSocketFactory.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
import javax.net.SocketFactory;
diff --git a/src/main/java/org/mariadb/jdbc/util/NativeSql.java b/src/main/java/org/mariadb/jdbc/util/NativeSql.java
index 4e5075b5a..47168391c 100644
--- a/src/main/java/org/mariadb/jdbc/util/NativeSql.java
+++ b/src/main/java/org/mariadb/jdbc/util/NativeSql.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
import java.sql.SQLException;
diff --git a/src/main/java/org/mariadb/jdbc/util/ParameterList.java b/src/main/java/org/mariadb/jdbc/util/ParameterList.java
index 950ab6650..98c7a1da8 100644
--- a/src/main/java/org/mariadb/jdbc/util/ParameterList.java
+++ b/src/main/java/org/mariadb/jdbc/util/ParameterList.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
import java.util.Arrays;
diff --git a/src/main/java/org/mariadb/jdbc/util/PrepareResult.java b/src/main/java/org/mariadb/jdbc/util/PrepareResult.java
index 21740f45c..9a416f172 100644
--- a/src/main/java/org/mariadb/jdbc/util/PrepareResult.java
+++ b/src/main/java/org/mariadb/jdbc/util/PrepareResult.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
public interface PrepareResult {
diff --git a/src/main/java/org/mariadb/jdbc/util/Security.java b/src/main/java/org/mariadb/jdbc/util/Security.java
index 6ec0c4def..008433058 100644
--- a/src/main/java/org/mariadb/jdbc/util/Security.java
+++ b/src/main/java/org/mariadb/jdbc/util/Security.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
public final class Security {
diff --git a/src/main/java/org/mariadb/jdbc/util/StringUtils.java b/src/main/java/org/mariadb/jdbc/util/StringUtils.java
index d4205684b..022c7f3ef 100644
--- a/src/main/java/org/mariadb/jdbc/util/StringUtils.java
+++ b/src/main/java/org/mariadb/jdbc/util/StringUtils.java
@@ -1,3 +1,6 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2023 MariaDB Corporation Ab
package org.mariadb.jdbc.util;
public final class StringUtils {
diff --git a/src/main/java/org/mariadb/jdbc/util/ThreadUtils.java b/src/main/java/org/mariadb/jdbc/util/ThreadUtils.java
new file mode 100644
index 000000000..3f54bc793
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/util/ThreadUtils.java
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2023 MariaDB Corporation Ab
+package org.mariadb.jdbc.util;
+
+import java.util.concurrent.Callable;
+import javax.security.auth.Subject;
+
+public class ThreadUtils {
+ public static long getId(Thread thread) {
+ // must be return thread.threadId() for java 19+,
+ // but since we support java 8, cannot be removed for now
+ return thread.getId();
+ }
+
+ public static void callAs(
+ final Subject subject, final Callable> action)
+ throws Exception {
+ Subject.doAs(subject, action.call());
+ // must be for java 18+, but since we support java 8, cannot be removed for now
+ // Subject.callAs(subject, action);
+ }
+}
diff --git a/src/main/java/org/mariadb/jdbc/util/Version.java b/src/main/java/org/mariadb/jdbc/util/Version.java
index c07306060..a5ef4298e 100644
--- a/src/main/java/org/mariadb/jdbc/util/Version.java
+++ b/src/main/java/org/mariadb/jdbc/util/Version.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
public class Version {
diff --git a/src/main/java/org/mariadb/jdbc/util/VersionFactory.java b/src/main/java/org/mariadb/jdbc/util/VersionFactory.java
index 94133e849..4990c051c 100644
--- a/src/main/java/org/mariadb/jdbc/util/VersionFactory.java
+++ b/src/main/java/org/mariadb/jdbc/util/VersionFactory.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/util/constants/Capabilities.java b/src/main/java/org/mariadb/jdbc/util/constants/Capabilities.java
index fc165c86c..08caeaa38 100644
--- a/src/main/java/org/mariadb/jdbc/util/constants/Capabilities.java
+++ b/src/main/java/org/mariadb/jdbc/util/constants/Capabilities.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.constants;
/** Client / Server capabilities */
diff --git a/src/main/java/org/mariadb/jdbc/util/constants/CatalogTerm.java b/src/main/java/org/mariadb/jdbc/util/constants/CatalogTerm.java
index 2faa37db9..3b8da274c 100644
--- a/src/main/java/org/mariadb/jdbc/util/constants/CatalogTerm.java
+++ b/src/main/java/org/mariadb/jdbc/util/constants/CatalogTerm.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.constants;
public enum CatalogTerm {
diff --git a/src/main/java/org/mariadb/jdbc/util/constants/ColumnFlags.java b/src/main/java/org/mariadb/jdbc/util/constants/ColumnFlags.java
index 274efb456..7a11904cf 100644
--- a/src/main/java/org/mariadb/jdbc/util/constants/ColumnFlags.java
+++ b/src/main/java/org/mariadb/jdbc/util/constants/ColumnFlags.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.constants;
/** Column flag see https://mariadb.com/kb/en/result-set-packets/#field-details-flag */
diff --git a/src/main/java/org/mariadb/jdbc/util/constants/ConnectionState.java b/src/main/java/org/mariadb/jdbc/util/constants/ConnectionState.java
index e58936c95..b4f0f962e 100644
--- a/src/main/java/org/mariadb/jdbc/util/constants/ConnectionState.java
+++ b/src/main/java/org/mariadb/jdbc/util/constants/ConnectionState.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.constants;
/** Connection state change, to ensure what is needed to reset connection to a proper state */
diff --git a/src/main/java/org/mariadb/jdbc/util/constants/ServerStatus.java b/src/main/java/org/mariadb/jdbc/util/constants/ServerStatus.java
index f2cfbeca5..7a380ed52 100644
--- a/src/main/java/org/mariadb/jdbc/util/constants/ServerStatus.java
+++ b/src/main/java/org/mariadb/jdbc/util/constants/ServerStatus.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.constants;
/** Server status flags */
@@ -9,28 +8,40 @@
public class ServerStatus {
/** is in transaction */
public static final short IN_TRANSACTION = 1;
+
/** autocommit */
public static final short AUTOCOMMIT = 2;
+
/** more result exists (packet follows) */
public static final short MORE_RESULTS_EXISTS = 8;
+
/** no good index was used */
public static final short QUERY_NO_GOOD_INDEX_USED = 16;
+
/** no index was used */
public static final short QUERY_NO_INDEX_USED = 32;
+
/** cursor exists */
public static final short CURSOR_EXISTS = 64;
+
/** last row sent */
public static final short LAST_ROW_SENT = 128;
+
/** database dropped */
public static final short DB_DROPPED = 256;
+
/** escape type */
public static final short NO_BACKSLASH_ESCAPES = 512;
+
/** metadata changed */
public static final short METADATA_CHANGED = 1024;
+
/** query was slow */
public static final short QUERY_WAS_SLOW = 2048;
+
/** resultset contains output parameters */
public static final short PS_OUT_PARAMETERS = 4096;
+
/** session state change (OK_Packet contains additional data) */
public static final short SERVER_SESSION_STATE_CHANGED = 1 << 14;
}
diff --git a/src/main/java/org/mariadb/jdbc/util/constants/StateChange.java b/src/main/java/org/mariadb/jdbc/util/constants/StateChange.java
index 040fc637f..abde531ad 100644
--- a/src/main/java/org/mariadb/jdbc/util/constants/StateChange.java
+++ b/src/main/java/org/mariadb/jdbc/util/constants/StateChange.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.constants;
/** OK_PACKET state change flags */
@@ -9,14 +8,19 @@
public final class StateChange {
/** system variable change */
public static final short SESSION_TRACK_SYSTEM_VARIABLES = 0;
+
/** schema change */
public static final short SESSION_TRACK_SCHEMA = 1;
+
/** state change */
public static final short SESSION_TRACK_STATE_CHANGE = 2;
+
/** GTID change */
public static final short SESSION_TRACK_GTIDS = 3;
+
/** transaction characteristics change */
public static final short SESSION_TRACK_TRANSACTION_CHARACTERISTICS = 4;
+
/** transaction state change */
public static final short SESSION_TRACK_TRANSACTION_STATE = 5;
}
diff --git a/src/main/java/org/mariadb/jdbc/util/log/ConsoleLogger.java b/src/main/java/org/mariadb/jdbc/util/log/ConsoleLogger.java
index 8a3dd0456..4849725cb 100644
--- a/src/main/java/org/mariadb/jdbc/util/log/ConsoleLogger.java
+++ b/src/main/java/org/mariadb/jdbc/util/log/ConsoleLogger.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.log;
import java.io.PrintStream;
diff --git a/src/main/java/org/mariadb/jdbc/util/log/JdkLogger.java b/src/main/java/org/mariadb/jdbc/util/log/JdkLogger.java
index 66aa84bef..ae71b7d77 100644
--- a/src/main/java/org/mariadb/jdbc/util/log/JdkLogger.java
+++ b/src/main/java/org/mariadb/jdbc/util/log/JdkLogger.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.log;
import java.util.logging.Level;
diff --git a/src/main/java/org/mariadb/jdbc/util/log/Logger.java b/src/main/java/org/mariadb/jdbc/util/log/Logger.java
index b12309aeb..9bd7f766d 100644
--- a/src/main/java/org/mariadb/jdbc/util/log/Logger.java
+++ b/src/main/java/org/mariadb/jdbc/util/log/Logger.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.log;
/** Logger interface */
diff --git a/src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java b/src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java
index 5b68cb3e2..7ac4eb7c2 100644
--- a/src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java
+++ b/src/main/java/org/mariadb/jdbc/util/log/LoggerHelper.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.log;
/** Logger helper to display network exchange */
@@ -63,7 +62,8 @@ public static String hex(byte[] bytes, int offset, int dataLength, int trunkLeng
sb.append(
" +--------------------------------------------------+\n"
+ " | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"
- + "+------+--------------------------------------------------+------------------+\n|000000| ");
+ + "+------+--------------------------------------------------+------------------+\n"
+ + "|000000| ");
while (pos < logLength + offset) {
int byteValue = bytes[pos] & 0xFF;
@@ -111,9 +111,9 @@ public static String hex(byte[] bytes, int offset, int dataLength, int trunkLeng
}
private static String mediumIntTohexa(int value) {
- String st = Integer.toHexString(value * 16);
- while (st.length() < 6) st = "0" + st;
- return st;
+ StringBuilder st = new StringBuilder(Integer.toHexString(value * 16));
+ while (st.length() < 6) st.insert(0, "0");
+ return st.toString();
}
/**
diff --git a/src/main/java/org/mariadb/jdbc/util/log/Loggers.java b/src/main/java/org/mariadb/jdbc/util/log/Loggers.java
index 7001efb51..42e2e4c14 100644
--- a/src/main/java/org/mariadb/jdbc/util/log/Loggers.java
+++ b/src/main/java/org/mariadb/jdbc/util/log/Loggers.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.log;
import java.util.HashMap;
@@ -48,6 +47,39 @@ public static Logger getLogger(Class> cls) {
return LOGGER_FACTORY.getLogger(cls.getName());
}
+ /** Initialize factory */
+ public static void init() {
+ String name = LoggerFactory.class.getName();
+ LoggerFactory loggerFactory = null;
+ if (Boolean.parseBoolean(System.getProperty(NO_LOGGER_PROPERTY, "false"))) {
+ loggerFactory = new NoLoggerFactory();
+ } else {
+
+ try {
+ if (Boolean.parseBoolean(System.getProperty(TEST_ENABLE_SLF4J, "true"))) {
+ Class.forName("org.slf4j.LoggerFactory");
+ loggerFactory = new Slf4JLoggerFactory();
+ }
+ } catch (ClassNotFoundException cle) {
+ // slf4j not in the classpath
+ }
+ if (loggerFactory == null) {
+ // default to console or use JDK logger if explicitly set by System property
+ if ("JDK".equalsIgnoreCase(System.getProperty(FALLBACK_PROPERTY))) {
+ loggerFactory = new JdkLoggerFactory();
+ } else {
+ loggerFactory = new ConsoleLoggerFactory();
+ }
+ }
+ try {
+ loggerFactory.getLogger(name);
+ } catch (Throwable e) {
+ // eat
+ }
+ }
+ LOGGER_FACTORY = loggerFactory;
+ }
+
private interface LoggerFactory {
Logger getLogger(String name);
}
@@ -84,37 +116,4 @@ public Logger getLogger(String name) {
name, n -> new ConsoleLogger(n, System.getProperty(CONSOLE_DEBUG_PROPERTY) != null));
}
}
-
- /** Initialize factory */
- public static void init() {
- String name = LoggerFactory.class.getName();
- LoggerFactory loggerFactory = null;
- if (Boolean.parseBoolean(System.getProperty(NO_LOGGER_PROPERTY, "false"))) {
- loggerFactory = new NoLoggerFactory();
- } else {
-
- try {
- if (Boolean.parseBoolean(System.getProperty(TEST_ENABLE_SLF4J, "true"))) {
- Class.forName("org.slf4j.LoggerFactory");
- loggerFactory = new Slf4JLoggerFactory();
- }
- } catch (ClassNotFoundException cle) {
- // slf4j not in the classpath
- }
- if (loggerFactory == null) {
- // default to console or use JDK logger if explicitly set by System property
- if ("JDK".equalsIgnoreCase(System.getProperty(FALLBACK_PROPERTY))) {
- loggerFactory = new JdkLoggerFactory();
- } else {
- loggerFactory = new ConsoleLoggerFactory();
- }
- }
- try {
- loggerFactory.getLogger(name);
- } catch (Throwable e) {
- // eat
- }
- }
- LOGGER_FACTORY = loggerFactory;
- }
}
diff --git a/src/main/java/org/mariadb/jdbc/util/log/NoLogger.java b/src/main/java/org/mariadb/jdbc/util/log/NoLogger.java
index 7caf7aa58..0d41fcbb8 100644
--- a/src/main/java/org/mariadb/jdbc/util/log/NoLogger.java
+++ b/src/main/java/org/mariadb/jdbc/util/log/NoLogger.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.log;
/** No logger implementation */
diff --git a/src/main/java/org/mariadb/jdbc/util/log/Slf4JLogger.java b/src/main/java/org/mariadb/jdbc/util/log/Slf4JLogger.java
index 4be762e66..62829588d 100644
--- a/src/main/java/org/mariadb/jdbc/util/log/Slf4JLogger.java
+++ b/src/main/java/org/mariadb/jdbc/util/log/Slf4JLogger.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.log;
import org.slf4j.Logger;
diff --git a/src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java b/src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java
index 596512529..99d162051 100644
--- a/src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java
+++ b/src/main/java/org/mariadb/jdbc/util/options/OptionAliases.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.util.options;
import java.util.HashMap;
diff --git a/src/main/java11/org/mariadb/jdbc/client/SocketHelper.java b/src/main/java11/org/mariadb/jdbc/client/SocketHelper.java
index 573f1c3e5..9aedde698 100644
--- a/src/main/java11/org/mariadb/jdbc/client/SocketHelper.java
+++ b/src/main/java11/org/mariadb/jdbc/client/SocketHelper.java
@@ -1,17 +1,17 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.client;
-import jdk.net.ExtendedSocketOptions;
-import org.mariadb.jdbc.Configuration;
-
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
+import jdk.net.ExtendedSocketOptions;
+import org.mariadb.jdbc.Configuration;
public class SocketHelper {
+ public SocketHelper() { }
+
public static void setSocketOption(final Configuration conf, final Socket socket) throws IOException {
socket.setTcpNoDelay(true);
socket.setSoTimeout(conf.socketTimeout());
diff --git a/src/main/java9/module-info.java b/src/main/java9/module-info.java
index 5896c2823..5f1814779 100644
--- a/src/main/java9/module-info.java
+++ b/src/main/java9/module-info.java
@@ -21,6 +21,7 @@
exports org.mariadb.jdbc.message;
exports org.mariadb.jdbc.type;
exports org.mariadb.jdbc.export;
+ exports org.mariadb.jdbc.util.constants;
exports org.mariadb.jdbc.plugin;
exports org.mariadb.jdbc.plugin.codec;
exports org.mariadb.jdbc.plugin.authentication.standard;
diff --git a/src/test/java/org/mariadb/jdbc/integration/BatchTest.java b/src/test/java/org/mariadb/jdbc/integration/BatchTest.java
index 57327e9df..5060564bf 100644
--- a/src/test/java/org/mariadb/jdbc/integration/BatchTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/BatchTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -32,6 +31,29 @@ public static void after2() throws SQLException {
stmt.execute("DROP TABLE IF EXISTS BatchTest");
}
+ @Test
+ public void batchError() throws SQLException {
+ Statement stmt = sharedConn.createStatement();
+ stmt.execute("DROP TABLE IF EXISTS t1");
+ stmt.execute("CREATE TABLE t1(c0 DATE UNIQUE PRIMARY KEY NOT NULL)");
+
+ stmt.addBatch("INSERT INTO t1 VALUES ('2006-04-01')");
+ stmt.addBatch("INSERT INTO t1 VALUES ('2006-04-01')");
+ stmt.addBatch("INSERT INTO t1 VALUES ('2019-04-11')");
+ stmt.addBatch("INSERT INTO t1 VALUES ('2006-04-01')");
+ stmt.addBatch("INSERT INTO t1 VALUES ('2020-04-11')");
+ try {
+ stmt.executeBatch();
+ fail();
+ } catch (BatchUpdateException e) {
+ assertTrue(e.getMessage().contains("Duplicate entry"));
+ assertEquals(5, e.getUpdateCounts().length);
+ assertArrayEquals(
+ new int[] {1, java.sql.Statement.EXECUTE_FAILED, 1, java.sql.Statement.EXECUTE_FAILED, 1},
+ e.getUpdateCounts());
+ }
+ }
+
@Test
public void wrongParameter() throws SQLException {
try (Connection con = createCon("&useServerPrepStmts=false")) {
@@ -60,7 +82,8 @@ public void wrongParameter(Connection con) throws SQLException {
e.getMessage().contains("Parameter at position 2 is not set")
|| e.getMessage()
.contains(
- "batch set of parameters differ from previous set. All parameters must be set"));
+ "batch set of parameters differ from previous set. All parameters must be"
+ + " set"));
}
prep.setInt(1, 5);
@@ -453,29 +476,6 @@ private void batchWithError(Connection con) throws SQLException {
}
}
- private class TimestampCal {
- private Timestamp val;
- private int id;
-
- public TimestampCal(Timestamp val, int id) {
- this.val = val;
- this.id = id;
- }
-
- public Timestamp getVal() {
- return val;
- }
-
- public int getId() {
- return id;
- }
-
- @Override
- public String toString() {
- return "TimestampCal{" + "val=" + val + ", id=" + id + '}';
- }
- }
-
@Test
public void ensureCalendarSync() throws SQLException {
Assumptions.assumeTrue(isMariaDBServer() && !isXpand());
@@ -522,4 +522,27 @@ private int insertTimestamp(TimestampCal[] vals, Calendar cal) {
return -1;
}
}
+
+ private class TimestampCal {
+ private final Timestamp val;
+ private final int id;
+
+ public TimestampCal(Timestamp val, int id) {
+ this.val = val;
+ this.id = id;
+ }
+
+ public Timestamp getVal() {
+ return val;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ @Override
+ public String toString() {
+ return "TimestampCal{" + "val=" + val + ", id=" + id + '}';
+ }
+ }
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/BlobTest.java b/src/test/java/org/mariadb/jdbc/integration/BlobTest.java
index ca02e9420..74690f163 100644
--- a/src/test/java/org/mariadb/jdbc/integration/BlobTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/BlobTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -304,8 +303,8 @@ public void equal() {
MariaDbBlob blob = new MariaDbBlob(bytes);
assertEquals(blob, blob);
assertEquals(new MariaDbBlob(bytes), blob);
- assertFalse(blob.equals(null));
- assertFalse(blob.equals(""));
+ assertNotEquals(null, blob);
+ assertNotEquals("", blob);
byte[] bytes = new byte[] {5, 1, 2, 3, 4, 5};
assertNotEquals(new MariaDbBlob(bytes), blob);
assertNotEquals(new MariaDbBlob(new byte[] {5, 1}), blob);
diff --git a/src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitErrorTest.java b/src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitErrorTest.java
index 4bc9c1cea..197e1de8f 100644
--- a/src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitErrorTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/BulkStmtSplitErrorTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import java.sql.PreparedStatement;
diff --git a/src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java b/src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java
index 745fa45f3..14ab94bed 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ClientPreparedStatementParsingTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -13,13 +12,13 @@
public class ClientPreparedStatementParsingTest extends Common {
- private void checkParsing(String sql, int paramNumber, String[] partsMulti) throws Exception {
+ private void checkParsing(String sql, int paramNumber, String[] partsMulti) {
boolean noBackslashEscapes =
(sharedConn.getContext().getServerStatus() & ServerStatus.NO_BACKSLASH_ESCAPES) > 0;
ClientParser parser = ClientParser.parameterParts(sql, noBackslashEscapes);
assertEquals(paramNumber, parser.getParamCount());
int pos = 0;
- int paramPos = parser.getQuery().length;
+ int paramPos;
for (int i = 0; i < parser.getParamPositions().size(); i++) {
paramPos = parser.getParamPositions().get(i);
assertEquals(partsMulti[i], new String(parser.getQuery(), pos, paramPos - pos));
@@ -41,7 +40,8 @@ public void stringEscapeParsing() throws Exception {
@Test
public void testRewritableWithConstantParameter() throws Exception {
checkParsing(
- "INSERT INTO TABLE(col1,col2,col3,col4, col5) VALUES (9, ?, 5, ?, 8) ON DUPLICATE KEY UPDATE col2=col2+10",
+ "INSERT INTO TABLE(col1,col2,col3,col4, col5) VALUES (9, ?, 5, ?, 8) ON DUPLICATE KEY"
+ + " UPDATE col2=col2+10",
2,
new String[] {
"INSERT INTO TABLE(col1,col2,col3,col4, col5) VALUES (9, ",
@@ -75,7 +75,8 @@ public void testComment() throws Exception {
@Test
public void testRewritableWithConstantParameterAndParamAfterValue() throws Exception {
checkParsing(
- "INSERT INTO TABLE(col1,col2,col3,col4, col5) VALUES (9, ?, 5, ?, 8) ON DUPLICATE KEY UPDATE col2=?",
+ "INSERT INTO TABLE(col1,col2,col3,col4, col5) VALUES (9, ?, 5, ?, 8) ON DUPLICATE KEY"
+ + " UPDATE col2=?",
3,
new String[] {
"INSERT INTO TABLE(col1,col2,col3,col4, col5) VALUES (9, ",
@@ -268,10 +269,18 @@ public void testValuesForPartition() throws Exception {
@Test
public void testParse() throws Exception {
checkParsing(
- "INSERT INTO `myTable` VALUES ('\\n\"\\'', \"'\\\n\\\"\") \n // comment\n , ('a', 'b') # EOL comment",
+ "INSERT INTO `myTable` VALUES ('\\n"
+ + "\"\\'', \"'\\\n"
+ + "\\\"\") \n"
+ + " // comment\n"
+ + " , ('a', 'b') # EOL comment",
0,
new String[] {
- "INSERT INTO `myTable` VALUES ('\\n\"\\'', \"'\\\n\\\"\") \n // comment\n , ('a', 'b') # EOL comment"
+ "INSERT INTO `myTable` VALUES ('\\n"
+ + "\"\\'', \"'\\\n"
+ + "\\\"\") \n"
+ + " // comment\n"
+ + " , ('a', 'b') # EOL comment"
});
}
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/ClobTest.java b/src/test/java/org/mariadb/jdbc/integration/ClobTest.java
index 172b31377..1b852c8ad 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ClobTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ClobTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -396,8 +395,8 @@ public void equal() {
MariaDbClob clob = new MariaDbClob(bytes);
assertEquals(clob, clob);
assertEquals(new MariaDbClob(bytes), clob);
- assertFalse(clob.equals(null));
- assertFalse(clob.equals(""));
+ assertNotEquals(null, clob);
+ assertNotEquals("", clob);
byte[] bytes = "Abc£de🙏fgh".getBytes(StandardCharsets.UTF_8);
assertNotEquals(new MariaDbClob(bytes), clob);
assertNotEquals(new MariaDbClob("Abc".getBytes(StandardCharsets.UTF_8)), clob);
diff --git a/src/test/java/org/mariadb/jdbc/integration/Common.java b/src/test/java/org/mariadb/jdbc/integration/Common.java
index 78e3ba0dc..fe99aa37e 100644
--- a/src/test/java/org/mariadb/jdbc/integration/Common.java
+++ b/src/test/java/org/mariadb/jdbc/integration/Common.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -69,6 +68,8 @@ public class Common {
}
}
+ @RegisterExtension public Extension watcher = new Follow();
+
private static String get(String name, Properties prop) {
String val = System.getenv("TEST_" + name);
if (val == null) val = System.getProperty("TEST_" + name);
@@ -173,28 +174,6 @@ public static void createSequenceTables() throws SQLException {
}
}
- public Connection createProxyCon(HaMode mode, String opts) throws SQLException {
- Configuration conf = Configuration.parse(mDefUrl);
- HostAddress hostAddress = conf.addresses().get(0);
- try {
- proxy = new TcpProxy(hostAddress.host, hostAddress.port);
- } catch (IOException i) {
- throw new SQLException("proxy error", i);
- }
-
- String url = mDefUrl.replaceAll("//([^/]*)/", "//localhost:" + proxy.getLocalPort() + "/");
- if (mode != HaMode.NONE) {
- url =
- url.replaceAll(
- "jdbc:mariadb:", "jdbc:mariadb:" + mode.name().toLowerCase(Locale.ROOT) + ":");
- }
- if (conf.sslMode() == SslMode.VERIFY_FULL) {
- url = url.replaceAll("sslMode=verify-full", "sslMode=verify-ca");
- }
-
- return (Connection) DriverManager.getConnection(url + opts);
- }
-
public static boolean haveSsl() throws SQLException {
Statement stmt = sharedConn.createStatement();
ResultSet rs = stmt.executeQuery("show variables like '%ssl%'");
@@ -210,15 +189,6 @@ public static boolean haveSsl() throws SQLException {
}
}
- public boolean isWindows() {
- return System.getProperty("os.name").toLowerCase().contains("win");
- }
-
- public void cancelForVersion(int major, int minor) {
- String dbVersion = sharedConn.getMetaData().getDatabaseProductVersion();
- Assumptions.assumeFalse(dbVersion.startsWith(major + "." + minor));
- }
-
public static Connection createCon(String option) throws SQLException {
return (Connection) DriverManager.getConnection(mDefUrl + "&" + option);
}
@@ -244,12 +214,6 @@ public static Connection createBasicCon(String option, Integer sslPort) throws S
return Driver.connect(conf);
}
- @AfterEach
- public void afterEach1() throws SQLException {
- sharedConn.isValid(2000);
- sharedConnBinary.isValid(2000);
- }
-
public static int getMaxAllowedPacket() throws SQLException {
java.sql.Statement st = sharedConn.createStatement();
ResultSet rs = st.executeQuery("select @@max_allowed_packet");
@@ -263,7 +227,42 @@ public static void assertThrowsContains(
Assertions.assertTrue(e.getMessage().contains(expected), "real message:" + e.getMessage());
}
- @RegisterExtension public Extension watcher = new Follow();
+ public Connection createProxyCon(HaMode mode, String opts) throws SQLException {
+ Configuration conf = Configuration.parse(mDefUrl);
+ HostAddress hostAddress = conf.addresses().get(0);
+ try {
+ proxy = new TcpProxy(hostAddress.host, hostAddress.port);
+ } catch (IOException i) {
+ throw new SQLException("proxy error", i);
+ }
+
+ String url = mDefUrl.replaceAll("//([^/]*)/", "//localhost:" + proxy.getLocalPort() + "/");
+ if (mode != HaMode.NONE) {
+ url =
+ url.replaceAll(
+ "jdbc:mariadb:", "jdbc:mariadb:" + mode.name().toLowerCase(Locale.ROOT) + ":");
+ }
+ if (conf.sslMode() == SslMode.VERIFY_FULL) {
+ url = url.replaceAll("sslMode=verify-full", "sslMode=verify-ca");
+ }
+
+ return (Connection) DriverManager.getConnection(url + opts);
+ }
+
+ public boolean isWindows() {
+ return System.getProperty("os.name").toLowerCase().contains("win");
+ }
+
+ public void cancelForVersion(int major, int minor) {
+ String dbVersion = sharedConn.getMetaData().getDatabaseProductVersion();
+ Assumptions.assumeFalse(dbVersion.startsWith(major + "." + minor));
+ }
+
+ @AfterEach
+ public void afterEach1() throws SQLException {
+ sharedConn.isValid(2000);
+ sharedConnBinary.isValid(2000);
+ }
private static class Follow implements TestWatcher, BeforeEachCallback {
@Override
diff --git a/src/test/java/org/mariadb/jdbc/integration/CompressTest.java b/src/test/java/org/mariadb/jdbc/integration/CompressTest.java
index 31f070641..511647f0b 100644
--- a/src/test/java/org/mariadb/jdbc/integration/CompressTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/CompressTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java b/src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java
index 2e05ce71d..517fefce7 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ConfigurationTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -16,7 +15,8 @@ public static void begin() throws SQLException {
drop();
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE testSessionVariable(id int not null primary key auto_increment, test varchar(10))");
+ "CREATE TABLE testSessionVariable(id int not null primary key auto_increment, test"
+ + " varchar(10))");
stmt.execute("FLUSH TABLES");
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java b/src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java
index f1a4ce8c5..8557888b7 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -14,6 +13,8 @@
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import org.junit.jupiter.api.*;
import org.mariadb.jdbc.*;
import org.mariadb.jdbc.integration.util.SocketFactoryBasicTest;
@@ -125,7 +126,8 @@ public void initSQL() throws SQLException {
public void nativeSQL() throws SQLException {
String[] inputs =
new String[] {
- "select {fn TIMESTAMPDIFF ( SQL_TSI_HOUR, {fn convert('SQL_', SQL_INTEGER)})}, {fn TIMESTAMPDIFF (HOUR, {fn convert ('sQL_' , SQL_INTEGER)})}",
+ "select {fn TIMESTAMPDIFF ( SQL_TSI_HOUR, {fn convert('SQL_', SQL_INTEGER)})}, {fn"
+ + " TIMESTAMPDIFF (HOUR, {fn convert ('sQL_' , SQL_INTEGER)})}",
"{call foo({fn now()})} //end",
"{call foo({fn '{' now()} /* {test}# \"'\" */) \"\\\"'#\" '\"\\''} #{test2}",
"{ call foo({fn now()})}",
@@ -149,7 +151,8 @@ public void nativeSQL() throws SQLException {
};
String[] outputs =
new String[] {
- "select TIMESTAMPDIFF ( HOUR, convert('SQL_', INTEGER)), TIMESTAMPDIFF (HOUR, convert ('sQL_' , INTEGER))",
+ "select TIMESTAMPDIFF ( HOUR, convert('SQL_', INTEGER)), TIMESTAMPDIFF (HOUR, convert "
+ + " ('sQL_' , INTEGER))",
"call foo(now()) //end",
"call foo('{' now() /* {test}# \"'\" */) \"\\\"'#\" '\"\\'' #{test2}",
"call foo(now())",
@@ -175,9 +178,11 @@ public void nativeSQL() throws SQLException {
assertEquals(outputs[i], sharedConn.nativeSQL(inputs[i]));
}
assertEquals(
- "INSERT INTO TEST_SYNTAX_ERROR(str_value, json_value) VALUES ('abc\\\\', '{\"data\": \"test\"}')",
+ "INSERT INTO TEST_SYNTAX_ERROR(str_value, json_value) VALUES ('abc\\\\', '{\"data\":"
+ + " \"test\"}')",
sharedConn.nativeSQL(
- "INSERT INTO TEST_SYNTAX_ERROR(str_value, json_value) VALUES ('abc\\\\', '{\"data\": \"test\"}')"));
+ "INSERT INTO TEST_SYNTAX_ERROR(str_value, json_value) VALUES ('abc\\\\', '{\"data\":"
+ + " \"test\"}')"));
try {
sharedConn.nativeSQL("{call foo({fn now())}");
@@ -320,7 +325,8 @@ public void doubleBackslash() throws SQLException {
+ " json_value MEDIUMTEXT CHARACTER SET utf8mb4 NOT NULL, "
+ " PRIMARY KEY ( id ))");
stmt.execute(
- "INSERT INTO TEST_SYNTAX_ERROR(str_value, json_value) VALUES ('abc\\\\', '{\"data\": \"test\"}')");
+ "INSERT INTO TEST_SYNTAX_ERROR(str_value, json_value) VALUES ('abc\\\\', '{\"data\":"
+ + " \"test\"}')");
}
@Test
@@ -461,7 +467,8 @@ public void run() {
SQLException.class,
() ->
stmt.executeQuery(
- "select * from information_schema.columns as c1, information_schema.tables, information_schema.tables as t2"));
+ "select * from information_schema.columns as c1, information_schema.tables,"
+ + " information_schema.tables as t2"));
}
}
@@ -498,7 +505,8 @@ public void testConnectionAttributes() throws Exception {
Statement attributeStatement = connection.createStatement();
ResultSet result =
attributeStatement.executeQuery(
- "select * from performance_schema.session_connect_attrs where ATTR_NAME='_server_host' and processlist_id = connection_id()");
+ "select * from performance_schema.session_connect_attrs where"
+ + " ATTR_NAME='_server_host' and processlist_id = connection_id()");
while (result.next()) {
String strVal = result.getString("ATTR_VALUE");
assertEquals(Configuration.parse(mDefUrl).addresses().get(0).host, strVal);
@@ -649,138 +657,6 @@ public void releaseSavepoint() throws SQLException {
}
}
- static class MySavepoint implements Savepoint {
- @Override
- public int getSavepointId() throws SQLException {
- return 0;
- }
-
- @Override
- public String getSavepointName() throws SQLException {
- return null;
- }
- }
-
- @Nested
- @DisplayName("Transaction Test")
- class Transaction {
-
- @Test
- public void testProperRollback() throws Exception {
- java.sql.Statement stmt = sharedConn.createStatement();
- try {
- stmt.execute("CREATE TABLE tx_prim_key(id int not null primary key) engine=innodb");
- stmt.execute(
- "CREATE TABLE tx_fore_key (id int not null primary key, id_ref int not null, "
- + "foreign key (id_ref) references tx_prim_key(id) on delete restrict on update restrict) "
- + "engine=innodb");
- stmt.executeUpdate("insert into tx_prim_key(id) values(32)");
- stmt.executeUpdate("insert into tx_fore_key(id, id_ref) values(42, 32)");
-
- // 2. try to delete entry in Primary table in a transaction - which will fail due
- // foreign key.
- sharedConn.setAutoCommit(false);
- try (java.sql.Statement st = sharedConn.createStatement()) {
- st.executeUpdate("delete from tx_prim_key where id = 32");
- sharedConn.commit();
- fail("Expected SQLException");
- } catch (SQLException e) {
- // This exception is expected
- assertTrue(
- e.getMessage().contains("a foreign key constraint fails")
- || e.getMessage().contains("Foreign key constraint violation"));
- sharedConn.rollback();
- }
-
- try (java.sql.Connection conn2 = createCon();
- java.sql.Statement st = conn2.createStatement()) {
- st.setQueryTimeout(30000);
- st.executeUpdate("delete from tx_fore_key where id = 42");
- st.executeUpdate("delete from tx_prim_key where id = 32");
- }
-
- } finally {
- stmt.execute("drop table if exists tx_fore_key");
- stmt.execute("drop table if exists tx_prim_key");
- }
- }
-
- @Test
- public void transactionTest() throws SQLException {
- Statement stmt = sharedConn.createStatement();
- try {
- stmt.execute(
- "CREATE TABLE transaction_test "
- + "(id int not null primary key auto_increment, test varchar(20)) "
- + "engine=innodb");
- sharedConn.setAutoCommit(false);
- stmt.executeUpdate("INSERT INTO transaction_test (test) VALUES ('heja')");
- stmt.executeUpdate("INSERT INTO transaction_test (test) VALUES ('japp')");
- sharedConn.commit();
- ResultSet rs = stmt.executeQuery("SELECT * FROM transaction_test");
- assertEquals(true, rs.next());
- assertEquals("heja", rs.getString("test"));
- assertEquals(true, rs.next());
- assertEquals("japp", rs.getString("test"));
- assertEquals(false, rs.next());
- stmt.executeUpdate(
- "INSERT INTO transaction_test (test) VALUES ('rollmeback')",
- java.sql.Statement.RETURN_GENERATED_KEYS);
- ResultSet rsGen = stmt.getGeneratedKeys();
- rsGen.next();
- int[] autoInc = setAutoInc();
- assertEquals(autoInc[1] + autoInc[0] * 3, rsGen.getInt(1));
- sharedConn.rollback();
- rs = stmt.executeQuery("SELECT * FROM transaction_test WHERE id=3");
- assertEquals(false, rs.next());
- sharedConn.setAutoCommit(true);
- } finally {
- stmt.execute("DROP TABLE IF EXISTS transaction_test");
- }
- }
-
- /**
- * Get current autoincrement value, since Galera values are automatically set.
- *
- * @throws SQLException if any error occur.
- */
- public int[] setAutoInc() throws SQLException {
- return setAutoInc(1, 0);
- }
-
- /**
- * Get current autoincrement value, since Galera values are automatically set.
- *
- * @param autoIncInit default increment
- * @param autoIncOffsetInit default increment offset
- * @throws SQLException if any error occur
- * @see https://mariadb.org/auto-increments-in-galera/
- */
- public int[] setAutoInc(int autoIncInit, int autoIncOffsetInit) throws SQLException {
-
- // in case of galera
- // if (isGalera()) {
- // ResultSet rs =
- // sharedConn.createStatement().executeQuery("show variables like
- // '%auto_increment%'");
- // while (rs.next()) {
- // if ("auto_increment_increment".equals(rs.getString(1))) {
- // autoInc = rs.getInt(2);
- // }
- // if ("auto_increment_offset".equals(rs.getString(1))) {
- // autoIncOffset = rs.getInt(2);
- // }
- // }
- // if (autoInc == 1) {
- // // galera with one node only, then offset is not used
- // autoIncOffset = 0;
- // }
- // }
- return new int[] {autoIncInit, autoIncOffsetInit};
- }
- }
-
@Test
public void various() throws SQLException {
assertThrows(SQLException.class, () -> sharedConn.setTypeMap(null));
@@ -892,19 +768,6 @@ public void pamAuthPlugin() throws Throwable {
stmt.execute("drop user " + pamUser + "@'%'");
}
- @Nested
- @DisplayName("Compression Test")
- class Compression {
-
- @Test
- public void testConnection() throws Exception {
- try (Connection connection = createCon("useCompression")) {
- // must have succeeded
- connection.getCatalog();
- }
- }
- }
-
@Test
public void testNoUseReadAheadInputConnection() throws Exception {
try (Connection connection = createCon("useReadAheadInput=false")) {
@@ -935,10 +798,12 @@ public void useNoDatabase() throws SQLException {
@Test
public void windowsNamedPipe() throws SQLException {
- Assumptions.assumeTrue(isMariaDBServer() || !minVersion(8, 0, 14));
ResultSet rs = null;
try {
- rs = sharedConn.createStatement().executeQuery("select @@named_pipe,@@socket");
+ rs =
+ sharedConn
+ .createStatement()
+ .executeQuery("select @@named_pipe,@@socket,@@named_pipe_full_access_group");
} catch (SQLException sqle) {
// on non Windows system, named_pipe doesn't exist.
}
@@ -948,10 +813,23 @@ public void windowsNamedPipe() throws SQLException {
Assumptions.assumeTrue(rs.getBoolean(1));
String namedPipeName = rs.getString(2);
System.out.println("namedPipeName:" + namedPipeName);
+ if (!isMariaDBServer() && minVersion(8, 0, 14)) {
+ String namedPipeFullAccess = rs.getString(3);
+ System.out.println("namedPipeFullAccess:" + namedPipeFullAccess);
+ Assumptions.assumeTrue(namedPipeFullAccess != null && !namedPipeFullAccess.isEmpty());
+ }
// skip test if no namedPipeName was obtained because then we do not use a socket connection
Assumptions.assumeTrue(namedPipeName != null);
- try (Connection connection = createCon("pipe=" + namedPipeName)) {
+ String connUrl =
+ password == null || password.isEmpty()
+ ? String.format("jdbc:mariadb:///%s?user=%s%s", database, user, defaultOther)
+ : String.format(
+ "jdbc:mariadb:///%s?user=%s&password=%s%s",
+ database, user, password, defaultOther);
+
+ try (Connection connection =
+ DriverManager.getConnection(connUrl + "&pipe=" + namedPipeName)) {
java.sql.Statement stmt = connection.createStatement();
try (ResultSet rs2 = stmt.executeQuery("SELECT 1")) {
assertTrue(rs2.next());
@@ -974,6 +852,60 @@ public void windowsNamedPipe() throws SQLException {
}
}
+ @Test
+ public void windowsNamedPipeCancel() throws SQLException {
+ Assumptions.assumeFalse(isMariaDBServer());
+ ResultSet rs = null;
+ try {
+ rs =
+ sharedConn
+ .createStatement()
+ .executeQuery("select @@named_pipe,@@socket,@@named_pipe_full_access_group");
+ } catch (SQLException sqle) {
+ // on non Windows system, named_pipe doesn't exist.
+ }
+ if (rs != null) {
+ assertTrue(rs.next());
+ System.out.println("named_pipe:" + rs.getString(1));
+ Assumptions.assumeTrue(rs.getBoolean(1));
+ String namedPipeName = rs.getString(2);
+ System.out.println("namedPipeName:" + namedPipeName);
+ if (!isMariaDBServer() && minVersion(8, 0, 14)) {
+ String namedPipeFullAccess = rs.getString(3);
+ System.out.println("namedPipeFullAccess:" + namedPipeFullAccess);
+ Assumptions.assumeTrue(namedPipeFullAccess != null && !namedPipeFullAccess.isEmpty());
+ }
+
+ // skip test if no namedPipeName was obtained because then we do not use a socket connection
+ Assumptions.assumeTrue(namedPipeName != null);
+ String connUrl =
+ password == null || password.isEmpty()
+ ? String.format("jdbc:mariadb:///%s?user=%s%s", database, user, defaultOther)
+ : String.format(
+ "jdbc:mariadb:///%s?user=%s&password=%s%s",
+ database, user, password, defaultOther);
+
+ try (Connection connection =
+ DriverManager.getConnection(connUrl + "&pipe=" + namedPipeName)) {
+ Statement stmt = connection.createStatement();
+ stmt.cancel(); // will do nothing
+
+ ExecutorService exec = Executors.newFixedThreadPool(1);
+
+ Common.assertThrowsContains(
+ SQLTimeoutException.class,
+ () -> {
+ exec.execute(new StatementTest.CancelThread(stmt));
+ stmt.execute(
+ "select * from information_schema.columns as c1, information_schema.tables,"
+ + " information_schema.tables as t2");
+ exec.shutdown();
+ },
+ "Query execution was interrupted");
+ }
+ }
+ }
+
@Test
public void localSocket() throws Exception {
Assumptions.assumeTrue(
@@ -1180,4 +1112,149 @@ public void loopHost() throws SQLException {
con.createStatement().executeQuery("SELECT 1");
}
}
+
+ static class MySavepoint implements Savepoint {
+ @Override
+ public int getSavepointId() throws SQLException {
+ return 0;
+ }
+
+ @Override
+ public String getSavepointName() throws SQLException {
+ return null;
+ }
+ }
+
+ @Nested
+ @DisplayName("Transaction Test")
+ class Transaction {
+
+ @Test
+ public void testProperRollback() throws Exception {
+ java.sql.Statement stmt = sharedConn.createStatement();
+ try {
+ stmt.execute("CREATE TABLE tx_prim_key(id int not null primary key) engine=innodb");
+ stmt.execute(
+ "CREATE TABLE tx_fore_key (id int not null primary key, id_ref int not null, foreign"
+ + " key (id_ref) references tx_prim_key(id) on delete restrict on update restrict) "
+ + "engine=innodb");
+ stmt.executeUpdate("insert into tx_prim_key(id) values(32)");
+ stmt.executeUpdate("insert into tx_fore_key(id, id_ref) values(42, 32)");
+
+ // 2. try to delete entry in Primary table in a transaction - which will fail due
+ // foreign key.
+ sharedConn.setAutoCommit(false);
+ try (java.sql.Statement st = sharedConn.createStatement()) {
+ st.executeUpdate("delete from tx_prim_key where id = 32");
+ sharedConn.commit();
+ fail("Expected SQLException");
+ } catch (SQLException e) {
+ // This exception is expected
+ assertTrue(
+ e.getMessage().contains("a foreign key constraint fails")
+ || e.getMessage().contains("Foreign key constraint violation"));
+ sharedConn.rollback();
+ }
+
+ try (java.sql.Connection conn2 = createCon();
+ java.sql.Statement st = conn2.createStatement()) {
+ st.setQueryTimeout(30000);
+ st.executeUpdate("delete from tx_fore_key where id = 42");
+ st.executeUpdate("delete from tx_prim_key where id = 32");
+ }
+
+ } finally {
+ stmt.execute("drop table if exists tx_fore_key");
+ stmt.execute("drop table if exists tx_prim_key");
+ }
+ }
+
+ @Test
+ public void transactionTest() throws SQLException {
+ Statement stmt = sharedConn.createStatement();
+ try {
+ stmt.execute(
+ "CREATE TABLE transaction_test "
+ + "(id int not null primary key auto_increment, test varchar(20)) "
+ + "engine=innodb");
+ sharedConn.setAutoCommit(false);
+ stmt.executeUpdate("INSERT INTO transaction_test (test) VALUES ('heja')");
+ stmt.executeUpdate("INSERT INTO transaction_test (test) VALUES ('japp')");
+ sharedConn.commit();
+ ResultSet rs = stmt.executeQuery("SELECT * FROM transaction_test");
+ assertTrue(rs.next());
+ assertEquals("heja", rs.getString("test"));
+ assertTrue(rs.next());
+ assertEquals("japp", rs.getString("test"));
+ assertFalse(rs.next());
+ stmt.executeUpdate(
+ "INSERT INTO transaction_test (test) VALUES ('rollmeback')",
+ java.sql.Statement.RETURN_GENERATED_KEYS);
+ ResultSet rsGen = stmt.getGeneratedKeys();
+ rsGen.next();
+ int[] autoInc = setAutoInc();
+ assertEquals(autoInc[1] + autoInc[0] * 3, rsGen.getInt(1));
+ sharedConn.rollback();
+ rs = stmt.executeQuery("SELECT * FROM transaction_test WHERE id=3");
+ assertFalse(rs.next());
+ sharedConn.setAutoCommit(true);
+ } finally {
+ stmt.execute("DROP TABLE IF EXISTS transaction_test");
+ }
+ }
+
+ /**
+ * Get current autoincrement value, since Galera values are automatically set.
+ *
+ * @throws SQLException if any error occur.
+ */
+ public int[] setAutoInc() throws SQLException {
+ return setAutoInc(1, 0);
+ }
+
+ /**
+ * Get current autoincrement value, since Galera values are automatically set.
+ *
+ * @param autoIncInit default increment
+ * @param autoIncOffsetInit default increment offset
+ * @throws SQLException if any error occur
+ * @see https://mariadb.org/auto-increments-in-galera/
+ */
+ public int[] setAutoInc(int autoIncInit, int autoIncOffsetInit) throws SQLException {
+
+ // in case of galera
+ // if (isGalera()) {
+ // ResultSet rs =
+ // sharedConn.createStatement().executeQuery("show variables like
+ // '%auto_increment%'");
+ // while (rs.next()) {
+ // if ("auto_increment_increment".equals(rs.getString(1))) {
+ // autoInc = rs.getInt(2);
+ // }
+ // if ("auto_increment_offset".equals(rs.getString(1))) {
+ // autoIncOffset = rs.getInt(2);
+ // }
+ // }
+ // if (autoInc == 1) {
+ // // galera with one node only, then offset is not used
+ // autoIncOffset = 0;
+ // }
+ // }
+ return new int[] {autoIncInit, autoIncOffsetInit};
+ }
+ }
+
+ @Nested
+ @DisplayName("Compression Test")
+ class Compression {
+
+ @Test
+ public void testConnection() throws Exception {
+ try (Connection connection = createCon("useCompression")) {
+ // must have succeeded
+ connection.getCatalog();
+ }
+ }
+ }
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java b/src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java
index 1852c8457..747dc38ee 100644
--- a/src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/CredentialPluginTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -23,7 +22,10 @@ public class CredentialPluginTest extends Common {
@BeforeAll
public static void beforeTest() throws SQLException {
String version = System.getProperty("java.version");
- int majorVersion = Integer.parseInt(version.substring(0, version.indexOf(".")));
+ int majorVersion =
+ (version.indexOf(".") >= 0)
+ ? Integer.parseInt(version.substring(0, version.indexOf(".")))
+ : Integer.parseInt(version);
Assumptions.assumeTrue(majorVersion < 17);
Assumptions.assumeTrue(isMariaDBServer());
diff --git a/src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java b/src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java
index a97db8683..f5b0e2006 100644
--- a/src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/DataSourceTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -52,14 +51,17 @@ private void testDs(MariaDbDataSource ds) throws SQLException {
try {
con1 = ds.getPooledConnection();
con2 = ds.getPooledConnection();
-
- ResultSet rs1 = con1.getConnection().createStatement().executeQuery("SELECT 1");
- ResultSet rs2 = con2.getConnection().createStatement().executeQuery("SELECT 2");
- while (rs1.next()) {
- assertEquals(1, rs1.getInt(1));
- }
- while (rs2.next()) {
- assertEquals(2, rs2.getInt(1));
+ try (Statement stmt = con1.getConnection().createStatement()) {
+ ResultSet rs1 = stmt.executeQuery("SELECT 1");
+ try (Statement stmt2 = con2.getConnection().createStatement()) {
+ ResultSet rs2 = stmt2.executeQuery("SELECT 2");
+ while (rs1.next()) {
+ assertEquals(1, rs1.getInt(1));
+ }
+ while (rs2.next()) {
+ assertEquals(2, rs2.getInt(1));
+ }
+ }
}
} finally {
@@ -73,15 +75,18 @@ private void testDs(MariaDbDataSource ds) throws SQLException {
conx1 = ds.getXAConnection();
conx2 = ds.getXAConnection();
- ResultSet rs1 = conx1.getConnection().createStatement().executeQuery("SELECT 1");
- ResultSet rs2 = conx2.getConnection().createStatement().executeQuery("SELECT 2");
- while (rs1.next()) {
- assertEquals(1, rs1.getInt(1));
- }
- while (rs2.next()) {
- assertEquals(2, rs2.getInt(1));
+ try (Statement stmt = conx1.getConnection().createStatement()) {
+ ResultSet rs1 = stmt.executeQuery("SELECT 1");
+ try (Statement stmt2 = conx2.getConnection().createStatement()) {
+ ResultSet rs2 = stmt2.executeQuery("SELECT 2");
+ while (rs1.next()) {
+ assertEquals(1, rs1.getInt(1));
+ }
+ while (rs2.next()) {
+ assertEquals(2, rs2.getInt(1));
+ }
+ }
}
-
} finally {
if (conx1 != null) con1.close();
if (conx2 != null) con2.close();
@@ -100,19 +105,19 @@ public void basic2() throws SQLException {
ds.setLoginTimeout(50);
assertEquals(50, ds.getLoginTimeout());
- assertThrows(SQLException.class, () -> ds.getConnection());
+ assertThrows(SQLException.class, ds::getConnection);
assertThrows(SQLException.class, () -> ds.getConnection("user", "password"));
- assertThrows(SQLException.class, () -> ds.getPooledConnection());
+ assertThrows(SQLException.class, ds::getPooledConnection);
assertThrows(SQLException.class, () -> ds.getPooledConnection("user", "password"));
- assertThrows(SQLException.class, () -> ds.getXAConnection());
+ assertThrows(SQLException.class, ds::getXAConnection);
assertThrows(SQLException.class, () -> ds.getXAConnection("user", "password"));
ds.setUser("dd");
assertEquals("dd", ds.getUser());
ds.setPassword("pwd");
- assertThrows(SQLException.class, () -> ds.getConnection());
- assertThrows(SQLException.class, () -> ds.getPooledConnection());
+ assertThrows(SQLException.class, ds::getConnection);
+ assertThrows(SQLException.class, ds::getPooledConnection);
assertThrows(SQLException.class, () -> ds.setUrl("jdbc:wrong://d"));
@@ -141,7 +146,8 @@ public void switchUser() throws SQLException {
stmt.execute("GRANT SELECT ON " + sharedConn.getCatalog() + ".* TO 'dsUser'@'%'");
} else {
stmt.execute(
- "CREATE USER 'dsUser'@'%' IDENTIFIED WITH mysql_native_password BY 'MySup8%rPassw@ord'");
+ "CREATE USER 'dsUser'@'%' IDENTIFIED WITH mysql_native_password BY"
+ + " 'MySup8%rPassw@ord'");
stmt.execute("GRANT SELECT ON " + sharedConn.getCatalog() + ".* TO 'dsUser'@'%'");
}
} else {
diff --git a/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java b/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java
index 69abf84b9..a7ac0f599 100644
--- a/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/DatabaseMetadataTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -53,45 +52,30 @@ public static void initClass() throws SQLException {
+ "t6 time(6))");
stmt.execute("CREATE TABLE json_test(t1 JSON)");
stmt.execute(
- "CREATE PROCEDURE testMetaCatalog(x int, out y int) COMMENT 'comments' \nBEGIN\nSELECT 1;end\n");
+ "CREATE PROCEDURE testMetaCatalog(x int, out y int) COMMENT 'comments' \n"
+ + "BEGIN\n"
+ + "SELECT 1;end\n");
stmt.execute(
- "CREATE TABLE IF NOT EXISTS dbpk_test(val varchar(20), id1 int not null, id2 int not null,primary key(id1, "
- + "id2)) engine=innodb");
+ "CREATE TABLE IF NOT EXISTS dbpk_test(val varchar(20), id1 int not null, id2 int not"
+ + " null,primary key(id1, id2)) engine=innodb");
stmt.execute("CREATE TABLE IF NOT EXISTS datetime_test(dt datetime)");
stmt.execute(
- "CREATE TABLE IF NOT EXISTS `manycols`("
- + " `tiny` tinyint(4) DEFAULT NULL,"
- + " `tiny_uns` tinyint(3) unsigned DEFAULT NULL,"
- + " `small` smallint(6) DEFAULT NULL,"
- + " `small_uns` smallint(5) unsigned DEFAULT NULL,"
- + " `medium` mediumint(9) DEFAULT NULL,"
- + " `medium_uns` mediumint(8) unsigned DEFAULT NULL,"
- + " `int_col` int(11) DEFAULT NULL,"
- + " `int_col_uns` int(10) unsigned DEFAULT NULL,"
- + " `big` bigint(20) DEFAULT NULL,"
- + " `big_uns` bigint(20) unsigned DEFAULT NULL,"
- + " `decimal_col` decimal(10,5) DEFAULT NULL,"
- + " `fcol` float DEFAULT NULL,"
- + " `fcol_uns` float unsigned DEFAULT NULL,"
- + " `dcol` double DEFAULT NULL,"
- + " `dcol_uns` double unsigned DEFAULT NULL,"
- + " `date_col` date DEFAULT NULL,"
- + " `time_col` time DEFAULT NULL,"
- + " `timestamp_col` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,"
- + " `year_col` year(4) DEFAULT NULL,"
- + " `bit_col` bit(5) DEFAULT NULL,"
- + " `char_col` char(5) DEFAULT NULL,"
- + " `varchar_col` varchar(10) DEFAULT NULL,"
- + " `binary_col` binary(10) DEFAULT NULL,"
- + " `varbinary_col` varbinary(10) DEFAULT NULL,"
- + " `tinyblob_col` tinyblob,"
- + " `blob_col` blob,"
- + " `mediumblob_col` mediumblob,"
- + " `longblob_col` longblob,"
- + " `tinytext_col` tinytext,"
- + " `text_col` text,"
- + " `mediumtext_col` mediumtext,"
- + " `longtext_col` longtext)");
+ "CREATE TABLE IF NOT EXISTS `manycols`( `tiny` tinyint(4) DEFAULT NULL, `tiny_uns`"
+ + " tinyint(3) unsigned DEFAULT NULL, `small` smallint(6) DEFAULT NULL, `small_uns`"
+ + " smallint(5) unsigned DEFAULT NULL, `medium` mediumint(9) DEFAULT NULL, "
+ + " `medium_uns` mediumint(8) unsigned DEFAULT NULL, `int_col` int(11) DEFAULT NULL, "
+ + " `int_col_uns` int(10) unsigned DEFAULT NULL, `big` bigint(20) DEFAULT NULL, "
+ + " `big_uns` bigint(20) unsigned DEFAULT NULL, `decimal_col` decimal(10,5) DEFAULT"
+ + " NULL, `fcol` float DEFAULT NULL, `fcol_uns` float unsigned DEFAULT NULL, `dcol`"
+ + " double DEFAULT NULL, `dcol_uns` double unsigned DEFAULT NULL, `date_col` date"
+ + " DEFAULT NULL, `time_col` time DEFAULT NULL, `timestamp_col` timestamp NOT NULL"
+ + " DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `year_col` year(4) DEFAULT"
+ + " NULL, `bit_col` bit(5) DEFAULT NULL, `char_col` char(5) DEFAULT NULL, "
+ + " `varchar_col` varchar(10) DEFAULT NULL, `binary_col` binary(10) DEFAULT NULL, "
+ + " `varbinary_col` varbinary(10) DEFAULT NULL, `tinyblob_col` tinyblob, `blob_col`"
+ + " blob, `mediumblob_col` mediumblob, `longblob_col` longblob, `tinytext_col`"
+ + " tinytext, `text_col` text, `mediumtext_col` mediumtext, `longtext_col`"
+ + " longtext)");
stmt.execute("CREATE TABLE IF NOT EXISTS ytab(y year)");
stmt.execute(
"CREATE TABLE IF NOT EXISTS maxcharlength(maxcharlength char(1)) character set utf8");
@@ -104,19 +88,18 @@ public static void initClass() throws SQLException {
stmt.execute("drop table if exists cross1");
stmt.execute("create table cross1 (id int not null primary key, val varchar(20))");
stmt.execute(
- "create table cross2 (id int not null, id2 int not null, "
- + "id_ref0 int, foreign key (id_ref0) references cross1(id), UNIQUE unik_name (id, id2))");
+ "create table cross2 (id int not null, id2 int not null, id_ref0 int, foreign key"
+ + " (id_ref0) references cross1(id), UNIQUE unik_name (id, id2))");
stmt.execute(
- "create table cross3 (id int not null primary key, "
- + "id_ref1 int, id_ref2 int, foreign key fk_my_name (id_ref1, id_ref2) references cross2(id, id2) on "
- + "update cascade)");
+ "create table cross3 (id int not null primary key, id_ref1 int, id_ref2 int, foreign key"
+ + " fk_my_name (id_ref1, id_ref2) references cross2(id, id2) on update cascade)");
stmt.execute(
- "create table getBestRowIdentifier1(i int not null primary key auto_increment, id int, "
- + "id_ref1 int, id_ref2 int, foreign key fk_my_name_1 (id_ref1, id_ref2) references cross2(id, id2) on "
- + "update cascade, UNIQUE getBestRowIdentifier_unik (id))");
+ "create table getBestRowIdentifier1(i int not null primary key auto_increment, id int,"
+ + " id_ref1 int, id_ref2 int, foreign key fk_my_name_1 (id_ref1, id_ref2) references"
+ + " cross2(id, id2) on update cascade, UNIQUE getBestRowIdentifier_unik (id))");
stmt.execute(
- "create table getBestRowIdentifier2(id_ref0 int not null, "
- + "id_ref1 int, id_ref2 int not null, UNIQUE (id_ref1, id_ref2) , UNIQUE (id_ref0, id_ref2))");
+ "create table getBestRowIdentifier2(id_ref0 int not null, id_ref1 int, id_ref2 int not"
+ + " null, UNIQUE (id_ref1, id_ref2) , UNIQUE (id_ref0, id_ref2))");
stmt.execute(
"CREATE TABLE IF NOT EXISTS get_index_info(\n"
+ " no INT NOT NULL AUTO_INCREMENT,\n"
@@ -161,7 +144,7 @@ public void primaryKeysTest() throws SQLException {
while (rs.next()) {
counter++;
assertEquals(sharedConn.getCatalog(), rs.getString("table_cat"));
- assertEquals(null, rs.getString("table_schem"));
+ assertNull(rs.getString("table_schem"));
assertEquals("dbpk_test", rs.getString("table_name"));
assertEquals("id" + counter, rs.getString("column_name"));
assertEquals("id" + counter, rs.getString("column_name"));
@@ -196,9 +179,9 @@ public void primaryKeyTest2() throws SQLException {
stmt.execute("drop table if exists primarykeytest1");
stmt.execute("CREATE TABLE primarykeytest1 ( id1 integer, constraint pk primary key(id1))");
stmt.execute(
- "CREATE TABLE primarykeytest2 (id2a integer, id2b integer, constraint pk primary key(id2a, id2b), "
- + "constraint fk1 foreign key(id2a) references primarykeytest1(id1), constraint fk2 foreign key(id2b) "
- + "references primarykeytest1(id1))");
+ "CREATE TABLE primarykeytest2 (id2a integer, id2b integer, constraint pk primary key(id2a,"
+ + " id2b), constraint fk1 foreign key(id2a) references primarykeytest1(id1), "
+ + " constraint fk2 foreign key(id2b) references primarykeytest1(id1))");
DatabaseMetaData dbmd = sharedConn.getMetaData();
ResultSet rs = dbmd.getPrimaryKeys(sharedConn.getCatalog(), null, "primarykeytest2");
@@ -206,7 +189,7 @@ public void primaryKeyTest2() throws SQLException {
while (rs.next()) {
counter++;
assertEquals(sharedConn.getCatalog(), rs.getString("table_cat"));
- assertEquals(null, rs.getString("table_schem"));
+ assertNull(rs.getString("table_schem"));
assertEquals("primarykeytest2", rs.getString("table_name"));
assertEquals(counter, rs.getShort("key_seq"));
assertEquals("PRIMARY", rs.getString("pk_name"));
@@ -224,9 +207,10 @@ public void primaryKeyTest2Schema() throws SQLException {
stmt.execute("drop table if exists primarykeytest1");
stmt.execute("CREATE TABLE primarykeytest1 ( id1 integer, constraint pk primary key(id1))");
stmt.execute(
- "CREATE TABLE primarykeytest2 (id2a integer, id2b integer, constraint pk primary key(id2a, id2b), "
- + "constraint fk1 foreign key(id2a) references primarykeytest1(id1), constraint fk2 foreign key(id2b) "
- + "references primarykeytest1(id1))");
+ "CREATE TABLE primarykeytest2 (id2a integer, id2b integer, constraint pk primary"
+ + " key(id2a, id2b), constraint fk1 foreign key(id2a) references"
+ + " primarykeytest1(id1), constraint fk2 foreign key(id2b) references"
+ + " primarykeytest1(id1))");
DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs = dbmd.getPrimaryKeys(con.getCatalog(), null, "primarykeytest2");
@@ -273,8 +257,8 @@ public void functionColumns() throws SQLException {
assertTrue(rs.next());
/* First row is for return value */
assertEquals(rs.getString("FUNCTION_CAT"), sharedConn.getCatalog());
- assertEquals(rs.getString("FUNCTION_SCHEM"), null);
- assertEquals(rs.getString("COLUMN_NAME"), null); /* No name, since it is return value */
+ assertNull(rs.getString("FUNCTION_SCHEM"));
+ assertNull(rs.getString("COLUMN_NAME")); /* No name, since it is return value */
assertEquals(rs.getInt("COLUMN_TYPE"), DatabaseMetaData.functionReturn);
assertEquals(rs.getInt("DATA_TYPE"), Types.CHAR);
assertEquals(rs.getString("TYPE_NAME"), "char");
@@ -316,7 +300,7 @@ public void functionColumnsSchema() throws SQLException {
/* First row is for return value */
assertEquals(rs.getString("FUNCTION_CAT"), "def");
assertEquals(rs.getString("FUNCTION_SCHEM"), database);
- assertEquals(rs.getString("COLUMN_NAME"), null); /* No name, since it is return value */
+ assertNull(rs.getString("COLUMN_NAME")); /* No name, since it is return value */
assertEquals(rs.getInt("COLUMN_TYPE"), DatabaseMetaData.functionReturn);
assertEquals(rs.getInt("DATA_TYPE"), Types.CHAR);
assertEquals(rs.getString("TYPE_NAME"), "char");
@@ -389,7 +373,8 @@ private void getImportedKeys(
+ " UNIQUE unik_name (category, id) )");
st.execute(
- "CREATE TABLE `cus``tomer` (id INT NOT NULL, id2 INT NOT NULL, PRIMARY KEY (id), UNIQUE unikConst (id2))");
+ "CREATE TABLE `cus``tomer` (id INT NOT NULL, id2 INT NOT NULL, PRIMARY KEY (id), UNIQUE"
+ + " unikConst (id2))");
String constraint = "ON UPDATE SET DEFAULT ON DELETE SET DEFAULT";
if (!isMariaDBServer() || !minVersion(10, 5, 0))
constraint = "ON UPDATE CASCADE ON DELETE CASCADE";
@@ -603,11 +588,11 @@ public void exportedKeysTest() throws SQLException {
ResultSet rs = dbmd.getExportedKeys(sharedConn.getCatalog(), null, "cross%");
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString("PKTABLE_CAT"));
- assertEquals(null, rs.getString("PKTABLE_SCHEM"));
+ assertNull(rs.getString("PKTABLE_SCHEM"));
assertEquals("cross1", rs.getString("PKTABLE_NAME"));
assertEquals("id", rs.getString("PKCOLUMN_NAME"));
assertEquals(sharedConn.getCatalog(), rs.getString("FKTABLE_CAT"));
- assertEquals(null, rs.getString("FKTABLE_SCHEM"));
+ assertNull(rs.getString("FKTABLE_SCHEM"));
assertEquals("cross2", rs.getString("FKTABLE_NAME"));
assertEquals("id_ref0", rs.getString("FKCOLUMN_NAME"));
assertTrue(rs.getInt("KEY_SEQ") == 1 || rs.wasNull());
@@ -626,11 +611,11 @@ public void exportedKeysTest() throws SQLException {
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString("PKTABLE_CAT"));
- assertEquals(null, rs.getString("PKTABLE_SCHEM"));
+ assertNull(rs.getString("PKTABLE_SCHEM"));
assertEquals("cross2", rs.getString("PKTABLE_NAME"));
assertEquals("id", rs.getString("PKCOLUMN_NAME"));
assertEquals(sharedConn.getCatalog(), rs.getString("FKTABLE_CAT"));
- assertEquals(null, rs.getString("FKTABLE_SCHEM"));
+ assertNull(rs.getString("FKTABLE_SCHEM"));
assertEquals("cross3", rs.getString("FKTABLE_NAME"));
assertEquals("id_ref1", rs.getString("FKCOLUMN_NAME"));
assertTrue(rs.getInt("KEY_SEQ") == 1 || rs.wasNull());
@@ -647,11 +632,11 @@ public void exportedKeysTest() throws SQLException {
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString("PKTABLE_CAT"));
- assertEquals(null, rs.getString("PKTABLE_SCHEM"));
+ assertNull(rs.getString("PKTABLE_SCHEM"));
assertEquals("cross2", rs.getString("PKTABLE_NAME"));
assertEquals("id2", rs.getString("PKCOLUMN_NAME"));
assertEquals(sharedConn.getCatalog(), rs.getString("FKTABLE_CAT"));
- assertEquals(null, rs.getString("FKTABLE_SCHEM"));
+ assertNull(rs.getString("FKTABLE_SCHEM"));
assertEquals("cross3", rs.getString("FKTABLE_NAME"));
assertEquals("id_ref2", rs.getString("FKCOLUMN_NAME"));
assertTrue(rs.getInt("KEY_SEQ") == 2 || rs.wasNull());
@@ -754,8 +739,8 @@ public void importedKeysTest() throws SQLException {
"create table fore_key0 (id int not null primary key, "
+ "id_ref0 int, foreign key (id_ref0) references prim_key(id)) engine=innodb");
stmt.execute(
- "create table fore_key1 (id int not null primary key, "
- + "id_ref1 int, foreign key (id_ref1) references prim_key(id) on update cascade) engine=innodb");
+ "create table fore_key1 (id int not null primary key, id_ref1 int, foreign key (id_ref1)"
+ + " references prim_key(id) on update cascade) engine=innodb");
DatabaseMetaData dbmd = sharedConn.getMetaData();
ResultSet rs = dbmd.getImportedKeys(sharedConn.getCatalog(), null, "fore_key0");
@@ -809,25 +794,25 @@ public void testGetTables() throws SQLException {
"create table fore_key0 (id int not null primary key, "
+ "id_ref0 int, foreign key (id_ref0) references prim_key(id)) engine=innodb");
stmt.execute(
- "create table fore_key1 (id int not null primary key, "
- + "id_ref1 int, foreign key (id_ref1) references prim_key(id) on update cascade) engine=innodb");
+ "create table fore_key1 (id int not null primary key, id_ref1 int, foreign key (id_ref1)"
+ + " references prim_key(id) on update cascade) engine=innodb");
DatabaseMetaData dbmd = sharedConn.getMetaData();
ResultSet rs = dbmd.getTables(null, null, "prim_key", null);
- assertEquals(true, rs.next());
+ assertTrue(rs.next());
rs = dbmd.getTables("", null, "prim_key", null);
- assertEquals(true, rs.next());
+ assertTrue(rs.next());
rs = dbmd.getTables("", null, "prim_key", new String[] {"BASE TABLE", "OTHER"});
- assertEquals(true, rs.next());
+ assertTrue(rs.next());
rs = dbmd.getTables("", null, "prim_key", new String[] {"TABLE", null});
- assertEquals(true, rs.next());
+ assertTrue(rs.next());
// ensure no regression CONJ-921
rs = dbmd.getTables(null, null, null, new String[] {"TABLE"});
- assertEquals(true, rs.next());
+ assertTrue(rs.next());
}
@Test
@@ -837,10 +822,10 @@ public void testGetTables2() throws SQLException {
ResultSet rs =
dbmd.getTables(
"information_schema", null, "TABLE_PRIVILEGES", new String[] {"SYSTEM VIEW"});
- assertEquals(true, rs.next());
- assertEquals(false, rs.next());
+ assertTrue(rs.next());
+ assertFalse(rs.next());
rs = dbmd.getTables(null, null, "TABLE_PRIVILEGES", new String[] {"TABLE"});
- assertEquals(false, rs.next());
+ assertFalse(rs.next());
}
@Test
@@ -848,13 +833,13 @@ public void testGetTablesSystemVersionTables() throws SQLException {
Assumptions.assumeTrue(isMariaDBServer() && minVersion(10, 3, 4));
DatabaseMetaData dbmd = sharedConn.getMetaData();
ResultSet rs = dbmd.getTables(null, null, "versionTable", null);
- assertEquals(true, rs.next());
- assertEquals(false, rs.next());
+ assertTrue(rs.next());
+ assertFalse(rs.next());
rs = dbmd.getTables(null, null, "versionTable", new String[] {"TABLE"});
- assertEquals(true, rs.next());
- assertEquals(false, rs.next());
+ assertTrue(rs.next());
+ assertFalse(rs.next());
rs = dbmd.getTables(null, null, "versionTable", new String[] {"SYSTEM VIEW"});
- assertEquals(false, rs.next());
+ assertFalse(rs.next());
}
@Test
@@ -869,7 +854,7 @@ public void testGetTables3() throws SQLException {
DatabaseMetaData dbmd = sharedConn.getMetaData();
ResultSet tableSet = dbmd.getTables(null, null, "table_type_test", null);
- assertEquals(true, tableSet.next());
+ assertTrue(tableSet.next());
String tableName = tableSet.getString("TABLE_NAME");
assertEquals("table_type_test", tableName);
@@ -890,14 +875,16 @@ public void testGetColumns() throws SQLException {
Statement stmt = sharedConn.createStatement();
if (minVersion(10, 2, 0) || !isMariaDBServer()) {
stmt.execute(
- "CREATE TABLE IF NOT EXISTS `ta\nble'getcolumns`("
- + "a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT AS (CHAR_LENGTH(b)) VIRTUAL, "
- + "d VARCHAR(5) AS (left(b,5)) STORED) CHARACTER SET 'utf8mb4'");
+ "CREATE TABLE IF NOT EXISTS `ta\n"
+ + "ble'getcolumns`(a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT AS"
+ + " (CHAR_LENGTH(b)) VIRTUAL, d VARCHAR(5) AS (left(b,5)) STORED) CHARACTER SET"
+ + " 'utf8mb4'");
} else {
stmt.execute(
- "CREATE TABLE IF NOT EXISTS `ta\nble'getcolumns`("
- + "a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT AS (CHAR_LENGTH(b)) VIRTUAL, "
- + "d VARCHAR(5) AS (left(b,5)) PERSISTENT) CHARACTER SET 'utf8mb4'");
+ "CREATE TABLE IF NOT EXISTS `ta\n"
+ + "ble'getcolumns`(a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT AS"
+ + " (CHAR_LENGTH(b)) VIRTUAL, d VARCHAR(5) AS (left(b,5)) PERSISTENT) CHARACTER SET"
+ + " 'utf8mb4'");
}
DatabaseMetaData dbmd = sharedConn.getMetaData();
@@ -905,7 +892,7 @@ public void testGetColumns() throws SQLException {
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString(1)); // TABLE_CAT
- assertEquals(null, rs.getString(2)); // TABLE_SCHEM
+ assertNull(rs.getString(2)); // TABLE_SCHEM
assertEquals("ta\nble'getcolumns", rs.getString(3)); // TABLE_NAME
assertEquals("a", rs.getString(4)); // COLUMN_NAME
assertEquals(Types.INTEGER, rs.getInt(5)); // DATA_TYPE
@@ -915,20 +902,20 @@ public void testGetColumns() throws SQLException {
assertEquals(10, rs.getInt(10)); // NUM_PREC_RADIX
assertEquals(0, rs.getInt(11)); // NULLABLE
assertEquals("", rs.getString(12)); // REMARKS
- assertEquals(null, rs.getString(13)); // COLUMN_DEF
+ assertNull(rs.getString(13)); // COLUMN_DEF
assertEquals(0, rs.getInt(16)); // CHAR_OCTET_LENGTH
assertEquals(1, rs.getInt(17)); // ORDINAL_POSITION
assertEquals("NO", rs.getString(18)); // IS_NULLABLE
- assertEquals(null, rs.getString(19)); // SCOPE_CATALOG
- assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA
- assertEquals(null, rs.getString(21)); // SCOPE_TABLE
+ assertNull(rs.getString(19)); // SCOPE_CATALOG
+ assertNull(rs.getString(20)); // SCOPE_SCHEMA
+ assertNull(rs.getString(21)); // SCOPE_TABLE
assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE
assertEquals("YES", rs.getString(23)); // IS_AUTOINCREMENT
assertEquals("NO", rs.getString(24)); // IS_GENERATEDCOLUMN
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString(1)); // TABLE_CAT
- assertEquals(null, rs.getString(2)); // TABLE_SCHEM
+ assertNull(rs.getString(2)); // TABLE_SCHEM
assertEquals("ta\nble'getcolumns", rs.getString(3)); // TABLE_NAME
assertEquals("b", rs.getString(4)); // COLUMN_NAME
assertEquals(Types.VARCHAR, rs.getInt(5)); // DATA_TYPE
@@ -945,16 +932,16 @@ public void testGetColumns() throws SQLException {
assertEquals(32 * 4, rs.getInt(16)); // CHAR_OCTET_LENGTH
assertEquals(2, rs.getInt(17)); // ORDINAL_POSITION
assertEquals("YES", rs.getString(18)); // IS_NULLABLE
- assertEquals(null, rs.getString(19)); // SCOPE_CATALOG
- assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA
- assertEquals(null, rs.getString(21)); // SCOPE_TABLE
+ assertNull(rs.getString(19)); // SCOPE_CATALOG
+ assertNull(rs.getString(20)); // SCOPE_SCHEMA
+ assertNull(rs.getString(21)); // SCOPE_TABLE
assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE
assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT
assertEquals("NO", rs.getString(24)); // IS_GENERATEDCOLUMN
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString(1)); // TABLE_CAT
- assertEquals(null, rs.getString(2)); // TABLE_SCHEM
+ assertNull(rs.getString(2)); // TABLE_SCHEM
assertEquals("ta\nble'getcolumns", rs.getString(3)); // TABLE_NAME
assertEquals("c", rs.getString(4)); // COLUMN_NAME
assertEquals(Types.INTEGER, rs.getInt(5)); // DATA_TYPE
@@ -972,16 +959,16 @@ public void testGetColumns() throws SQLException {
assertEquals(0, rs.getInt(16)); // CHAR_OCTET_LENGTH
assertEquals(3, rs.getInt(17)); // ORDINAL_POSITION
assertEquals("YES", rs.getString(18)); // IS_NULLABLE
- assertEquals(null, rs.getString(19)); // SCOPE_CATALOG
- assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA
- assertEquals(null, rs.getString(21)); // SCOPE_TABLE
+ assertNull(rs.getString(19)); // SCOPE_CATALOG
+ assertNull(rs.getString(20)); // SCOPE_SCHEMA
+ assertNull(rs.getString(21)); // SCOPE_TABLE
assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE
assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT
assertEquals("YES", rs.getString(24)); // IS_GENERATEDCOLUMN
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString(1)); // TABLE_CAT
- assertEquals(null, rs.getString(2)); // TABLE_SCHEM
+ assertNull(rs.getString(2)); // TABLE_SCHEM
assertEquals("ta\nble'getcolumns", rs.getString(3)); // TABLE_NAME
assertEquals("d", rs.getString(4)); // COLUMN_NAME
assertEquals(Types.VARCHAR, rs.getInt(5)); // DATA_TYPE
@@ -997,9 +984,9 @@ public void testGetColumns() throws SQLException {
assertEquals(5 * 4, rs.getInt(16)); // CHAR_OCTET_LENGTH
assertEquals(4, rs.getInt(17)); // ORDINAL_POSITION
assertEquals("YES", rs.getString(18)); // IS_NULLABLE
- assertEquals(null, rs.getString(19)); // SCOPE_CATALOG
- assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA
- assertEquals(null, rs.getString(21)); // SCOPE_TABLE
+ assertNull(rs.getString(19)); // SCOPE_CATALOG
+ assertNull(rs.getString(20)); // SCOPE_SCHEMA
+ assertNull(rs.getString(21)); // SCOPE_TABLE
assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE
assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT
assertEquals("YES", rs.getString(24)); // IS_GENERATEDCOLUMN
@@ -1019,14 +1006,16 @@ public void testGetColumnsSchema() throws SQLException {
stmt.execute(
"CREATE TABLE IF NOT EXISTS "
+ database
- + ".`ta\nble'getcolumns`("
- + "a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT AS (CHAR_LENGTH(b)) VIRTUAL, "
- + "d VARCHAR(5) AS (left(b,5)) STORED) CHARACTER SET 'utf8mb4'");
+ + ".`ta\n"
+ + "ble'getcolumns`(a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT"
+ + " AS (CHAR_LENGTH(b)) VIRTUAL, d VARCHAR(5) AS (left(b,5)) STORED) CHARACTER SET"
+ + " 'utf8mb4'");
} else {
stmt.execute(
- "CREATE TABLE IF NOT EXISTS \"+database+\".`ta\nble'getcolumns`("
- + "a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT AS (CHAR_LENGTH(b)) VIRTUAL, "
- + "d VARCHAR(5) AS (left(b,5)) PERSISTENT) CHARACTER SET 'utf8mb4'");
+ "CREATE TABLE IF NOT EXISTS \"+database+\".`ta\n"
+ + "ble'getcolumns`(a INT NOT NULL primary key auto_increment, b VARCHAR(32), c INT"
+ + " AS (CHAR_LENGTH(b)) VIRTUAL, d VARCHAR(5) AS (left(b,5)) PERSISTENT) CHARACTER"
+ + " SET 'utf8mb4'");
}
DatabaseMetaData dbmd = con.getMetaData();
@@ -1044,13 +1033,13 @@ public void testGetColumnsSchema() throws SQLException {
assertEquals(10, rs.getInt(10)); // NUM_PREC_RADIX
assertEquals(0, rs.getInt(11)); // NULLABLE
assertEquals("", rs.getString(12)); // REMARKS
- assertEquals(null, rs.getString(13)); // COLUMN_DEF
+ assertNull(rs.getString(13)); // COLUMN_DEF
assertEquals(0, rs.getInt(16)); // CHAR_OCTET_LENGTH
assertEquals(1, rs.getInt(17)); // ORDINAL_POSITION
assertEquals("NO", rs.getString(18)); // IS_NULLABLE
- assertEquals(null, rs.getString(19)); // SCOPE_CATALOG
- assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA
- assertEquals(null, rs.getString(21)); // SCOPE_TABLE
+ assertNull(rs.getString(19)); // SCOPE_CATALOG
+ assertNull(rs.getString(20)); // SCOPE_SCHEMA
+ assertNull(rs.getString(21)); // SCOPE_TABLE
assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE
assertEquals("YES", rs.getString(23)); // IS_AUTOINCREMENT
assertEquals("NO", rs.getString(24)); // IS_GENERATEDCOLUMN
@@ -1075,9 +1064,9 @@ public void testGetColumnsSchema() throws SQLException {
assertEquals(32 * 4, rs.getInt(16)); // CHAR_OCTET_LENGTH
assertEquals(2, rs.getInt(17)); // ORDINAL_POSITION
assertEquals("YES", rs.getString(18)); // IS_NULLABLE
- assertEquals(null, rs.getString(19)); // SCOPE_CATALOG
- assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA
- assertEquals(null, rs.getString(21)); // SCOPE_TABLE
+ assertNull(rs.getString(19)); // SCOPE_CATALOG
+ assertNull(rs.getString(20)); // SCOPE_SCHEMA
+ assertNull(rs.getString(21)); // SCOPE_TABLE
assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE
assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT
assertEquals("NO", rs.getString(24)); // IS_GENERATEDCOLUMN
@@ -1103,9 +1092,9 @@ public void testGetColumnsSchema() throws SQLException {
assertEquals(0, rs.getInt(16)); // CHAR_OCTET_LENGTH
assertEquals(3, rs.getInt(17)); // ORDINAL_POSITION
assertEquals("YES", rs.getString(18)); // IS_NULLABLE
- assertEquals(null, rs.getString(19)); // SCOPE_CATALOG
- assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA
- assertEquals(null, rs.getString(21)); // SCOPE_TABLE
+ assertNull(rs.getString(19)); // SCOPE_CATALOG
+ assertNull(rs.getString(20)); // SCOPE_SCHEMA
+ assertNull(rs.getString(21)); // SCOPE_TABLE
assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE
assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT
assertEquals("YES", rs.getString(24)); // IS_GENERATEDCOLUMN
@@ -1129,9 +1118,9 @@ public void testGetColumnsSchema() throws SQLException {
assertEquals(5 * 4, rs.getInt(16)); // CHAR_OCTET_LENGTH
assertEquals(4, rs.getInt(17)); // ORDINAL_POSITION
assertEquals("YES", rs.getString(18)); // IS_NULLABLE
- assertEquals(null, rs.getString(19)); // SCOPE_CATALOG
- assertEquals(null, rs.getString(20)); // SCOPE_SCHEMA
- assertEquals(null, rs.getString(21)); // SCOPE_TABLE
+ assertNull(rs.getString(19)); // SCOPE_CATALOG
+ assertNull(rs.getString(20)); // SCOPE_SCHEMA
+ assertNull(rs.getString(21)); // SCOPE_TABLE
assertEquals(0, rs.getShort(22)); // SOURCE_DATA_TYPE
assertEquals("NO", rs.getString(23)); // IS_AUTOINCREMENT
assertEquals("YES", rs.getString(24)); // IS_GENERATEDCOLUMN
@@ -1294,8 +1283,9 @@ private void testResultSetColumns(ResultSet rs, String spec) throws SQLException
+ ",expected String");
break;
case "decimal":
- assertTrue(
- columnType == Types.DECIMAL,
+ assertEquals(
+ Types.DECIMAL,
+ columnType,
"invalid type "
+ columnType
+ "( "
@@ -1333,8 +1323,9 @@ private void testResultSetColumns(ResultSet rs, String spec) throws SQLException
break;
case "null":
- assertTrue(
- columnType == Types.NULL,
+ assertEquals(
+ Types.NULL,
+ columnType,
"invalid type "
+ columnType
+ " for "
@@ -1369,12 +1360,11 @@ public void getSchemas() throws SQLException {
public void getAttributesBasic() throws Exception {
testResultSetColumns(
sharedConn.getMetaData().getAttributes(null, null, null, null),
- "TYPE_CAT String,TYPE_SCHEM String,TYPE_NAME String,"
- + "ATTR_NAME String,DATA_TYPE int,ATTR_TYPE_NAME String,ATTR_SIZE int,DECIMAL_DIGITS int,"
- + "NUM_PREC_RADIX int,NULLABLE int,REMARKS String,ATTR_DEF String,SQL_DATA_TYPE int,"
- + "SQL_DATETIME_SUB int, CHAR_OCTET_LENGTH int,ORDINAL_POSITION int,IS_NULLABLE String,"
- + "SCOPE_CATALOG String,SCOPE_SCHEMA String,"
- + "SCOPE_TABLE String,SOURCE_DATA_TYPE short");
+ "TYPE_CAT String,TYPE_SCHEM String,TYPE_NAME String,ATTR_NAME String,DATA_TYPE"
+ + " int,ATTR_TYPE_NAME String,ATTR_SIZE int,DECIMAL_DIGITS int,NUM_PREC_RADIX"
+ + " int,NULLABLE int,REMARKS String,ATTR_DEF String,SQL_DATA_TYPE int,SQL_DATETIME_SUB"
+ + " int, CHAR_OCTET_LENGTH int,ORDINAL_POSITION int,IS_NULLABLE String,SCOPE_CATALOG"
+ + " String,SCOPE_SCHEMA String,SCOPE_TABLE String,SOURCE_DATA_TYPE short");
}
@Test
@@ -1579,8 +1569,9 @@ public void getClientInfoPropertiesBasic() throws Exception {
assertEquals(0x00ffffff, rs.getInt(2));
assertEquals("", rs.getString(3));
assertEquals(
- "The name of the user that the application using the connection is performing work for. "
- + "This may not be the same as the user name that was used in establishing the connection.",
+ "The name of the user that the application using the connection is performing work for."
+ + " This may not be the same as the user name that was used in establishing the"
+ + " connection.",
rs.getString(4));
assertTrue(rs.next());
@@ -1633,11 +1624,11 @@ public void getProcedureColumnsBasic() throws SQLException {
Assumptions.assumeTrue(!isXpand());
testResultSetColumns(
sharedConn.getMetaData().getProcedureColumns(null, null, null, null),
- "PROCEDURE_CAT String,PROCEDURE_SCHEM String,PROCEDURE_NAME String,COLUMN_NAME String ,"
- + "COLUMN_TYPE short,DATA_TYPE int,TYPE_NAME String,PRECISION int,LENGTH int,SCALE short,"
- + "RADIX short,NULLABLE short,REMARKS String,COLUMN_DEF String,SQL_DATA_TYPE int,"
- + "SQL_DATETIME_SUB int ,CHAR_OCTET_LENGTH int,"
- + "ORDINAL_POSITION int,IS_NULLABLE String,SPECIFIC_NAME String");
+ "PROCEDURE_CAT String,PROCEDURE_SCHEM String,PROCEDURE_NAME String,COLUMN_NAME String"
+ + " ,COLUMN_TYPE short,DATA_TYPE int,TYPE_NAME String,PRECISION int,LENGTH int,SCALE"
+ + " short,RADIX short,NULLABLE short,REMARKS String,COLUMN_DEF String,SQL_DATA_TYPE"
+ + " int,SQL_DATETIME_SUB int ,CHAR_OCTET_LENGTH int,ORDINAL_POSITION int,IS_NULLABLE"
+ + " String,SPECIFIC_NAME String");
}
@Test
@@ -1646,10 +1637,10 @@ public void getFunctionColumnsBasic() throws SQLException {
Assumptions.assumeFalse(isXpand());
testResultSetColumns(
sharedConn.getMetaData().getFunctionColumns(null, null, null, null),
- "FUNCTION_CAT String,FUNCTION_SCHEM String,FUNCTION_NAME String,COLUMN_NAME String,COLUMN_TYPE short,"
- + "DATA_TYPE int,TYPE_NAME String,PRECISION int,LENGTH int,SCALE short,RADIX short,"
- + "NULLABLE short,REMARKS String,CHAR_OCTET_LENGTH int,ORDINAL_POSITION int,"
- + "IS_NULLABLE String,SPECIFIC_NAME String");
+ "FUNCTION_CAT String,FUNCTION_SCHEM String,FUNCTION_NAME String,COLUMN_NAME"
+ + " String,COLUMN_TYPE short,DATA_TYPE int,TYPE_NAME String,PRECISION int,LENGTH"
+ + " int,SCALE short,RADIX short,NULLABLE short,REMARKS String,CHAR_OCTET_LENGTH"
+ + " int,ORDINAL_POSITION int,IS_NULLABLE String,SPECIFIC_NAME String");
}
@Test
@@ -1686,7 +1677,8 @@ public void getVersionColumnsBasic() throws SQLException {
public void getPrimaryKeysBasic() throws SQLException {
testResultSetColumns(
sharedConn.getMetaData().getPrimaryKeys(null, null, null),
- "TABLE_CAT String,TABLE_SCHEM String,TABLE_NAME String,COLUMN_NAME String,KEY_SEQ short,PK_NAME String");
+ "TABLE_CAT String,TABLE_SCHEM String,TABLE_NAME String,COLUMN_NAME String,KEY_SEQ"
+ + " short,PK_NAME String");
}
@Test
@@ -1694,9 +1686,10 @@ public void getImportedKeysBasic() throws SQLException {
Assumptions.assumeFalse(isXpand());
testResultSetColumns(
sharedConn.getMetaData().getImportedKeys(null, null, ""),
- "PKTABLE_CAT String,PKTABLE_SCHEM String,PKTABLE_NAME String, PKCOLUMN_NAME String,FKTABLE_CAT String,"
- + "FKTABLE_SCHEM String,FKTABLE_NAME String,FKCOLUMN_NAME String,KEY_SEQ short,"
- + "UPDATE_RULE short,DELETE_RULE short,FK_NAME String,PK_NAME String,DEFERRABILITY short");
+ "PKTABLE_CAT String,PKTABLE_SCHEM String,PKTABLE_NAME String, PKCOLUMN_NAME"
+ + " String,FKTABLE_CAT String,FKTABLE_SCHEM String,FKTABLE_NAME String,FKCOLUMN_NAME"
+ + " String,KEY_SEQ short,UPDATE_RULE short,DELETE_RULE short,FK_NAME String,PK_NAME"
+ + " String,DEFERRABILITY short");
}
@Test
@@ -1704,9 +1697,10 @@ public void getExportedKeysBasic() throws SQLException {
Assumptions.assumeFalse(isXpand());
testResultSetColumns(
sharedConn.getMetaData().getExportedKeys(null, null, ""),
- "PKTABLE_CAT String,PKTABLE_SCHEM String,PKTABLE_NAME String, PKCOLUMN_NAME String,FKTABLE_CAT String,"
- + "FKTABLE_SCHEM String,FKTABLE_NAME String,FKCOLUMN_NAME String,KEY_SEQ short,"
- + "UPDATE_RULE short, DELETE_RULE short,FK_NAME String,PK_NAME String,DEFERRABILITY short");
+ "PKTABLE_CAT String,PKTABLE_SCHEM String,PKTABLE_NAME String, PKCOLUMN_NAME"
+ + " String,FKTABLE_CAT String,FKTABLE_SCHEM String,FKTABLE_NAME String,FKCOLUMN_NAME"
+ + " String,KEY_SEQ short,UPDATE_RULE short, DELETE_RULE short,FK_NAME String,PK_NAME"
+ + " String,DEFERRABILITY short");
}
@Test
@@ -1714,9 +1708,10 @@ public void getCrossReferenceBasic() throws SQLException {
Assumptions.assumeFalse(isXpand());
testResultSetColumns(
sharedConn.getMetaData().getCrossReference(null, null, "", null, null, ""),
- "PKTABLE_CAT String,PKTABLE_SCHEM String,PKTABLE_NAME String, PKCOLUMN_NAME String,FKTABLE_CAT String,"
- + "FKTABLE_SCHEM String,FKTABLE_NAME String,FKCOLUMN_NAME String,KEY_SEQ short,"
- + "UPDATE_RULE short,DELETE_RULE short,FK_NAME String,PK_NAME String,DEFERRABILITY short");
+ "PKTABLE_CAT String,PKTABLE_SCHEM String,PKTABLE_NAME String, PKCOLUMN_NAME"
+ + " String,FKTABLE_CAT String,FKTABLE_SCHEM String,FKTABLE_NAME String,FKCOLUMN_NAME"
+ + " String,KEY_SEQ short,UPDATE_RULE short,DELETE_RULE short,FK_NAME String,PK_NAME"
+ + " String,DEFERRABILITY short");
}
@Test
@@ -1726,11 +1721,11 @@ public void getCrossReferenceResults() throws SQLException {
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString(1));
- assertEquals(null, rs.getString(2));
+ assertNull(rs.getString(2));
assertEquals("cross1", rs.getString(3));
assertEquals("id", rs.getString(4));
assertEquals(sharedConn.getCatalog(), rs.getString(5));
- assertEquals(null, rs.getString(6));
+ assertNull(rs.getString(6));
assertEquals("cross2", rs.getString(7));
assertEquals("id_ref0", rs.getString(8));
assertTrue(rs.getInt(9) == 1 || rs.wasNull());
@@ -1745,11 +1740,11 @@ public void getCrossReferenceResults() throws SQLException {
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString(1));
- assertEquals(null, rs.getString(2));
+ assertNull(rs.getString(2));
assertEquals("cross2", rs.getString(3));
assertEquals("id", rs.getString(4));
assertEquals(sharedConn.getCatalog(), rs.getString(5));
- assertEquals(null, rs.getString(6));
+ assertNull(rs.getString(6));
assertEquals("cross3", rs.getString(7));
assertEquals("id_ref1", rs.getString(8));
assertTrue(rs.getInt(9) == 1 || rs.wasNull());
@@ -1765,11 +1760,11 @@ public void getCrossReferenceResults() throws SQLException {
assertTrue(rs.next());
assertEquals(sharedConn.getCatalog(), rs.getString(1));
- assertEquals(null, rs.getString(2));
+ assertNull(rs.getString(2));
assertEquals("cross2", rs.getString(3));
assertEquals("id2", rs.getString(4));
assertEquals(sharedConn.getCatalog(), rs.getString(5));
- assertEquals(null, rs.getString(6));
+ assertNull(rs.getString(6));
assertEquals("cross3", rs.getString(7));
assertEquals("id_ref2", rs.getString(8));
assertTrue(rs.getInt(9) == 2 || rs.wasNull());
@@ -1871,8 +1866,8 @@ public void getSuperTypesBasic() throws SQLException {
public void getFunctionsBasic() throws SQLException {
testResultSetColumns(
sharedConn.getMetaData().getFunctions(null, null, null),
- "FUNCTION_CAT String, FUNCTION_SCHEM String,FUNCTION_NAME String,REMARKS String,FUNCTION_TYPE short, "
- + "SPECIFIC_NAME String");
+ "FUNCTION_CAT String, FUNCTION_SCHEM String,FUNCTION_NAME String,REMARKS"
+ + " String,FUNCTION_TYPE short, SPECIFIC_NAME String");
}
@Test
@@ -1892,7 +1887,7 @@ public void testGetSchemas2() throws SQLException {
foundTestUnitsJdbc = true;
}
}
- assertEquals(true, foundTestUnitsJdbc);
+ assertTrue(foundTestUnitsJdbc);
try (Connection con = createCon("&useCatalogTerm=Schema")) {
dbmd = con.getMetaData();
rs = dbmd.getCatalogs();
@@ -1911,11 +1906,11 @@ public void testGetTypeInfoBasic() throws SQLException {
testResultSetColumns(
rs,
- "TYPE_NAME String,DATA_TYPE int,PRECISION int,LITERAL_PREFIX String,"
- + "LITERAL_SUFFIX String,CREATE_PARAMS String, NULLABLE short,CASE_SENSITIVE boolean,"
- + "SEARCHABLE short,UNSIGNED_ATTRIBUTE boolean,FIXED_PREC_SCALE boolean, "
- + "AUTO_INCREMENT boolean, LOCAL_TYPE_NAME String,MINIMUM_SCALE short,MAXIMUM_SCALE short,"
- + "SQL_DATA_TYPE int,SQL_DATETIME_SUB int, NUM_PREC_RADIX int");
+ "TYPE_NAME String,DATA_TYPE int,PRECISION int,LITERAL_PREFIX String,LITERAL_SUFFIX"
+ + " String,CREATE_PARAMS String, NULLABLE short,CASE_SENSITIVE boolean,SEARCHABLE"
+ + " short,UNSIGNED_ATTRIBUTE boolean,FIXED_PREC_SCALE boolean, AUTO_INCREMENT boolean,"
+ + " LOCAL_TYPE_NAME String,MINIMUM_SCALE short,MAXIMUM_SCALE short,SQL_DATA_TYPE"
+ + " int,SQL_DATETIME_SUB int, NUM_PREC_RADIX int");
}
@Test
@@ -2581,7 +2576,7 @@ public void testMetaCatalog() throws Exception {
// test without catalog
rs = meta.getProcedures(null, null, "testMetaCatalog");
assertTrue(rs.next());
- assertTrue("testMetaCatalog".equals(rs.getString(3)));
+ assertEquals("testMetaCatalog", rs.getString(3));
assertFalse(rs.next());
}
@@ -2609,7 +2604,7 @@ public void testMetaCatalogSchema() throws Exception {
// test without catalog
rs = meta.getProcedures(null, null, "testMetaCatalog");
assertTrue(rs.next());
- assertTrue("testMetaCatalog".equals(rs.getString(3)));
+ assertEquals("testMetaCatalog", rs.getString(3));
assertFalse(rs.next());
}
}
@@ -2722,4 +2717,58 @@ public void foreignKeyTest() throws SQLException {
}
}
}
+
+
+ @Test
+ public void testTemporaryTables() throws SQLException {
+ Assumptions.assumeTrue(isMariaDBServer() && minVersion(11,2,0));
+ Assumptions.assumeTrue(
+ !"mariadb-es".equals(System.getenv("srv"))
+ && !"mariadb-es-test".equals(System.getenv("srv")));
+
+ java.sql.Statement stmt = sharedConn.createStatement();
+ stmt.execute("create temporary table testTemporaryTables (b int)");
+ try (Connection con = createCon()) {
+ java.sql.Statement ss = con.createStatement();
+ ResultSet rr = ss.executeQuery("select table_schema, table_name, table_type, temporary " +
+ "from information_schema.tables " +
+ "where TABLE_NAME = 'testTemporaryTables'");
+ assertFalse(rr.next());
+ }
+ DatabaseMetaData dbmd = sharedConn.getMetaData();
+
+ ResultSet rs = dbmd.getTables(null, null, "testTemporary%", null);
+ assertTrue(rs.next());
+ assertEquals("testtemporarytables",rs.getString("TABLE_NAME").toLowerCase());
+ assertEquals("LOCAL TEMPORARY", rs.getString("TABLE_TYPE"));
+ assertFalse(rs.next());
+
+ rs = dbmd.getTables(null, null, "testTemporary%", new String[]{"LOCAL TEMPORARY"});
+ assertTrue(rs.next());
+ assertEquals("testtemporarytables",rs.getString("TABLE_NAME").toLowerCase());
+ assertEquals("LOCAL TEMPORARY", rs.getString("TABLE_TYPE"));
+ assertFalse(rs.next());
+
+ rs = dbmd.getTables(null, null, "testTemporary%", new String[]{"TEMPORARY"});
+ assertTrue(rs.next());
+ assertEquals("testtemporarytables",rs.getString("TABLE_NAME").toLowerCase());
+ assertEquals("LOCAL TEMPORARY", rs.getString("TABLE_TYPE"));
+ assertFalse(rs.next());
+
+ rs = dbmd.getTables(null, null, "testTemporary%", new String[]{"TABLE"});
+ assertFalse(rs.next());
+
+ rs = dbmd.getTables(null, null, "testTemporary%", new String[]{"TEMPORARY", "TABLE"});
+ assertTrue(rs.next());
+ assertEquals("testtemporarytables",rs.getString("TABLE_NAME").toLowerCase());
+ assertEquals("LOCAL TEMPORARY", rs.getString("TABLE_TYPE"));
+ assertFalse(rs.next());
+
+ rs = dbmd.getTables(null, null, "testTemporary%", new String[]{"TEMPORARY", null, "TABLE"});
+ assertTrue(rs.next());
+ assertEquals("testtemporarytables",rs.getString("TABLE_NAME").toLowerCase());
+ assertEquals("LOCAL TEMPORARY", rs.getString("TABLE_TYPE"));
+ assertFalse(rs.next());
+ }
+
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/DriverTest.java b/src/test/java/org/mariadb/jdbc/integration/DriverTest.java
index c1174ce37..91d35646c 100644
--- a/src/test/java/org/mariadb/jdbc/integration/DriverTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/DriverTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/EofTest.java b/src/test/java/org/mariadb/jdbc/integration/EofTest.java
index c2b913401..6be9b63f7 100644
--- a/src/test/java/org/mariadb/jdbc/integration/EofTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/EofTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/ErrorTest.java b/src/test/java/org/mariadb/jdbc/integration/ErrorTest.java
index 25f762213..9b2abc758 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ErrorTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ErrorTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/FailoverTest.java b/src/test/java/org/mariadb/jdbc/integration/FailoverTest.java
index ecdfc4976..3d6a9881b 100644
--- a/src/test/java/org/mariadb/jdbc/integration/FailoverTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/FailoverTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -30,7 +29,6 @@ public void simpleFailoverTransactionReplay() throws SQLException {
SQLTransientConnectionException.class,
() -> stmt.execute("SELECT 1"),
"Driver has reconnect connection after a communications link failure");
- ;
Assertions.assertTrue(con.getContext().getThreadId() != threadId);
}
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/FunctionTest.java b/src/test/java/org/mariadb/jdbc/integration/FunctionTest.java
index 49bcc23a3..45a711311 100644
--- a/src/test/java/org/mariadb/jdbc/integration/FunctionTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/FunctionTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -22,7 +21,8 @@ public void basicFunction() throws SQLException {
Statement stmt = sharedConn.createStatement();
stmt.execute("DROP FUNCTION IF EXISTS basic_function");
stmt.execute(
- "CREATE FUNCTION basic_function (t1 INT, t2 INT unsigned) RETURNS INT DETERMINISTIC RETURN t1 * t2;");
+ "CREATE FUNCTION basic_function (t1 INT, t2 INT unsigned) RETURNS INT DETERMINISTIC RETURN"
+ + " t1 * t2;");
try (CallableStatement callableStatement =
sharedConn.prepareCall("{? = call basic_function(?,?)}")) {
callableStatement.registerOutParameter(1, JDBCType.INTEGER);
@@ -41,7 +41,7 @@ public void basicFunction() throws SQLException {
callableStatement.clearParameters();
assertThrowsContains(
SQLTransientConnectionException.class,
- () -> callableStatement.execute(),
+ callableStatement::execute,
"Parameter at position 1 is not set");
}
@@ -167,7 +167,8 @@ public void functionToString() throws SQLException {
callableStatement.setLong(2, 10L);
callableStatement.setBytes(3, new byte[] {(byte) 'a', (byte) 'b'});
assertEquals(
- "FunctionStatement{sql:'SELECT basic_function(?,?)', parameters:[null,10,_binary 'ab']}",
+ "FunctionStatement{sql:'SELECT basic_function(?,?)', parameters:[null,10,_binary"
+ + " 'ab']}",
callableStatement.toString());
}
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/GaleraTest.java b/src/test/java/org/mariadb/jdbc/integration/GaleraTest.java
index e23b85c3d..e331cced5 100644
--- a/src/test/java/org/mariadb/jdbc/integration/GaleraTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/GaleraTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import java.sql.SQLException;
diff --git a/src/test/java/org/mariadb/jdbc/integration/GssapiAuthenticationTest.java b/src/test/java/org/mariadb/jdbc/integration/GssapiAuthenticationTest.java
index bdb468d33..7d3a8d8a2 100644
--- a/src/test/java/org/mariadb/jdbc/integration/GssapiAuthenticationTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/GssapiAuthenticationTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import java.sql.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/LocalInfileTest.java b/src/test/java/org/mariadb/jdbc/integration/LocalInfileTest.java
index bed57d7f8..a262cd668 100644
--- a/src/test/java/org/mariadb/jdbc/integration/LocalInfileTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/LocalInfileTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -11,6 +10,7 @@
import java.util.Locale;
import org.junit.jupiter.api.*;
+@SuppressWarnings("ResultOfMethodCallIgnored")
public class LocalInfileTest extends Common {
@BeforeAll
public static void beforeAll2() throws SQLException {
@@ -22,9 +22,11 @@ public static void beforeAll2() throws SQLException {
stmt.execute("CREATE TABLE ttlocal(id int, test varchar(100))");
stmt.execute("CREATE TABLE ldinfile(a varchar(10))");
stmt.execute(
- "CREATE TABLE `infile`(`a` varchar(50) DEFAULT NULL, `b` varchar(50) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1");
+ "CREATE TABLE `infile`(`a` varchar(50) DEFAULT NULL, `b` varchar(50) DEFAULT NULL)"
+ + " ENGINE=InnoDB DEFAULT CHARSET=latin1");
stmt.execute(
- "CREATE TABLE big_load_data_infile(id int not null primary key auto_increment, name char(20)) ENGINE=myisam");
+ "CREATE TABLE big_load_data_infile(id int not null primary key auto_increment, name"
+ + " char(20)) ENGINE=myisam");
stmt.execute("FLUSH TABLES");
}
@@ -73,38 +75,8 @@ public void bigLoadDataInfileTest() throws SQLException, IOException {
}
}
- /** Custom memory conserving generator of a LOAD DATA INFILE that generates a stream. */
- private static class VeryLongAutoGeneratedInputStream extends InputStream {
-
- private final int numberOfRows;
- private int currentPosInBuffer;
- private byte[] buffer;
- private int currentRow;
-
- private VeryLongAutoGeneratedInputStream(int numberOfRows) {
- this.numberOfRows = numberOfRows;
- currentRow = 0;
- }
-
- @Override
- public int read() {
- if (currentRow > numberOfRows) {
- return -1;
- }
- if (buffer != null && currentPosInBuffer >= buffer.length) {
- buffer = null;
- }
- if (buffer == null) {
- currentRow++;
- currentPosInBuffer = 0;
- buffer = (currentRow + "\tname" + currentRow + "\n").getBytes();
- }
- return buffer[currentPosInBuffer++];
- }
- }
-
@Test
- public void streamInBatch() throws SQLException, IOException {
+ public void streamInBatch() throws SQLException {
Assumptions.assumeFalse((!isMariaDBServer() && minVersion(8, 0, 3)));
Assumptions.assumeTrue(
!"skysql".equals(System.getenv("srv")) && !"skysql-ha".equals(System.getenv("srv")));
@@ -112,10 +84,10 @@ public void streamInBatch() throws SQLException, IOException {
"LOAD DATA LOCAL INFILE 'dummy.tsv' INTO TABLE LocalInfileInputStreamTest2 (id, test)";
String builder = "1\thello\n2\tworld\n";
- Statement stmt = sharedConn.createStatement();
+ org.mariadb.jdbc.Statement stmt = sharedConn.createStatement();
stmt.execute("TRUNCATE LocalInfileInputStreamTest2");
InputStream inputStream = new ByteArrayInputStream(builder.getBytes());
- ((org.mariadb.jdbc.Statement) stmt).setLocalInfileInputStream(inputStream);
+ stmt.setLocalInfileInputStream(inputStream);
stmt.addBatch(batch_update);
stmt.addBatch("SET UNIQUE_CHECKS=1");
stmt.executeBatch();
@@ -128,7 +100,8 @@ public void streamInBatch() throws SQLException, IOException {
try (PreparedStatement prep =
sharedConn.prepareStatement(
- "LOAD DATA LOCAL INFILE 'dummy.tsv' INTO TABLE LocalInfileInputStreamTest2 (id, test)")) {
+ "LOAD DATA LOCAL INFILE 'dummy.tsv' INTO TABLE LocalInfileInputStreamTest2 (id,"
+ + " test)")) {
inputStream = new ByteArrayInputStream(builder.getBytes());
((org.mariadb.jdbc.Statement) prep).setLocalInfileInputStream(inputStream);
prep.addBatch();
@@ -142,7 +115,8 @@ public void streamInBatch() throws SQLException, IOException {
}
try (PreparedStatement prep =
sharedConnBinary.prepareStatement(
- "LOAD DATA LOCAL INFILE 'dummy.tsv' INTO TABLE LocalInfileInputStreamTest2 (id, test)")) {
+ "LOAD DATA LOCAL INFILE 'dummy.tsv' INTO TABLE LocalInfileInputStreamTest2 (id,"
+ + " test)")) {
inputStream = new ByteArrayInputStream(builder.getBytes());
((org.mariadb.jdbc.Statement) prep).setLocalInfileInputStream(inputStream);
prep.addBatch();
@@ -173,8 +147,10 @@ public void throwExceptions() throws Exception {
SQLException.class,
() ->
stmt.execute(
- "LOAD DATA LOCAL INFILE 'someFile' INTO TABLE LocalInfileInputStreamTest2 (id, test)"),
- "Local infile is disabled by connector. Enable `allowLocalInfile` to allow local infile commands");
+ "LOAD DATA LOCAL INFILE 'someFile' INTO TABLE LocalInfileInputStreamTest2 (id,"
+ + " test)"),
+ "Local infile is disabled by connector. Enable `allowLocalInfile` to allow local infile"
+ + " commands");
stmt.addBatch(
"LOAD DATA LOCAL INFILE 'someFile' INTO TABLE LocalInfileInputStreamTest2 (id, test)");
stmt.addBatch("SET UNIQUE_CHECKS=1");
@@ -187,7 +163,8 @@ public void throwExceptions() throws Exception {
assertTrue(
e.getMessage()
.contains(
- "Local infile is disabled by connector. Enable `allowLocalInfile` to allow local infile commands"));
+ "Local infile is disabled by connector. Enable `allowLocalInfile` to allow"
+ + " local infile commands"));
assertNotNull(e.getCause());
assertEquals(e.getCause().getMessage(), e.getMessage());
assertEquals(((SQLException) e.getCause()).getSQLState(), e.getSQLState());
@@ -201,7 +178,8 @@ public void throwExceptions() throws Exception {
Common.assertThrowsContains(
SQLException.class,
prep::execute,
- "Local infile is disabled by connector. Enable `allowLocalInfile` to allow local infile commands");
+ "Local infile is disabled by connector. Enable `allowLocalInfile` to allow local infile"
+ + " commands");
}
}
}
@@ -218,7 +196,8 @@ public void wrongFile() throws Exception {
SQLException.class,
() ->
stmt.execute(
- "LOAD DATA LOCAL INFILE 'someFile' INTO TABLE LocalInfileInputStreamTest2 (id, test)"),
+ "LOAD DATA LOCAL INFILE 'someFile' INTO TABLE LocalInfileInputStreamTest2 (id,"
+ + " test)"),
"Could not send file : someFile");
assertTrue(con.isValid(1));
}
@@ -381,13 +360,15 @@ public void loadDataValidationFails(boolean prepStmt) throws Exception {
}
try (PreparedStatement prep =
con.prepareStatement(
- "/* test */ LOAD DATA LOCAL INFILE 'j' INTO TABLE LocalInfileInputStreamTest2 (id, test)")) {
+ "/* test */ LOAD DATA LOCAL INFILE 'j' INTO TABLE LocalInfileInputStreamTest2 (id,"
+ + " test)")) {
assertThrowsContains(SQLException.class, () -> prep.execute(), "Could not send file : j");
}
// special test comment inside LOAD DATA LOCAL are not checked, resulting in error
try (PreparedStatement prep =
con.prepareStatement(
- "LOAD /**g*/ DATA LOCAL INFILE 'h' INTO TABLE LocalInfileInputStreamTest2 (id, test)")) {
+ "LOAD /**g*/ DATA LOCAL INFILE 'h' INTO TABLE LocalInfileInputStreamTest2 (id,"
+ + " test)")) {
assertThrowsContains(
SQLException.class,
() -> prep.execute(),
@@ -500,4 +481,34 @@ public void testMoreThanMaxAllowedPacketLocalInfileInputStream() throws Exceptio
Assumptions.assumeTrue(maxAllowedPacket < 100_000_000);
checkBigLocalInfile(maxAllowedPacket + 1024);
}
+
+ /** Custom memory conserving generator of a LOAD DATA INFILE that generates a stream. */
+ private static class VeryLongAutoGeneratedInputStream extends InputStream {
+
+ private final int numberOfRows;
+ private int currentPosInBuffer;
+ private byte[] buffer;
+ private int currentRow;
+
+ private VeryLongAutoGeneratedInputStream(int numberOfRows) {
+ this.numberOfRows = numberOfRows;
+ currentRow = 0;
+ }
+
+ @Override
+ public int read() {
+ if (currentRow > numberOfRows) {
+ return -1;
+ }
+ if (buffer != null && currentPosInBuffer >= buffer.length) {
+ buffer = null;
+ }
+ if (buffer == null) {
+ currentRow++;
+ currentPosInBuffer = 0;
+ buffer = (currentRow + "\tname" + currentRow + "\n").getBytes();
+ }
+ return buffer[currentPosInBuffer++];
+ }
+ }
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/LoggingTest.java b/src/test/java/org/mariadb/jdbc/integration/LoggingTest.java
index e1e20318c..7070e2340 100644
--- a/src/test/java/org/mariadb/jdbc/integration/LoggingTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/LoggingTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -155,8 +154,7 @@ void certLogging() throws Exception {
logger.addAppender(fa);
String certString =
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIDfDCCAmSgAwIBAgIURZJQVOWv+oaj+MLlHWc1B0TnOaowDQYJKoZIhvcNAQEL\n"
+ "BQAwUjELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkdEMQswCQYDVQQHDAJTWjESMBAG\n"
+ "A1UECgwJQWNtZSxJbmMuMRUwEwYDVQQDDAxBY21lIFJvb3QgQ0EwIBcNMjEwMzMw\n"
@@ -189,22 +187,22 @@ void certLogging() throws Exception {
verifyExceptionEqual(
"local.host",
cert,
- "DNS host \"local.host\" doesn't correspond to certificate "
- + "CN \"*.mariadb.org\" and SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
+ "DNS host \"local.host\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
HostnameVerifier.verify("127.0.0.1", cert, -1);
verifyExceptionEqual(
"127.0.0.2",
cert,
- "IPv4 host \"127.0.0.2\" doesn't correspond to certificate "
- + "CN \"*.mariadb.org\" and SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
+ "IPv4 host \"127.0.0.2\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
HostnameVerifier.verify("2001:db8:3902:3468:0:0:0:443", cert, -1);
verifyExceptionEqual(
"2001:db8:1::",
cert,
- "IPv6 host \"2001:db8:1::\" doesn't correspond to certificate "
- + "CN \"*.mariadb.org\" and SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
+ "IPv6 host \"2001:db8:1::\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
try {
String contents = new String(Files.readAllBytes(Paths.get(tempFile.getPath())));
@@ -216,7 +214,8 @@ void certLogging() throws Exception {
"IPv4 verification of hostname : type=IP value=127.0.0.1 to 127.0.0.2"));
assertTrue(
contents.contains(
- "IPv6 verification of hostname : type=IP value=2001:db8:3902:3468:0:0:0:443 to 2001:db8:1::"));
+ "IPv6 verification of hostname : type=IP value=2001:db8:3902:3468:0:0:0:443 to"
+ + " 2001:db8:1::"));
logger.setLevel(initialLevel);
logger.detachAppender(fa);
diff --git a/src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java b/src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java
index 5e512e617..c5c9852bd 100644
--- a/src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -271,13 +270,13 @@ public void masterFailover() throws Exception {
con.isValid(1000);
}
- Thread.sleep(100);
+ Thread.sleep(1000);
// same in transaction
try (Connection con =
(Connection)
DriverManager.getConnection(
url
- + "&waitReconnectTimeout=300&retriesAllDown=10&connectTimeout=20&deniedListTimeout=20&socketTimeout=10")) {
+ + "&waitReconnectTimeout=300&retriesAllDown=10&connectTimeout=20&deniedListTimeout=20&socketTimeout=100")) {
Statement stmt = con.createStatement();
stmt.execute("START TRANSACTION");
stmt.execute("SET @con=1");
@@ -314,7 +313,7 @@ public void masterFailover() throws Exception {
assertTrue(e.getMessage().contains("In progress transaction was lost"));
}
}
- Thread.sleep(50);
+ Thread.sleep(100);
// with transaction replay
try (Connection con =
(Connection)
diff --git a/src/test/java/org/mariadb/jdbc/integration/MultiPacketTest.java b/src/test/java/org/mariadb/jdbc/integration/MultiPacketTest.java
index ba1faa494..d5a5f8c8f 100644
--- a/src/test/java/org/mariadb/jdbc/integration/MultiPacketTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/MultiPacketTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/src/test/java/org/mariadb/jdbc/integration/MultiQueriesTest.java b/src/test/java/org/mariadb/jdbc/integration/MultiQueriesTest.java
index fac1f0144..2d9b4d8cb 100644
--- a/src/test/java/org/mariadb/jdbc/integration/MultiQueriesTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/MultiQueriesTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -92,6 +91,7 @@ public void allowMultiQueriesFetchTest() throws SQLException {
}
@Test
+ @SuppressWarnings("try")
public void quitWhileStreaming() throws SQLException {
// XPAND doesn't support DO command
Assumptions.assumeFalse(isXpand());
@@ -100,7 +100,8 @@ public void quitWhileStreaming() throws SQLException {
Statement stmt = connection.createStatement();
stmt.setFetchSize(1);
stmt.executeQuery(
- "DO 2;SELECT * from AllowMultiQueriesTest;SELECT * from AllowMultiQueriesTest; DO 1; SELECT 2");
+ "DO 2;SELECT * from AllowMultiQueriesTest;SELECT * from AllowMultiQueriesTest; DO 1; SELECT"
+ + " 2");
connection.abort(Runnable::run);
connection = createCon("&allowMultiQueries=true");
diff --git a/src/test/java/org/mariadb/jdbc/integration/ParameterMetaDataTest.java b/src/test/java/org/mariadb/jdbc/integration/ParameterMetaDataTest.java
index 50bf44e55..efeac9260 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ParameterMetaDataTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ParameterMetaDataTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/PoolDataSourceTest.java b/src/test/java/org/mariadb/jdbc/integration/PoolDataSourceTest.java
index 300140f0b..ae9f528b6 100644
--- a/src/test/java/org/mariadb/jdbc/integration/PoolDataSourceTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/PoolDataSourceTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -9,7 +8,6 @@
import java.lang.management.ManagementFactory;
import java.sql.*;
import java.util.HashSet;
-import java.util.List;
import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@@ -51,7 +49,8 @@ public static void beforeClassDataSourceTest() throws SQLException {
stmt.execute("GRANT SELECT ON " + sharedConn.getCatalog() + ".* TO 'poolUser'@'%'");
}
stmt.execute(
- "CREATE TABLE testResetRollback(id int not null primary key auto_increment, test varchar(20))");
+ "CREATE TABLE testResetRollback(id int not null primary key auto_increment, test"
+ + " varchar(20))");
stmt.execute("FLUSH TABLES");
stmt.execute("FLUSH PRIVILEGES");
}
@@ -63,6 +62,25 @@ public static void drop() throws SQLException {
}
}
+ /**
+ * List current connections to server.
+ *
+ * @return number of thread connected.
+ */
+ public static int getCurrentConnections() {
+ try {
+ Statement stmt = sharedConn.createStatement();
+ ResultSet rs = stmt.executeQuery("show status where `variable_name` = 'Threads_connected'");
+ if (rs.next()) {
+ System.out.println("threads : " + rs.getInt(2));
+ return rs.getInt(2);
+ }
+ return -1;
+ } catch (SQLException e) {
+ return -1;
+ }
+ }
+
@Test
public void basic() throws SQLException {
MariaDbPoolDataSource ds = new MariaDbPoolDataSource(mDefUrl + "&maxPoolSize=2");
@@ -99,17 +117,20 @@ private void testDs(MariaDbPoolDataSource ds) throws SQLException {
try {
con1 = ds.getPooledConnection();
con2 = ds.getPooledConnection();
-
- ResultSet rs1 = con1.getConnection().createStatement().executeQuery("SELECT 1");
- ResultSet rs2 = con2.getConnection().createStatement().executeQuery("SELECT 2");
- while (rs1.next()) {
- assertEquals(1, rs1.getInt(1));
- }
- while (rs2.next()) {
- assertEquals(2, rs2.getInt(1));
+ try (Statement st1 = con1.getConnection().createStatement()) {
+ try (Statement st2 = con2.getConnection().createStatement()) {
+ ResultSet rs1 = st1.executeQuery("SELECT 1");
+ ResultSet rs2 = st2.executeQuery("SELECT 2");
+ while (rs1.next()) {
+ assertEquals(1, rs1.getInt(1));
+ }
+ while (rs2.next()) {
+ assertEquals(2, rs2.getInt(1));
+ }
+ }
}
long threadId = ((org.mariadb.jdbc.Connection) con2.getConnection()).getThreadId();
- if (con2 != null) con2.getConnection().close();
+ con2.getConnection().close();
con2 = ds.getPooledConnection();
assertEquals(threadId, ((org.mariadb.jdbc.Connection) con2.getConnection()).getThreadId());
} finally {
@@ -122,14 +143,17 @@ private void testDs(MariaDbPoolDataSource ds) throws SQLException {
try {
conx1 = ds.getXAConnection();
conx2 = ds.getXAConnection();
-
- ResultSet rs1 = conx1.getConnection().createStatement().executeQuery("SELECT 1");
- ResultSet rs2 = conx2.getConnection().createStatement().executeQuery("SELECT 2");
- while (rs1.next()) {
- assertEquals(1, rs1.getInt(1));
- }
- while (rs2.next()) {
- assertEquals(2, rs2.getInt(1));
+ try (Statement st1 = conx1.getConnection().createStatement()) {
+ try (Statement st2 = conx2.getConnection().createStatement()) {
+ ResultSet rs1 = st1.executeQuery("SELECT 1");
+ ResultSet rs2 = st2.executeQuery("SELECT 2");
+ while (rs1.next()) {
+ assertEquals(1, rs1.getInt(1));
+ }
+ while (rs2.next()) {
+ assertEquals(2, rs2.getInt(1));
+ }
+ }
}
} finally {
@@ -150,19 +174,19 @@ public void basic2() throws SQLException {
ds.setLoginTimeout(50);
assertEquals(50, ds.getLoginTimeout());
- assertThrows(SQLException.class, () -> ds.getConnection());
+ assertThrows(SQLException.class, ds::getConnection);
assertThrows(SQLException.class, () -> ds.getConnection("user", "password"));
- assertThrows(SQLException.class, () -> ds.getPooledConnection());
+ assertThrows(SQLException.class, ds::getPooledConnection);
assertThrows(SQLException.class, () -> ds.getPooledConnection("user", "password"));
- assertThrows(SQLException.class, () -> ds.getXAConnection());
+ assertThrows(SQLException.class, ds::getXAConnection);
assertThrows(SQLException.class, () -> ds.getXAConnection("user", "password"));
ds.setUser("dd");
assertEquals("dd", ds.getUser());
ds.setPassword("pwd");
- assertThrows(SQLException.class, () -> ds.getConnection());
- assertThrows(SQLException.class, () -> ds.getPooledConnection());
+ assertThrows(SQLException.class, ds::getConnection);
+ assertThrows(SQLException.class, ds::getPooledConnection);
assertThrows(SQLException.class, () -> ds.setUrl("jdbc:wrong://d"));
@@ -178,18 +202,18 @@ public void testDataSource() throws SQLException {
try (MariaDbPoolDataSource ds =
new MariaDbPoolDataSource(mDefUrl + "&allowPublicKeyRetrieval")) {
try (Connection connection = ds.getConnection()) {
- assertEquals(connection.isValid(0), true);
+ assertTrue(connection.isValid(0));
}
try (Connection connection = ds.getConnection("poolUser", "!Passw0rd3Works")) {
- assertEquals(connection.isValid(0), true);
+ assertTrue(connection.isValid(0));
}
PooledConnection poolCon = ds.getPooledConnection();
- assertEquals(poolCon.getConnection().isValid(0), true);
+ assertTrue(poolCon.getConnection().isValid(0));
poolCon.close();
poolCon = ds.getPooledConnection("poolUser", "!Passw0rd3Works");
- assertEquals(poolCon.getConnection().isValid(0), true);
+ assertTrue(poolCon.getConnection().isValid(0));
poolCon.close();
}
}
@@ -469,7 +493,7 @@ public void testIdleTimeout() throws Throwable {
ObjectName name = objectNames.iterator().next();
checkJmxInfo(server, name, 0, 3, 3);
- List initialThreadIds = pool.testGetConnectionIdleThreadIds();
+ pool.testGetConnectionIdleThreadIds();
Thread.sleep(200);
// must still have 3 connections, but must be other ones
@@ -569,7 +593,6 @@ public void ensureUsingPool() throws Exception {
new LinkedBlockingQueue<>(5000),
new PoolThreadFactory("testPool"));
- final long start = System.currentTimeMillis();
Set threadIds = new HashSet<>();
for (int i = 0; i < 500; i++) {
connectionAppender.execute(
@@ -641,7 +664,8 @@ public void wrongUrlHandling() throws SQLException {
assertTrue(
sqle.getMessage()
.contains(
- "No connection available within the specified time (option 'connectTimeout': 500 ms)"));
+ "No connection available within the specified time (option 'connectTimeout':"
+ + " 500 ms)"));
}
}
}
@@ -666,31 +690,12 @@ public void testPrepareReset() throws SQLException {
}
}
- /**
- * List current connections to server.
- *
- * @return number of thread connected.
- */
- public static int getCurrentConnections() {
- try {
- Statement stmt = sharedConn.createStatement();
- ResultSet rs = stmt.executeQuery("show status where `variable_name` = 'Threads_connected'");
- if (rs.next()) {
- System.out.println("threads : " + rs.getInt(2));
- return rs.getInt(2);
- }
- return -1;
- } catch (SQLException e) {
- return -1;
- }
- }
-
@Test
public void poolWithUser() throws SQLException {
try (MariaDbPoolDataSource pool =
new MariaDbPoolDataSource(
mDefUrl + "&maxPoolSize=1&poolName=myPool&allowPublicKeyRetrieval")) {
- long threadId = 0;
+ long threadId;
try (Connection conn = pool.getConnection()) {
conn.isValid(1);
threadId = ((org.mariadb.jdbc.Connection) conn).getThreadId();
@@ -708,6 +713,7 @@ public void poolWithUser() throws SQLException {
}
@Test
+ @SuppressWarnings("try")
public void various() throws SQLException {
Common.assertThrowsContains(
SQLException.class,
@@ -734,6 +740,7 @@ public void various() throws SQLException {
}
@Test
+ @SuppressWarnings("try")
public void pools() throws SQLException {
// ensure all are closed
Pools.close();
diff --git a/src/test/java/org/mariadb/jdbc/integration/PooledConnectionTest.java b/src/test/java/org/mariadb/jdbc/integration/PooledConnectionTest.java
index e4bf9dd8b..6318745c9 100644
--- a/src/test/java/org/mariadb/jdbc/integration/PooledConnectionTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/PooledConnectionTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -102,30 +101,7 @@ public void testPoolKillConnection() throws Exception {
&& !"galera".equals(System.getenv("srv"))
&& !isXpand());
- File tempFile = File.createTempFile("log", ".tmp");
- //
- // Logger logger = (Logger) LoggerFactory.getLogger("org.mariadb.jdbc");
- // Level initialLevel = logger.getLevel();
- // logger.setLevel(Level.TRACE);
- // logger.setAdditive(false);
- // logger.detachAndStopAllAppenders();
- //
- // LoggerContext context = new LoggerContext();
- // FileAppender fa = new FileAppender<>();
- // fa.setName("FILE");
- // fa.setImmediateFlush(true);
- // PatternLayoutEncoder pa = new PatternLayoutEncoder();
- // pa.setPattern("%r %5p %c [%t] - %m%n");
- // pa.setContext(context);
- // pa.start();
- // fa.setEncoder(pa);
- //
- // fa.setFile(tempFile.getPath());
- // fa.setAppend(true);
- // fa.setContext(context);
- // fa.start();
- //
- // logger.addAppender(fa);
+ File.createTempFile("log", ".tmp");
try (MariaDbPoolDataSource ds =
new MariaDbPoolDataSource(mDefUrl + "&maxPoolSize=1&allowPublicKeyRetrieval")) {
@@ -143,22 +119,6 @@ public void testPoolKillConnection() throws Exception {
conn = pc.getConnection();
assertNotEquals(threadId, conn.getThreadId());
pc.close();
- } finally {
-
- // String contents = new String(Files.readAllBytes(Paths.get(tempFile.getPath())));
- // assertTrue(
- // contents.contains(
- // "removed from pool MariaDB-pool due to error during reset (total:0, active:0,
- // pending:0)"),
- // contents);
- // assertTrue(contents.contains("pool MariaDB-pool new physical connection created"),
- // contents);
- //
- // assertTrue(
- // contents.contains("closing pool MariaDB-pool (total:1, active:0, pending:0)"),
- // contents);
- // logger.setLevel(initialLevel);
- // logger.detachAppender(fa);
}
}
@@ -230,7 +190,8 @@ public void testPooledConnectionStatementError() throws Exception {
stmt.execute("GRANT SELECT ON " + sharedConn.getCatalog() + ".* TO 'dsUser'@'%'");
} else {
stmt.execute(
- "CREATE USER 'dsUser'@'%' IDENTIFIED WITH mysql_native_password BY 'MySup8%rPassw@ord'");
+ "CREATE USER 'dsUser'@'%' IDENTIFIED WITH mysql_native_password BY"
+ + " 'MySup8%rPassw@ord'");
stmt.execute("GRANT SELECT ON " + sharedConn.getCatalog() + ".* TO 'dsUser'@'%'");
}
} else {
diff --git a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementMetadataTest.java b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementMetadataTest.java
index 3393d3d59..fb87e3671 100644
--- a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementMetadataTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementMetadataTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java
index 4161ae732..e21ab3f26 100644
--- a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementParametersTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -226,8 +225,7 @@ public void checkParameters(org.mariadb.jdbc.Connection con, boolean text) throw
rs -> assertEquals("abcde", rs.getString(1)),
con);
final String unicodeString =
- ""
- + "\uD83D\uDE0E" // 😎 unicode 6 smiling face with sunglasses
+ "\uD83D\uDE0E" // 😎 unicode 6 smiling face with sunglasses
+ "\uD83C\uDF36" // 🌶 unicode 7 hot pepper
+ "\uD83C\uDFA4" // 🎤 unicode 8 no microphones
+ "\uD83E\uDD42 "; // 🥂 unicode 9 clinking glasses
diff --git a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementTest.java b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementTest.java
index dfb7e003f..5db861327 100644
--- a/src/test/java/org/mariadb/jdbc/integration/PreparedStatementTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/PreparedStatementTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -40,6 +39,17 @@ public static void beforeAll2() throws SQLException {
createSequenceTables();
}
+ public static String generateLongText(int len) {
+ int leftLimit = 97; // letter 'a'
+ int rightLimit = 122; // letter 'z'
+ Random random = new Random();
+ return random
+ .ints(leftLimit, rightLimit)
+ .limit(len)
+ .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
+ .toString();
+ }
+
@Test
public void prep() throws SQLException {
try (PreparedStatement stmt = sharedConn.prepareStatement("SELECT ?")) {
@@ -691,7 +701,8 @@ private void moreResults(Connection con) throws SQLException {
stmt.execute("DROP PROCEDURE IF EXISTS multi");
stmt.setFetchSize(3);
stmt.execute(
- "CREATE PROCEDURE multi() BEGIN SELECT * from sequence_1_to_10; SELECT * FROM sequence_1_to_10;SELECT 2; END");
+ "CREATE PROCEDURE multi() BEGIN SELECT * from sequence_1_to_10; SELECT * FROM"
+ + " sequence_1_to_10;SELECT 2; END");
stmt.execute("CALL multi()");
Assertions.assertTrue(stmt.getMoreResults());
ResultSet rs = stmt.getResultSet();
@@ -756,7 +767,8 @@ private void moreRowLimitedResults(Connection con) throws SQLException {
stmt.setFetchSize(3);
stmt.setMaxRows(5);
stmt.execute(
- "CREATE PROCEDURE multi() BEGIN SELECT * from prepare4; SELECT * FROM prepare4;SELECT 2; END");
+ "CREATE PROCEDURE multi() BEGIN SELECT * from prepare4; SELECT * FROM prepare4;SELECT 2;"
+ + " END");
stmt.execute("CALL multi()");
Assertions.assertTrue(stmt.getMoreResults());
ResultSet rs = stmt.getResultSet();
@@ -912,15 +924,18 @@ public void expectedError() throws SQLException {
Common.assertThrowsContains(
SQLException.class,
() -> prep.executeLargeUpdate("SELECT 1", Statement.NO_GENERATED_KEYS),
- "executeLargeUpdate(String sql, int autoGeneratedKeys) cannot be called on preparedStatement");
+ "executeLargeUpdate(String sql, int autoGeneratedKeys) cannot be called on"
+ + " preparedStatement");
Common.assertThrowsContains(
SQLException.class,
() -> prep.executeLargeUpdate("SELECT 1", new int[] {}),
- "executeLargeUpdate(String sql, int[] columnIndexes) cannot be called on preparedStatement");
+ "executeLargeUpdate(String sql, int[] columnIndexes) cannot be called on"
+ + " preparedStatement");
Common.assertThrowsContains(
SQLException.class,
() -> prep.executeLargeUpdate("SELECT 1", new String[] {}),
- "executeLargeUpdate(String sql, String[] columnNames) cannot be called on preparedStatement");
+ "executeLargeUpdate(String sql, String[] columnNames) cannot be called on"
+ + " preparedStatement");
}
}
@@ -1141,17 +1156,6 @@ public void more2BytesParameters() throws Throwable {
assertTrue(sharedConnBinary.isValid(1));
}
- public static String generateLongText(int len) {
- int leftLimit = 97; // letter 'a'
- int rightLimit = 122; // letter 'z'
- Random random = new Random();
- return random
- .ints(leftLimit, rightLimit)
- .limit(len)
- .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append)
- .toString();
- }
-
@Test
public void skippingRes() throws SQLException {
int maxAllowedPacket = getMaxAllowedPacket();
@@ -1259,27 +1263,31 @@ public void prepareStmtToString(java.sql.Connection conn, String prefix) throws
preparedStatement.setAsciiStream(2, new ByteArrayInputStream("test3".getBytes()));
assertEquals(
prefix
- + "{sql:'INSERT INTO prepare1(t1, t2) VALUES (?,?)', parameters:[,]}",
+ + "{sql:'INSERT INTO prepare1(t1, t2) VALUES (?,?)', parameters:[,]}",
preparedStatement.toString());
preparedStatement.setObject(1, LocalDateTime.parse("2010-01-12T01:55:12"));
preparedStatement.setObject(2, LocalDate.parse("2011-01-01"));
assertEquals(
prefix
- + "{sql:'INSERT INTO prepare1(t1, t2) VALUES (?,?)', parameters:['2010-01-12 01:55:12','2011-01-01']}",
+ + "{sql:'INSERT INTO prepare1(t1, t2) VALUES (?,?)', parameters:['2010-01-12"
+ + " 01:55:12','2011-01-01']}",
preparedStatement.toString());
preparedStatement.setBigDecimal(1, new BigDecimal("158.9876543210"));
preparedStatement.setString(2, "test");
assertEquals(
prefix
- + "{sql:'INSERT INTO prepare1(t1, t2) VALUES (?,?)', parameters:[158.9876543210,'test']}",
+ + "{sql:'INSERT INTO prepare1(t1, t2) VALUES (?,?)',"
+ + " parameters:[158.9876543210,'test']}",
preparedStatement.toString());
preparedStatement.setString(3, "unusedParam");
assertEquals(
prefix
- + "{sql:'INSERT INTO prepare1(t1, t2) VALUES (?,?)', parameters:[158.9876543210,'test','unusedParam']}",
+ + "{sql:'INSERT INTO prepare1(t1, t2) VALUES (?,?)',"
+ + " parameters:[158.9876543210,'test','unusedParam']}",
preparedStatement.toString());
}
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/ProcedureParameterTest.java b/src/test/java/org/mariadb/jdbc/integration/ProcedureParameterTest.java
index 395e8e0d1..5813cc6ab 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ProcedureParameterTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ProcedureParameterTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -104,7 +103,8 @@ public void basicProcedure() throws SQLException {
Statement stmt = sharedConn.createStatement();
stmt.execute("DROP PROCEDURE IF EXISTS basic_proc2");
stmt.execute(
- "CREATE PROCEDURE basic_proc2 (INOUT t1 INT, IN t2 MEDIUMINT unsigned, OUT t3 DECIMAL(8,3), OUT t4 VARCHAR(20), IN t5 SMALLINT) BEGIN \n"
+ "CREATE PROCEDURE basic_proc2 (INOUT t1 INT, IN t2 MEDIUMINT unsigned, OUT t3 DECIMAL(8,3),"
+ + " OUT t4 VARCHAR(20), IN t5 SMALLINT) BEGIN \n"
+ "set t3 = t1 * t5;\n"
+ "set t1 = t2 * t1;\n"
+ "set t4 = 'return data';\n"
diff --git a/src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java b/src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java
index 46ef29d50..e53c5677b 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ProcedureTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -10,7 +9,7 @@
import java.io.IOException;
import java.io.StringReader;
import java.math.BigDecimal;
-import java.net.URL;
+import java.net.URI;
import java.sql.*;
import java.util.Calendar;
import java.util.HashMap;
@@ -123,7 +122,8 @@ public void basicProcedure() throws Throwable {
Statement stmt = sharedConn.createStatement();
stmt.execute("DROP PROCEDURE IF EXISTS basic_proc");
stmt.execute(
- "CREATE PROCEDURE basic_proc (IN t1 INT, INOUT t2 INT unsigned, OUT t3 INT, IN t4 INT, OUT t5 VARCHAR(20), OUT t6 TIMESTAMP, OUT t7 blob) BEGIN \n"
+ "CREATE PROCEDURE basic_proc (IN t1 INT, INOUT t2 INT unsigned, OUT t3 INT, IN t4 INT, OUT"
+ + " t5 VARCHAR(20), OUT t6 TIMESTAMP, OUT t7 blob) BEGIN \n"
+ "SELECT 1;\n"
+ "set t3 = t1 * t4;\n"
+ "set t2 = t2 * t1;\n"
@@ -298,7 +298,7 @@ private void checkResults(CallableStatement callableStatement) throws SQLExcepti
"Data type INTEGER cannot be decoded as byte[]");
Common.assertThrowsContains(
SQLException.class,
- () -> callableStatement.getDate(2, (Calendar) null),
+ () -> callableStatement.getDate(2, null),
"Data type INTEGER cannot be decoded as Date");
Common.assertThrowsContains(
SQLException.class,
@@ -306,7 +306,7 @@ private void checkResults(CallableStatement callableStatement) throws SQLExcepti
"Data type INTEGER cannot be decoded as Time");
Common.assertThrowsContains(
SQLException.class,
- () -> callableStatement.getTime(2, (Calendar) null),
+ () -> callableStatement.getTime(2, null),
"Data type INTEGER cannot be decoded as Time");
Common.assertThrowsContains(
SQLException.class,
@@ -314,7 +314,7 @@ private void checkResults(CallableStatement callableStatement) throws SQLExcepti
"Data type INTEGER cannot be decoded as Timestamp");
Common.assertThrowsContains(
SQLException.class,
- () -> callableStatement.getTimestamp(2, (Calendar) null),
+ () -> callableStatement.getTimestamp(2, null),
"Data type INTEGER cannot be decoded as Timestamp");
assertEquals(6L, callableStatement.getObject(2));
Map> map = new HashMap<>();
@@ -412,7 +412,7 @@ private void checkResults(CallableStatement callableStatement) throws SQLExcepti
"Data type INTEGER cannot be decoded as Date");
Common.assertThrowsContains(
SQLException.class,
- () -> callableStatement.getDate("t2", (Calendar) null),
+ () -> callableStatement.getDate("t2", null),
"Data type INTEGER cannot be decoded as Date");
Common.assertThrowsContains(
SQLException.class,
@@ -420,7 +420,7 @@ private void checkResults(CallableStatement callableStatement) throws SQLExcepti
"Data type INTEGER cannot be decoded as Time");
Common.assertThrowsContains(
SQLException.class,
- () -> callableStatement.getTime("t2", (Calendar) null),
+ () -> callableStatement.getTime("t2", null),
"Data type INTEGER cannot be decoded as Time");
Common.assertThrowsContains(
SQLException.class,
@@ -428,7 +428,7 @@ private void checkResults(CallableStatement callableStatement) throws SQLExcepti
"Data type INTEGER cannot be decoded as Timestamp");
Common.assertThrowsContains(
SQLException.class,
- () -> callableStatement.getTimestamp("t2", (Calendar) null),
+ () -> callableStatement.getTimestamp("t2", null),
"Data type INTEGER cannot be decoded as Timestamp");
assertEquals(6L, callableStatement.getObject("t2"));
Common.assertThrowsContains(
@@ -512,7 +512,7 @@ public void setProcedureTest() throws Exception {
assertEquals("ab", callableStatement.getString(2));
reset(callableStatement);
- callableStatement.setURL(1, new URL("http://a"));
+ callableStatement.setURL(1, URI.create("http://a").toURL());
callableStatement.setString(2, "b");
callableStatement.execute();
assertEquals("http://ab", callableStatement.getString(2));
@@ -796,7 +796,7 @@ public void setProcedureTest() throws Exception {
assertEquals("ab", callableStatement.getString(2));
reset(callableStatement);
- callableStatement.setURL("t1", new URL("http://a"));
+ callableStatement.setURL("t1", URI.create("http://a").toURL());
callableStatement.setString(2, "b");
callableStatement.execute();
assertEquals("http://ab", callableStatement.getString(2));
@@ -1115,12 +1115,14 @@ public void procedureToString() throws SQLException {
callableStatement.registerOutParameter(3, JDBCType.INTEGER);
callableStatement.registerOutParameter(5, JDBCType.VARCHAR);
assertEquals(
- "ProcedureStatement{sql:'call basic_proc(?,?,?,?,?,?,?)', parameters:[null,null,null,null,null]}",
+ "ProcedureStatement{sql:'call basic_proc(?,?,?,?,?,?,?)',"
+ + " parameters:[null,null,null,null,null]}",
callableStatement.toString());
callableStatement.setBytes(2, new byte[] {(byte) 'a', (byte) 'b'});
callableStatement.setLong(1, 10L);
assertEquals(
- "ProcedureStatement{sql:'call basic_proc(?,?,?,?,?,?,?)', parameters:[10,_binary 'ab',null,null,null]}",
+ "ProcedureStatement{sql:'call basic_proc(?,?,?,?,?,?,?)', parameters:[10,_binary"
+ + " 'ab',null,null,null]}",
callableStatement.toString());
}
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/ResultSetTest.java b/src/test/java/org/mariadb/jdbc/integration/ResultSetTest.java
index ef2f500c7..d7783c7cf 100644
--- a/src/test/java/org/mariadb/jdbc/integration/ResultSetTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/ResultSetTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java b/src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java
index ffe0b14dc..8286b5120 100644
--- a/src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/Sha256AuthenticationTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import java.io.File;
@@ -77,13 +76,16 @@ public static void init() throws Exception {
}
stmt.execute(
- "CREATE USER 'cachingSha256User'@'%' IDENTIFIED WITH caching_sha2_password BY '!Passw0rd3Works'");
+ "CREATE USER 'cachingSha256User'@'%' IDENTIFIED WITH caching_sha2_password BY"
+ + " '!Passw0rd3Works'");
stmt.execute(
"CREATE USER 'cachingSha256User2'@'%' IDENTIFIED WITH caching_sha2_password BY ''");
stmt.execute(
- "CREATE USER 'cachingSha256User3'@'%' IDENTIFIED WITH caching_sha2_password BY '!Passw0rd3Works'");
+ "CREATE USER 'cachingSha256User3'@'%' IDENTIFIED WITH caching_sha2_password BY"
+ + " '!Passw0rd3Works'");
stmt.execute(
- "CREATE USER 'cachingSha256User4'@'%' IDENTIFIED WITH caching_sha2_password BY '!Passw0rd3Works'");
+ "CREATE USER 'cachingSha256User4'@'%' IDENTIFIED WITH caching_sha2_password BY"
+ + " '!Passw0rd3Works'");
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User'@'%'");
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User2'@'%'");
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'cachingSha256User3'@'%'");
diff --git a/src/test/java/org/mariadb/jdbc/integration/SslTest.java b/src/test/java/org/mariadb/jdbc/integration/SslTest.java
index 8d7fd803f..6ac80110a 100644
--- a/src/test/java/org/mariadb/jdbc/integration/SslTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/SslTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -22,9 +21,9 @@
@DisplayName("SSL tests")
public class SslTest extends Common {
- private static Integer sslPort;
private static final String baseOptions = "&user=serverAuthUser&password=!Passw0rd3Works";
private static final String baseMutualOptions = "&user=mutualAuthUser&password=!Passw0rd3Works";
+ private static Integer sslPort;
@AfterAll
public static void drop() throws SQLException {
@@ -82,6 +81,37 @@ private static void createSslUser(String user, String requirement) throws SQLExc
}
}
+ public static String retrieveCertificatePath() throws Exception {
+ String serverCertificatePath = checkFileExists(System.getProperty("serverCertificatePath"));
+ if (serverCertificatePath == null) {
+ serverCertificatePath = checkFileExists(System.getenv("TEST_DB_SERVER_CERT"));
+ }
+
+ // try local server
+ if (serverCertificatePath == null
+ && !"skysql".equals(System.getenv("srv"))
+ && !"skysql-ha".equals(System.getenv("srv"))) {
+
+ try (ResultSet rs = sharedConn.createStatement().executeQuery("select @@ssl_cert")) {
+ assertTrue(rs.next());
+ serverCertificatePath = checkFileExists(rs.getString(1));
+ }
+ }
+ if (serverCertificatePath == null) {
+ serverCertificatePath = checkFileExists("../../ssl/server.crt");
+ }
+ return serverCertificatePath;
+ }
+
+ private static String checkFileExists(String path) throws IOException {
+ if (path == null) return null;
+ File f = new File(path);
+ if (f.exists()) {
+ return f.getCanonicalPath().replace("\\", "/");
+ }
+ return null;
+ }
+
private String getSslVersion(Connection con) throws SQLException {
Statement stmt = con.createStatement();
if ("maxscale".equals(System.getenv("srv")) || "skysql-ha".equals(System.getenv("srv"))) {
@@ -296,7 +326,7 @@ public void certificateMandatorySsl() throws Throwable {
createCon(baseOptions + "&sslMode=VERIFY_CA&serverSslCert=file:///wrongPath", sslPort)) {
assertNotNull(getSslVersion(con));
} catch (Exception e) {
- assertTrue(e.getCause() instanceof FileNotFoundException);
+ assertTrue(e.getCause() instanceof IOException);
}
if (!"localhost".equals(hostname)) {
@@ -364,35 +394,4 @@ private String getServerCertificate(String serverCertPath) throws SQLException {
throw new SQLException("abnormal exception", e);
}
}
-
- public static String retrieveCertificatePath() throws Exception {
- String serverCertificatePath = checkFileExists(System.getProperty("serverCertificatePath"));
- if (serverCertificatePath == null) {
- serverCertificatePath = checkFileExists(System.getenv("TEST_DB_SERVER_CERT"));
- }
-
- // try local server
- if (serverCertificatePath == null
- && !"skysql".equals(System.getenv("srv"))
- && !"skysql-ha".equals(System.getenv("srv"))) {
-
- try (ResultSet rs = sharedConn.createStatement().executeQuery("select @@ssl_cert")) {
- assertTrue(rs.next());
- serverCertificatePath = checkFileExists(rs.getString(1));
- }
- }
- if (serverCertificatePath == null) {
- serverCertificatePath = checkFileExists("../../ssl/server.crt");
- }
- return serverCertificatePath;
- }
-
- private static String checkFileExists(String path) throws IOException {
- if (path == null) return null;
- File f = new File(path);
- if (f.exists()) {
- return f.getCanonicalPath().replace("\\", "/");
- }
- return null;
- }
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/StatementTest.java b/src/test/java/org/mariadb/jdbc/integration/StatementTest.java
index a090d1dee..b2c31daa2 100644
--- a/src/test/java/org/mariadb/jdbc/integration/StatementTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/StatementTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -44,7 +43,8 @@ public static void beforeAll2() throws SQLException {
"CREATE TABLE executeGenerated2 (t1 int not null primary key auto_increment, t2 int)");
stmt.execute("CREATE TABLE testAffectedRow(id int)");
stmt.execute(
- "CREATE TABLE bigIntId(`id` bigint(20) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, val VARCHAR(256))");
+ "CREATE TABLE bigIntId(`id` bigint(20) unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT, val"
+ + " VARCHAR(256))");
createSequenceTables();
stmt.execute("FLUSH TABLES");
}
@@ -101,8 +101,8 @@ public void longGeneratedId(BigInteger expected) throws SQLException {
} else {
assertEquals(expected.longValueExact(), rs.getLong(1));
}
- assertTrue(expected.compareTo(((CompleteResult) rs).getBigInteger(1)) == 0);
- assertTrue(new BigDecimal(expected).compareTo(rs.getBigDecimal(1)) == 0);
+ assertEquals(0, expected.compareTo(((CompleteResult) rs).getBigInteger(1)));
+ assertEquals(0, new BigDecimal(expected).compareTo(rs.getBigDecimal(1)));
}
@Test
@@ -541,8 +541,8 @@ public void queryTimeout() {
stmt.setQueryTimeout(1);
assertEquals(1, stmt.getQueryTimeout());
stmt.execute(
- "select * from information_schema.columns as c1, information_schema.tables, information_schema"
- + ".tables as t2");
+ "select * from information_schema.columns as c1, information_schema.tables,"
+ + " information_schema.tables as t2");
},
"Query execution was interrupted (max_statement_time exceeded)");
}
@@ -619,8 +619,7 @@ public void testWarnings() throws SQLException {
@Test
public void cancel() throws Exception {
Assumptions.assumeTrue(
- isMariaDBServer()
- && !"maxscale".equals(System.getenv("srv"))
+ !"maxscale".equals(System.getenv("srv"))
&& !"skysql".equals(System.getenv("srv"))
&& !"skysql-ha".equals(System.getenv("srv"))
&& !isXpand());
@@ -634,8 +633,8 @@ public void cancel() throws Exception {
() -> {
exec.execute(new CancelThread(stmt));
stmt.execute(
- "select * from information_schema.columns as c1, information_schema.tables, information_schema"
- + ".tables as t2");
+ "select * from information_schema.columns as c1, information_schema.tables,"
+ + " information_schema.tables as t2");
exec.shutdown();
},
"Query execution was interrupted");
@@ -877,7 +876,8 @@ public void moreResults() throws SQLException {
stmt.execute("DROP PROCEDURE IF EXISTS multi");
stmt.setFetchSize(3);
stmt.execute(
- "CREATE PROCEDURE multi() BEGIN SELECT * from sequence_1_to_10; SELECT * FROM sequence_1_to_10000;SELECT 2; END");
+ "CREATE PROCEDURE multi() BEGIN SELECT * from sequence_1_to_10; SELECT * FROM"
+ + " sequence_1_to_10000;SELECT 2; END");
stmt.execute("CALL multi()");
assertTrue(stmt.getMoreResults());
ResultSet rs = stmt.getResultSet();
@@ -937,25 +937,6 @@ public void closeOnCompletion() throws SQLException {
assertTrue(stmt.isClosed());
}
- private static class CancelThread implements Runnable {
-
- private final java.sql.Statement stmt;
-
- public CancelThread(java.sql.Statement stmt) {
- this.stmt = stmt;
- }
-
- @Override
- public void run() {
- try {
- Thread.sleep(100);
- stmt.cancel();
- } catch (SQLException | InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
-
@Test
public void testAffectedRow() throws SQLException {
testAffectedRow(false);
@@ -1097,4 +1078,23 @@ public void generatedKey() throws SQLException {
assertFalse(rs.next());
}
}
+
+ static class CancelThread implements Runnable {
+
+ private final java.sql.Statement stmt;
+
+ public CancelThread(java.sql.Statement stmt) {
+ this.stmt = stmt;
+ }
+
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(100);
+ stmt.cancel();
+ } catch (SQLException | InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java b/src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java
index 2e81fd1d0..32e4eeb5f 100644
--- a/src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/UnixsocketTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -21,8 +20,8 @@ static void beforeAllCmd() throws SQLException {
sharedConn
.createStatement()
.execute(
- "CREATE TABLE IF NOT EXISTS test_table"
- + "(int_column int default 100,mediumtext_column mediumtext null) collate = utf8mb3_bin");
+ "CREATE TABLE IF NOT EXISTS test_table(int_column int default 100,mediumtext_column"
+ + " mediumtext null) collate = utf8mb3_bin");
}
@AfterAll
@@ -88,10 +87,7 @@ public void testConnectWithUnixSocketWhenDBNotUp() throws IOException {
for (int i = 0; i < 10; i++) {
assertThrows(
- SQLNonTransientConnectionException.class,
- () -> {
- driver.connect(url, new Properties());
- });
+ SQLNonTransientConnectionException.class, () -> driver.connect(url, new Properties()));
}
proc = rt.exec(commands);
stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
diff --git a/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java b/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java
index d085829d4..45d3e517e 100644
--- a/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/UpdateResultSetTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -39,15 +38,20 @@ public static void beforeAll2() throws SQLException {
org.mariadb.jdbc.Statement stmt = sharedConn.createStatement();
stmt.execute("CREATE TABLE testnoprimarykey(`id` INT NOT NULL,`t1` VARCHAR(50) NOT NULL)");
stmt.execute(
- "CREATE TABLE testbasicprimarykey(`id` INT NOT NULL,`t1` VARCHAR(50) NOT NULL, CONSTRAINT pk PRIMARY KEY (id))");
+ "CREATE TABLE testbasicprimarykey(`id` INT NOT NULL,`t1` VARCHAR(50) NOT NULL, CONSTRAINT"
+ + " pk PRIMARY KEY (id))");
stmt.execute(
- "CREATE TABLE testMultipleTable1(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50) NULL,PRIMARY KEY (`id1`))");
+ "CREATE TABLE testMultipleTable1(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50)"
+ + " NULL,PRIMARY KEY (`id1`))");
stmt.execute(
- "CREATE TABLE testMultipleTable2(`id2` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50) NULL,PRIMARY KEY (`id2`))");
+ "CREATE TABLE testMultipleTable2(`id2` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50)"
+ + " NULL,PRIMARY KEY (`id2`))");
stmt.execute(
- "CREATE TABLE testOneNoTable(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50) NULL,PRIMARY KEY (`id1`))");
+ "CREATE TABLE testOneNoTable(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50)"
+ + " NULL,PRIMARY KEY (`id1`))");
stmt.execute(
- "CREATE TABLE testAutoIncrement(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50) NULL,PRIMARY KEY (`id1`))");
+ "CREATE TABLE testAutoIncrement(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50)"
+ + " NULL,PRIMARY KEY (`id1`))");
stmt.execute(
"CREATE TABLE testUpdateWhenFetch("
@@ -69,7 +73,8 @@ public static void beforeAll2() throws SQLException {
+ " PRIMARY KEY (`column1`))");
}
stmt.execute(
- "CREATE TABLE test_update_max(`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,`t1` VARCHAR(50) NOT NULL)");
+ "CREATE TABLE test_update_max(`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,`t1` VARCHAR(50)"
+ + " NOT NULL)");
}
/**
@@ -92,7 +97,8 @@ public void testNoPrimaryKey() throws Exception {
Common.assertThrowsContains(
SQLException.class,
() -> rs.updateString(1, "1"),
- "ResultSet cannot be updated. Cannot update rows, since no primary field is present in query");
+ "ResultSet cannot be updated. Cannot update rows, since no primary field is present in"
+ + " query");
}
sharedConn.rollback();
}
@@ -113,7 +119,8 @@ public void testBasicPrimaryKey() throws Exception {
Common.assertThrowsContains(
SQLException.class,
() -> rs.updateString(1, "val"),
- "ResultSet cannot be updated. Cannot update rows, since primary field id is not present in query");
+ "ResultSet cannot be updated. Cannot update rows, since primary field id is not present"
+ + " in query");
}
sharedConn.rollback();
}
@@ -220,9 +227,11 @@ public void testMultipleDatabase() throws Exception {
stmt.execute("CREATE DATABASE testConnectorJ");
stmt.execute("DROP TABLE IF EXISTS testMultipleDatabase");
stmt.execute(
- "CREATE TABLE testMultipleDatabase(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50) NULL,PRIMARY KEY (`id1`))");
+ "CREATE TABLE testMultipleDatabase(`id1` INT NOT NULL AUTO_INCREMENT,`t1` VARCHAR(50)"
+ + " NULL,PRIMARY KEY (`id1`))");
stmt.execute(
- "CREATE TABLE testConnectorJ.testMultipleDatabase(`id2` INT NOT NULL AUTO_INCREMENT,`t2` VARCHAR(50) NULL,PRIMARY KEY (`id2`))");
+ "CREATE TABLE testConnectorJ.testMultipleDatabase(`id2` INT NOT NULL AUTO_INCREMENT,`t2`"
+ + " VARCHAR(50) NULL,PRIMARY KEY (`id2`))");
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
stmt.executeQuery("INSERT INTO testMultipleDatabase(t1) values ('1')");
@@ -270,11 +279,13 @@ public void testMeta() throws Exception {
rs.updateString(1, "1-1-bis");
rs.updateRow();
},
- "ResultSet cannot be updated. Cannot update rows, since primary field id is not present in query");
+ "ResultSet cannot be updated. Cannot update rows, since primary field id is not present"
+ + " in query");
Common.assertThrowsContains(
SQLException.class,
rs::deleteRow,
- "ResultSet cannot be updated. Cannot update rows, since primary field id is not present in query");
+ "ResultSet cannot be updated. Cannot update rows, since primary field id is not present"
+ + " in query");
ResultSetMetaData rsmd = rs.getMetaData();
assertFalse(rsmd.isReadOnly(1));
assertFalse(rsmd.isReadOnly(2));
@@ -587,7 +598,8 @@ public void testUpdateChangingMultiplePrimaryKey() throws Exception {
+ "PRIMARY KEY (`id`,`id2`))");
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
stmt.execute(
- "INSERT INTO testUpdateChangingMultiplePrimaryKey values (1,-1,'1'), (2,-2,'2'), (3,-3,'3')");
+ "INSERT INTO testUpdateChangingMultiplePrimaryKey values (1,-1,'1'), (2,-2,'2'),"
+ + " (3,-3,'3')");
try (PreparedStatement preparedStatement =
sharedConn.prepareStatement(
"SELECT * FROM testUpdateChangingMultiplePrimaryKey",
@@ -1082,7 +1094,8 @@ public void repeatedFieldUpdatable() throws SQLException {
Statement stmt = sharedConn.createStatement();
stmt.execute("DROP TABLE IF EXISTS repeatedFieldUpdatable");
stmt.execute(
- "CREATE TABLE repeatedFieldUpdatable(t1 varchar(50) NOT NULL, t2 varchar(50), PRIMARY KEY (t1))");
+ "CREATE TABLE repeatedFieldUpdatable(t1 varchar(50) NOT NULL, t2 varchar(50), PRIMARY KEY"
+ + " (t1))");
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
stmt.execute("insert into repeatedFieldUpdatable values ('gg', 'hh'), ('jj', 'll')");
@@ -1174,7 +1187,8 @@ public void addAfterDataFull() throws SQLException {
Statement stmt = sharedConn.createStatement();
sharedConn.createStatement().execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
stmt.execute(
- "INSERT INTO test_update_max(t1) value ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'), ('8'), ('9'), ('10')");
+ "INSERT INTO test_update_max(t1) value ('1'), ('2'), ('3'), ('4'), ('5'), ('6'), ('7'),"
+ + " ('8'), ('9'), ('10')");
try (PreparedStatement preparedStatement =
sharedConn.prepareStatement(
"SELECT t1, id FROM test_update_max",
diff --git a/src/test/java/org/mariadb/jdbc/integration/XaTest.java b/src/test/java/org/mariadb/jdbc/integration/XaTest.java
index 586679f21..4f3054d7f 100644
--- a/src/test/java/org/mariadb/jdbc/integration/XaTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/XaTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration;
import static org.junit.jupiter.api.Assertions.*;
@@ -62,8 +61,8 @@ public void xidToString() {
new MariaDbXid(-1010695802, new byte[] {0x00}, new byte[] {0x00, 0x01, 0x00})));
assertEquals(xid, xid);
assertEquals(xid, new MariaDbXid(1575, new byte[] {0x00}, new byte[] {0x01}));
- assertFalse(xid.equals("dd"));
- assertFalse(xid.equals(null));
+ assertNotEquals("dd", xid);
+ assertNotEquals(null, xid);
assertEquals(1544359, xid.hashCode());
}
@@ -233,7 +232,7 @@ public void testRecover() throws Exception {
xaResource.end(xid, XAResource.TMSUCCESS);
xaResource.prepare(xid);
Xid[] recoveredXids = xaResource.recover(XAResource.TMSTARTRSCAN | XAResource.TMENDRSCAN);
- assertTrue(recoveredXids != null);
+ assertNotNull(recoveredXids);
assertTrue(recoveredXids.length > 0);
boolean found = false;
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/BinaryCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/BinaryCodecTest.java
index 98f104d57..2f5efccec 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/BinaryCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/BinaryCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -38,11 +37,11 @@ public static void beforeAll2() throws SQLException {
drop();
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE BinaryCodec (t1 VARBINARY(20), t2 VARBINARY(30), t3 VARBINARY(20), t4 BINARY(20)) CHARACTER "
- + "SET utf8mb4 COLLATE utf8mb4_unicode_ci");
+ "CREATE TABLE BinaryCodec (t1 VARBINARY(20), t2 VARBINARY(30), t3 VARBINARY(20), t4"
+ + " BINARY(20)) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
stmt.execute(
- "INSERT INTO BinaryCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31 23:59:59.152',"
- + " '23:54:51.840010', null)");
+ "INSERT INTO BinaryCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31"
+ + " 23:59:59.152', '23:54:51.840010', null)");
stmt.execute(
"CREATE TABLE BinaryCodec2 (id int not null primary key auto_increment, t1 VARBINARY(20))");
stmt.execute("FLUSH TABLES");
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java
index 5e21c319f..3c7628ed8 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/BitCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java
index 0966a9266..caf7dae79 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/BlobCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -22,8 +21,8 @@
import org.mariadb.jdbc.integration.Common;
public class BlobCodecTest extends CommonCodecTest {
- private static File tmpFile;
private static final byte[] fileContent = new byte[11000];
+ private static File tmpFile;
@AfterAll
public static void drop() throws SQLException {
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/CharCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/CharCodecTest.java
index d7bb57d67..521706d59 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/CharCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/CharCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -40,8 +39,9 @@ public static void beforeAll2() throws SQLException {
"CREATE TABLE CharCodec (t1 CHAR(30), t2 CHAR(30), t3 CHAR(25), t4 CHAR(25)) CHARACTER "
+ "SET utf8mb4 COLLATE utf8mb4_unicode_ci");
stmt.execute(
- "INSERT INTO CharCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31 23:59:59.152',"
- + " '23:54:51.840010', null),('2010-12-31T23:59:59.152+01:00', '2010-12-31T23:59:59.152Z', null, null)");
+ "INSERT INTO CharCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31"
+ + " 23:59:59.152', '23:54:51.840010', null),('2010-12-31T23:59:59.152+01:00',"
+ + " '2010-12-31T23:59:59.152Z', null, null)");
stmt.execute("FLUSH TABLES");
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/ClobCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/ClobCodecTest.java
index 3c1f19722..615320d86 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/ClobCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/ClobCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -41,8 +40,8 @@ public static void beforeAll2() throws SQLException {
"CREATE TABLE ClobCodec (t1 TINYTEXT, t2 TEXT, t3 MEDIUMTEXT, t4 LONGTEXT) CHARACTER "
+ "SET utf8mb4 COLLATE utf8mb4_unicode_ci");
stmt.execute(
- "INSERT INTO ClobCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31 23:59:59.152',"
- + " '23:54:51.840010', null)");
+ "INSERT INTO ClobCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31"
+ + " 23:59:59.152', '23:54:51.840010', null)");
stmt.execute(
"CREATE TABLE ClobParamCodec(id int not null primary key auto_increment, t1 TEXT) "
+ "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/CommonCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/CommonCodecTest.java
index 582be2ff3..2c535262b 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/CommonCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/CommonCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DateCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DateCodecTest.java
index 7325463aa..24d918145 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/DateCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/DateCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -165,7 +164,7 @@ public void getString(ResultSet rs) throws SQLException {
assertTrue(rs.wasNull());
if (isMariaDBServer()) {
rs.next();
- assertTrue("0000-00-00".equals(rs.getString(1)));
+ assertEquals("0000-00-00", rs.getString(1));
}
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java
index 1fe600f50..a6c1d6772 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/DateTimeCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -35,10 +34,11 @@ public static void beforeAll2() throws SQLException {
drop();
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE DateTimeCodec (t1 DATETIME , t2 DATETIME(6), t3 DATETIME(6), t4 DATETIME(6))");
+ "CREATE TABLE DateTimeCodec (t1 DATETIME , t2 DATETIME(6), t3 DATETIME(6), t4"
+ + " DATETIME(6))");
stmt.execute(
- "INSERT INTO DateTimeCodec VALUES "
- + "('2010-01-12 01:55:12', '1000-01-01 01:55:13.212345', '9999-12-31 18:30:12.55', null)"
+ "INSERT INTO DateTimeCodec VALUES ('2010-01-12 01:55:12', '1000-01-01 01:55:13.212345',"
+ + " '9999-12-31 18:30:12.55', null)"
+ (isMariaDBServer()
? ",('0000-00-00 00:00:00', '0000-00-00 00:00:00', '9999-12-31 00:00:00.00', null)"
: ""));
@@ -211,9 +211,9 @@ public void getNString(ResultSet rs) throws SQLException {
assertEquals("2010-01-12 01:55:12", rs.getNString(1));
assertFalse(rs.wasNull());
String s = rs.getNString(2);
- assertTrue(s.equals("1000-01-01 01:55:13.212345"));
+ assertEquals("1000-01-01 01:55:13.212345", s);
s = rs.getNString("t2alias");
- assertTrue(s.equals("1000-01-01 01:55:13.212345"));
+ assertEquals("1000-01-01 01:55:13.212345", s);
assertFalse(rs.wasNull());
s = rs.getNString(3);
assertTrue(s.equals("9999-12-31 18:30:12.550000") || s.equals("9999-12-31 18:30:12.550"));
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DecimalCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DecimalCodecTest.java
index 96efaa750..d2eb21bb0 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/DecimalCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/DecimalCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -33,15 +32,20 @@ public static void beforeAll2() throws SQLException {
drop();
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE DecimalCodec (t1 DECIMAL(10,0), t2 DECIMAL(30,6), t3 DECIMAL(10,3), t4 DECIMAL(10,0))");
+ "CREATE TABLE DecimalCodec (t1 DECIMAL(10,0), t2 DECIMAL(30,6), t3 DECIMAL(10,3), t4"
+ + " DECIMAL(10,0))");
stmt.execute(
- "CREATE TABLE DecimalCodec2 (t1 DECIMAL(10,0), t2 DECIMAL(10,6), t3 DECIMAL(10,3), t4 DECIMAL(10,0))");
+ "CREATE TABLE DecimalCodec2 (t1 DECIMAL(10,0), t2 DECIMAL(10,6), t3 DECIMAL(10,3), t4"
+ + " DECIMAL(10,0))");
stmt.execute(
- "INSERT INTO DecimalCodec VALUES (0, 105.21, -1.6, null), (0, 9223372036854775808, 0, null)");
+ "INSERT INTO DecimalCodec VALUES (0, 105.21, -1.6, null), (0, 9223372036854775808, 0,"
+ + " null)");
stmt.execute(
- "CREATE TABLE DecimalCodec3 (id int not null primary key auto_increment, t1 DECIMAL(10,0))");
+ "CREATE TABLE DecimalCodec3 (id int not null primary key auto_increment, t1"
+ + " DECIMAL(10,0))");
stmt.execute(
- "CREATE TABLE DecimalCodec4 (t1 DECIMAL(10,0) ZEROFILL, t2 DECIMAL(10,6) ZEROFILL, t3 DECIMAL(10,3) ZEROFILL, t4 DECIMAL(10,0) ZEROFILL)");
+ "CREATE TABLE DecimalCodec4 (t1 DECIMAL(10,0) ZEROFILL, t2 DECIMAL(10,6) ZEROFILL, t3"
+ + " DECIMAL(10,3) ZEROFILL, t4 DECIMAL(10,0) ZEROFILL)");
stmt.execute("INSERT INTO DecimalCodec4 VALUES (0, 105.21, 1.6, null)");
stmt.execute("FLUSH TABLES");
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/DoubleCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/DoubleCodecTest.java
index d383bcdcd..b4e9ec1c4 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/DoubleCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/DoubleCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/EnumCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/EnumCodecTest.java
index c0351b130..b6b74a9fa 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/EnumCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/EnumCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -39,14 +38,15 @@ public static void beforeAll2() throws SQLException {
drop();
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE EnumCodec (t1 ENUM('0', '1', 'some🌟', '2011-01-01', '2010-12-31 23:59:59.152', '23:54:51.840010'),"
- + " t2 ENUM('0', '1', 'some🌟', '2011-01-01', '2010-12-31 23:59:59.152', '23:54:51.840010'), "
- + " t3 ENUM('0', '1', 'some🌟', '2011-01-01', '2010-12-31 23:59:59.152', '23:54:51.840010'),"
- + " t4 ENUM('0', '1', 'some🌟', '2011-01-01', '2010-12-31 23:59:59.152', '23:54:51.840010'))"
- + " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
+ "CREATE TABLE EnumCodec (t1 ENUM('0', '1', 'some🌟', '2011-01-01', '2010-12-31"
+ + " 23:59:59.152', '23:54:51.840010'), t2 ENUM('0', '1', 'some🌟', '2011-01-01',"
+ + " '2010-12-31 23:59:59.152', '23:54:51.840010'), t3 ENUM('0', '1', 'some🌟',"
+ + " '2011-01-01', '2010-12-31 23:59:59.152', '23:54:51.840010'), t4 ENUM('0', '1',"
+ + " 'some🌟', '2011-01-01', '2010-12-31 23:59:59.152', '23:54:51.840010')) CHARACTER"
+ + " SET utf8mb4 COLLATE utf8mb4_unicode_ci");
stmt.execute(
- "INSERT INTO EnumCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31 23:59:59.152',"
- + " '23:54:51.840010', null)");
+ "INSERT INTO EnumCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31"
+ + " 23:59:59.152', '23:54:51.840010', null)");
stmt.execute("CREATE TABLE EnumCodec2 (t1 ENUM('0', '1', '2')) CHARACTER SET binary");
stmt.execute("INSERT INTO EnumCodec2 VALUES ('0'), ('1'), (null)");
stmt.execute("FLUSH TABLES");
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/FloatCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/FloatCodecTest.java
index 925c2036a..45cc38c73 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/FloatCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/FloatCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java
index 79e985871..369a84a4f 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/GeometryCollectionCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -105,15 +104,18 @@ public static void beforeAll2() throws Exception {
Assumptions.assumeFalse(isXpand());
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE GeometryCollectionCodec (t1 GeometryCollection, t2 GeometryCollection, t3 GeometryCollection, t4 GeometryCollection)");
+ "CREATE TABLE GeometryCollectionCodec (t1 GeometryCollection, t2 GeometryCollection, t3"
+ + " GeometryCollection, t4 GeometryCollection)");
stmt.execute(
- "INSERT INTO GeometryCollectionCodec VALUES "
- + "(ST_GeomFromText('GeometryCollection(POINT (0 0), LINESTRING(10 10,20 10,20 20,10 20,10 10))'), "
- + "ST_GeomFromText('GeometryCollection(POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10)), MULTIPOINT(0 0,0 10,10 0))'), "
- + "ST_GeomFromText('GeometryCollection(MULTILINESTRING((0 0,50 0,50 50,0 50), (10 10,20 10,20 20,10 20)), MULTIPOLYGON(((1 1, 1 8,4 9,6 9,9 3,7 2, 1 1))))'), "
- + "null)");
+ "INSERT INTO GeometryCollectionCodec VALUES (ST_GeomFromText('GeometryCollection(POINT (0"
+ + " 0), LINESTRING(10 10,20 10,20 20,10 20,10 10))'),"
+ + " ST_GeomFromText('GeometryCollection(POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20"
+ + " 10,20 20,10 20,10 10)), MULTIPOINT(0 0,0 10,10 0))'),"
+ + " ST_GeomFromText('GeometryCollection(MULTILINESTRING((0 0,50 0,50 50,0 50), (10"
+ + " 10,20 10,20 20,10 20)), MULTIPOLYGON(((1 1, 1 8,4 9,6 9,9 3,7 2, 1 1))))'), null)");
stmt.execute(
- "CREATE TABLE GeometryCollectionCodec2 (id int not null primary key auto_increment, t1 GeometryCollection)");
+ "CREATE TABLE GeometryCollectionCodec2 (id int not null primary key auto_increment, t1"
+ + " GeometryCollection)");
stmt.execute("FLUSH TABLES");
String binUrl =
mDefUrl + (mDefUrl.indexOf("?") > 0 ? "&" : "?") + "geometryDefaultType=default";
@@ -133,7 +135,8 @@ private ResultSet get() throws SQLException {
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
ResultSet rs =
stmt.executeQuery(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from GeometryCollectionCodec");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " GeometryCollectionCodec");
assertTrue(rs.next());
sharedConn.commit();
return rs;
@@ -144,8 +147,8 @@ private CompleteResult getPrepare(org.mariadb.jdbc.Connection con) throws SQLExc
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
PreparedStatement preparedStatement =
con.prepareStatement(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from GeometryCollectionCodec"
- + " WHERE 1 > ?");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " GeometryCollectionCodec WHERE 1 > ?");
preparedStatement.closeOnCompletion();
preparedStatement.setInt(1, 0);
CompleteResult rs = (CompleteResult) preparedStatement.executeQuery();
@@ -270,7 +273,7 @@ private void sendParam(Connection con) throws Exception {
con.prepareStatement("INSERT INTO GeometryCollectionCodec2(t1) VALUES (?)")) {
prep.setObject(1, geo1);
prep.execute();
- prep.setObject(1, (GeometryCollection) null);
+ prep.setObject(1, null);
prep.execute();
prep.setObject(1, geo2);
@@ -336,8 +339,8 @@ public void equal() {
})
.hashCode(),
geo1.hashCode());
- assertFalse(geo1.equals(null));
- assertFalse(geo1.equals(""));
+ assertNotEquals(null, geo1);
+ assertNotEquals("", geo1);
assertNotEquals(
new GeometryCollection(
new Geometry[] {
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/IntCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/IntCodecTest.java
index 9b95995fc..e16c72c5f 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/IntCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/IntCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java
index 60540f711..b7f9498f8 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/LineStringCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -40,12 +39,15 @@ public static void beforeAll2() throws Exception {
Assumptions.assumeFalse(isXpand());
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE LineStringCodec (t1 LineString, t2 LineString, t3 LineString, t4 LineString)");
+ "CREATE TABLE LineStringCodec (t1 LineString, t2 LineString, t3 LineString, t4"
+ + " LineString)");
stmt.execute(
- "INSERT INTO LineStringCodec VALUES "
- + "( ST_LineStringFromText('LINESTRING(0 0,0 10,10 0)'), ST_LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)'), ST_LineStringFromText('LINESTRING(-1 0.55, 3 5, 1 1)'), null)");
+ "INSERT INTO LineStringCodec VALUES ( ST_LineStringFromText('LINESTRING(0 0,0 10,10 0)'),"
+ + " ST_LineStringFromText('LINESTRING(10 10,20 10,20 20,10 20,10 10)'),"
+ + " ST_LineStringFromText('LINESTRING(-1 0.55, 3 5, 1 1)'), null)");
stmt.execute(
- "CREATE TABLE LineStringCodec2 (id int not null primary key auto_increment, t1 LineString)");
+ "CREATE TABLE LineStringCodec2 (id int not null primary key auto_increment, t1"
+ + " LineString)");
stmt.execute("FLUSH TABLES");
String binUrl =
mDefUrl + (mDefUrl.indexOf("?") > 0 ? "&" : "?") + "geometryDefaultType=default";
@@ -57,7 +59,8 @@ private ResultSet get() throws SQLException {
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
ResultSet rs =
stmt.executeQuery(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from LineStringCodec");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " LineStringCodec");
assertTrue(rs.next());
sharedConn.commit();
return rs;
@@ -296,7 +299,7 @@ private void sendParam(Connection con) throws Exception {
con.prepareStatement("INSERT INTO LineStringCodec2(t1) VALUES (?)")) {
prep.setObject(1, ls1);
prep.execute();
- prep.setObject(1, (LineString) null);
+ prep.setObject(1, null);
prep.execute();
prep.setObject(1, ls2);
@@ -341,8 +344,8 @@ public void equal() {
new LineString(new Point[] {new Point(0, 0), new Point(0, 10), new Point(10, 0)}, true)
.hashCode(),
ls.hashCode());
- assertFalse(ls.equals(null));
- assertFalse(ls.equals(""));
+ assertNotEquals(null, ls);
+ assertNotEquals("", ls);
assertNotEquals(
new LineString(new Point[] {new Point(0, 0), new Point(0, 20), new Point(20, 0)}, true),
ls);
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/LongCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/LongCodecTest.java
index 68b465d2d..32d6b3088 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/LongCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/LongCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -34,8 +33,8 @@ public static void beforeAll2() throws SQLException {
Statement stmt = sharedConn.createStatement();
stmt.execute("CREATE TABLE LongCodec (t1 BIGINT, t2 BIGINT, t3 BIGINT, t4 BIGINT)");
stmt.execute(
- "CREATE TABLE LongCodecUnsigned (t1 BIGINT UNSIGNED, t2 BIGINT UNSIGNED, t3 BIGINT UNSIGNED, t4 BIGINT "
- + "UNSIGNED)");
+ "CREATE TABLE LongCodecUnsigned (t1 BIGINT UNSIGNED, t2 BIGINT UNSIGNED, t3 BIGINT"
+ + " UNSIGNED, t4 BIGINT UNSIGNED)");
stmt.execute("INSERT INTO LongCodec VALUES (0, 1, -1, null)");
stmt.execute("INSERT INTO LongCodecUnsigned VALUES (0, 1, 18446744073709551615, null)");
stmt.execute("CREATE TABLE LongCodec2 (id int not null primary key auto_increment, t1 BIGINT)");
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MediumIntCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MediumIntCodecTest.java
index 4352c99ee..7368da266 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/MediumIntCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/MediumIntCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -36,14 +35,15 @@ public static void beforeAll2() throws SQLException {
stmt.execute(
"CREATE TABLE MediumIntCodec (t1 MEDIUMINT, t2 MEDIUMINT, t3 MEDIUMINT, t4 MEDIUMINT)");
stmt.execute(
- "CREATE TABLE MediumIntCodecUnsigned (t1 MEDIUMINT UNSIGNED, t2 MEDIUMINT UNSIGNED, t3 MEDIUMINT UNSIGNED, t4 MEDIUMINT "
- + "UNSIGNED)");
+ "CREATE TABLE MediumIntCodecUnsigned (t1 MEDIUMINT UNSIGNED, t2 MEDIUMINT UNSIGNED, t3"
+ + " MEDIUMINT UNSIGNED, t4 MEDIUMINT UNSIGNED)");
stmt.execute("INSERT INTO MediumIntCodec VALUES (0, 1, -1, null)");
stmt.execute("INSERT INTO MediumIntCodecUnsigned VALUES (0, 1, 16777215, null)");
stmt.execute(
"CREATE TABLE MediumIntCodec2 (id int not null primary key auto_increment, t1 MEDIUMINT)");
stmt.execute(
- "CREATE TABLE MediumIntCodec3 (id int not null, id2 int not null, t1 MEDIUMINT, PRIMARY KEY (id, id2))");
+ "CREATE TABLE MediumIntCodec3 (id int not null, id2 int not null, t1 MEDIUMINT, PRIMARY KEY"
+ + " (id, id2))");
stmt.execute("FLUSH TABLES");
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java
index 62f84f70c..a09d21ead 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiLineStringCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -79,14 +78,16 @@ public static void beforeAll2() throws Exception {
Assumptions.assumeFalse(isXpand());
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE MultiLineStringCodec (t1 MultiLineString, t2 MultiLineString, t3 MultiLineString, t4 MultiLineString)");
+ "CREATE TABLE MultiLineStringCodec (t1 MultiLineString, t2 MultiLineString, t3"
+ + " MultiLineString, t4 MultiLineString)");
stmt.execute(
- "INSERT INTO MultiLineStringCodec VALUES "
- + "(ST_MLineFromText('MULTILINESTRING((1 1,1 5,4 9,6 9,9 3,7 2))'), "
- + "ST_MLineFromText('MULTILINESTRING((0 0,50 0,50 50,0 50), (10 10,20 10,20 20,10 20))'), "
- + "ST_MLineFromText('MULTILINESTRING((0 0,50 0,50 50,0 50))'), null)");
+ "INSERT INTO MultiLineStringCodec VALUES (ST_MLineFromText('MULTILINESTRING((1 1,1 5,4 9,6"
+ + " 9,9 3,7 2))'), ST_MLineFromText('MULTILINESTRING((0 0,50 0,50 50,0 50), (10 10,20"
+ + " 10,20 20,10 20))'), ST_MLineFromText('MULTILINESTRING((0 0,50 0,50 50,0 50))'),"
+ + " null)");
stmt.execute(
- "CREATE TABLE MultiLineStringCodec2 (id int not null primary key auto_increment, t1 MultiLineString)");
+ "CREATE TABLE MultiLineStringCodec2 (id int not null primary key auto_increment, t1"
+ + " MultiLineString)");
stmt.execute("FLUSH TABLES");
String binUrl =
@@ -99,7 +100,8 @@ private ResultSet get() throws SQLException {
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
ResultSet rs =
stmt.executeQuery(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from MultiLineStringCodec");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " MultiLineStringCodec");
assertTrue(rs.next());
sharedConn.commit();
return rs;
@@ -110,8 +112,8 @@ private CompleteResult getPrepare(org.mariadb.jdbc.Connection con) throws SQLExc
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
PreparedStatement preparedStatement =
con.prepareStatement(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from MultiLineStringCodec"
- + " WHERE 1 > ?");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " MultiLineStringCodec WHERE 1 > ?");
preparedStatement.closeOnCompletion();
preparedStatement.setInt(1, 0);
CompleteResult rs = (CompleteResult) preparedStatement.executeQuery();
@@ -354,7 +356,7 @@ private void sendParam(Connection con) throws Exception {
con.prepareStatement("INSERT INTO MultiLineStringCodec2(t1) VALUES (?)")) {
prep.setObject(1, ls1);
prep.execute();
- prep.setObject(1, (MultiLineString) null);
+ prep.setObject(1, null);
prep.execute();
prep.setObject(1, ls2);
@@ -420,8 +422,8 @@ public void equal() {
})
.hashCode(),
ls2.hashCode());
- assertFalse(ls2.equals(null));
- assertFalse(ls2.equals(""));
+ assertNotEquals(null, ls2);
+ assertNotEquals("", ls2);
assertNotEquals(ls1, ls2);
assertNotEquals(
new MultiLineString(
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java
index 69120c740..116ad1ab0 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPointCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -40,12 +39,15 @@ public static void beforeAll2() throws Exception {
Assumptions.assumeFalse(isXpand());
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE MultiPointCodec (t1 MultiPoint, t2 MultiPoint, t3 MultiPoint, t4 MultiPoint)");
+ "CREATE TABLE MultiPointCodec (t1 MultiPoint, t2 MultiPoint, t3 MultiPoint, t4"
+ + " MultiPoint)");
stmt.execute(
- "INSERT INTO MultiPointCodec VALUES "
- + "(ST_MPointFromText('MULTIPOINT(0 0,0 10,10 0)'), ST_MPointFromText('MULTIPOINT(10 10,20 10,20 20,10 20,10 10)'), ST_MPointFromText('MULTIPOINT(-1 0.55, 3 5, 1 1)'), null)");
+ "INSERT INTO MultiPointCodec VALUES (ST_MPointFromText('MULTIPOINT(0 0,0 10,10 0)'),"
+ + " ST_MPointFromText('MULTIPOINT(10 10,20 10,20 20,10 20,10 10)'),"
+ + " ST_MPointFromText('MULTIPOINT(-1 0.55, 3 5, 1 1)'), null)");
stmt.execute(
- "CREATE TABLE MultiPointCodec2 (id int not null primary key auto_increment, t1 MultiPoint)");
+ "CREATE TABLE MultiPointCodec2 (id int not null primary key auto_increment, t1"
+ + " MultiPoint)");
stmt.execute("FLUSH TABLES");
String binUrl =
@@ -58,7 +60,8 @@ private ResultSet get() throws SQLException {
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
ResultSet rs =
stmt.executeQuery(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from MultiPointCodec");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " MultiPointCodec");
assertTrue(rs.next());
sharedConn.commit();
return rs;
@@ -307,7 +310,7 @@ private void sendParam(Connection con) throws Exception {
con.prepareStatement("INSERT INTO MultiPointCodec2(t1) VALUES (?)")) {
prep.setObject(1, ls1);
prep.execute();
- prep.setObject(1, (MultiPoint) null);
+ prep.setObject(1, null);
prep.execute();
prep.setObject(1, ls2);
@@ -350,8 +353,8 @@ public void equal() {
new MultiPoint(new Point[] {new Point(0, 0), new Point(0, 10), new Point(10, 0)})
.hashCode(),
mp.hashCode());
- assertFalse(mp.equals(null));
- assertFalse(mp.equals(""));
+ assertNotEquals(null, mp);
+ assertNotEquals("", mp);
assertNotEquals(
new MultiPoint(new Point[] {new Point(0, 0), new Point(0, 10), new Point(10, 20)}), mp);
assertNotEquals(
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java
index 632230d7f..b47e54b7a 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/MultiPolygonCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -122,14 +121,17 @@ public static void beforeAll2() throws Exception {
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE MultiPolygonCodec (t1 MultiPolygon, t2 MultiPolygon, t3 MultiPolygon, t4 MultiPolygon)");
+ "CREATE TABLE MultiPolygonCodec (t1 MultiPolygon, t2 MultiPolygon, t3 MultiPolygon, t4"
+ + " MultiPolygon)");
stmt.execute(
- "INSERT INTO MultiPolygonCodec VALUES "
- + "(ST_MPolyFromText('MULTIPOLYGON(((1 1, 1 5,4 9,6 9,9 3,7 2, 1 1)), ((0 0, 50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10)))'), "
- + "ST_MPolyFromText('MULTIPOLYGON(((1 1, 1 8,4 9,6 9,9 3,7 2, 1 1)))'), "
- + "ST_MPolyFromText('MULTIPOLYGON(((0 0, 50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10)))'), null)");
+ "INSERT INTO MultiPolygonCodec VALUES (ST_MPolyFromText('MULTIPOLYGON(((1 1, 1 5,4 9,6 9,9"
+ + " 3,7 2, 1 1)), ((0 0, 50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10)))'),"
+ + " ST_MPolyFromText('MULTIPOLYGON(((1 1, 1 8,4 9,6 9,9 3,7 2, 1 1)))'),"
+ + " ST_MPolyFromText('MULTIPOLYGON(((0 0, 50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10"
+ + " 20,10 10)))'), null)");
stmt.execute(
- "CREATE TABLE MultiPolygonCodec2 (id int not null primary key auto_increment, t1 MultiPolygon)");
+ "CREATE TABLE MultiPolygonCodec2 (id int not null primary key auto_increment, t1"
+ + " MultiPolygon)");
stmt.execute("FLUSH TABLES");
String binUrl =
@@ -137,12 +139,39 @@ public static void beforeAll2() throws Exception {
geoConn = (org.mariadb.jdbc.Connection) DriverManager.getConnection(binUrl);
}
+ private static int toDigit(char hexChar) {
+ int digit = Character.digit(hexChar, 16);
+ if (digit == -1) {
+ throw new IllegalArgumentException("Invalid Hexadecimal Character: " + hexChar);
+ }
+ return digit;
+ }
+
+ public static byte hexToByte(String hexString) {
+ int firstDigit = toDigit(hexString.charAt(0));
+ int secondDigit = toDigit(hexString.charAt(1));
+ return (byte) ((firstDigit << 4) + secondDigit);
+ }
+
+ public static byte[] decodeHexString(String hexString) {
+ if (hexString.length() % 2 == 1) {
+ throw new IllegalArgumentException("Invalid hexadecimal String supplied.");
+ }
+
+ byte[] bytes = new byte[hexString.length() / 2];
+ for (int i = 0; i < hexString.length(); i += 2) {
+ bytes[i / 2] = hexToByte(hexString.substring(i, i + 2));
+ }
+ return bytes;
+ }
+
private ResultSet get() throws SQLException {
Statement stmt = sharedConn.createStatement();
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
ResultSet rs =
stmt.executeQuery(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from MultiPolygonCodec");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " MultiPolygonCodec");
assertTrue(rs.next());
sharedConn.commit();
return rs;
@@ -153,8 +182,8 @@ private CompleteResult getPrepare(org.mariadb.jdbc.Connection con) throws SQLExc
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
PreparedStatement preparedStatement =
con.prepareStatement(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from MultiPolygonCodec"
- + " WHERE 1 > ?");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " MultiPolygonCodec WHERE 1 > ?");
preparedStatement.closeOnCompletion();
preparedStatement.setInt(1, 0);
CompleteResult rs = (CompleteResult) preparedStatement.executeQuery();
@@ -208,32 +237,6 @@ public void getObjectTypePrepare() throws Exception {
getObjectType(getPrepare(sharedConnBinary));
}
- private static int toDigit(char hexChar) {
- int digit = Character.digit(hexChar, 16);
- if (digit == -1) {
- throw new IllegalArgumentException("Invalid Hexadecimal Character: " + hexChar);
- }
- return digit;
- }
-
- public static byte hexToByte(String hexString) {
- int firstDigit = toDigit(hexString.charAt(0));
- int secondDigit = toDigit(hexString.charAt(1));
- return (byte) ((firstDigit << 4) + secondDigit);
- }
-
- public static byte[] decodeHexString(String hexString) {
- if (hexString.length() % 2 == 1) {
- throw new IllegalArgumentException("Invalid hexadecimal String supplied.");
- }
-
- byte[] bytes = new byte[hexString.length() / 2];
- for (int i = 0; i < hexString.length(); i += 2) {
- bytes[i / 2] = hexToByte(hexString.substring(i, i + 2));
- }
- return bytes;
- }
-
public void getObjectType(ResultSet rs) throws Exception {
testErrObject(rs, Integer.class, 1);
testErrObject(rs, String.class, 1);
@@ -303,7 +306,7 @@ private void sendParam(Connection con) throws Exception {
con.prepareStatement("INSERT INTO MultiPolygonCodec2(t1) VALUES (?)")) {
prep.setObject(1, ls1);
prep.execute();
- prep.setObject(1, (MultiPolygon) null);
+ prep.setObject(1, null);
prep.execute();
prep.setObject(1, ls2);
@@ -379,8 +382,8 @@ public void equal() {
});
assertEquals(testPoly, ls1);
assertEquals(testPoly.hashCode(), ls1.hashCode());
- assertFalse(ls1.equals(null));
- assertFalse(ls1.equals(""));
+ assertNotEquals(null, ls1);
+ assertNotEquals("", ls1);
assertNotEquals(
new MultiPolygon(
new Polygon[] {
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/NullCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/NullCodecTest.java
index ce116ca3f..d884310ba 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/NullCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/NullCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -193,9 +192,9 @@ public void getBooleanPrepared() throws SQLException {
}
private void getBoolean(ResultSet rs) throws SQLException {
- assertEquals(false, rs.getBoolean(1));
+ assertFalse(rs.getBoolean(1));
assertTrue(rs.wasNull());
- assertEquals(false, rs.getBoolean("t1alias"));
+ assertFalse(rs.getBoolean("t1alias"));
assertTrue(rs.wasNull());
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java
index be0f674da..1f87f41e7 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/PointCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -39,8 +38,8 @@ public static void beforeAll2() throws Exception {
Statement stmt = sharedConn.createStatement();
stmt.execute("CREATE TABLE PointCodec (t1 POINT, t2 POINT, t3 POINT, t4 POINT)");
stmt.execute(
- "INSERT INTO PointCodec VALUES "
- + "(ST_PointFromText('POINT(10 1)'), ST_PointFromText('POINT(1.5 18)'), ST_PointFromText('POINT(-1 0.55)'), null)");
+ "INSERT INTO PointCodec VALUES (ST_PointFromText('POINT(10 1)'),"
+ + " ST_PointFromText('POINT(1.5 18)'), ST_PointFromText('POINT(-1 0.55)'), null)");
stmt.execute("CREATE TABLE PointCodec2 (id int not null primary key auto_increment, t1 POINT)");
stmt.execute("FLUSH TABLES");
@@ -214,7 +213,7 @@ private void sendParam(Connection con) throws Exception {
try (PreparedStatement prep = con.prepareStatement("INSERT INTO PointCodec2(t1) VALUES (?)")) {
prep.setObject(1, new Point(52.1, 12.8));
prep.execute();
- prep.setObject(1, (Point) null);
+ prep.setObject(1, null);
prep.execute();
prep.setObject(1, new Point(2.2, 3.3));
@@ -251,8 +250,8 @@ public void equal() {
assertEquals(pt, pt);
assertEquals(new Point(0, 10), pt);
assertEquals(new Point(0, 10).hashCode(), pt.hashCode());
- assertFalse(pt.equals(null));
- assertFalse(pt.equals(""));
+ assertNotEquals(null, pt);
+ assertNotEquals("", pt);
assertNotEquals(new Point(0, 20), pt);
assertNotEquals(new Point(10, 10), pt);
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java
index 6bb74431d..143aafa05 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/PolygonCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -93,10 +92,9 @@ public static void beforeAll2() throws Exception {
Statement stmt = sharedConn.createStatement();
stmt.execute("CREATE TABLE PolygonCodec (t1 Polygon, t2 Polygon, t3 Polygon, t4 Polygon)");
stmt.execute(
- "INSERT INTO PolygonCodec VALUES "
- + "(ST_PolygonFromText('POLYGON((1 1,1 5,4 9,6 9,9 3,7 2,1 1))'), "
- + "ST_PolygonFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10 20,10 10))'), "
- + "ST_PolygonFromText('POLYGON((0 0,50 0,50 50,0 50,0 0))'), null)");
+ "INSERT INTO PolygonCodec VALUES (ST_PolygonFromText('POLYGON((1 1,1 5,4 9,6 9,9 3,7 2,1"
+ + " 1))'), ST_PolygonFromText('POLYGON((0 0,50 0,50 50,0 50,0 0), (10 10,20 10,20 20,10"
+ + " 20,10 10))'), ST_PolygonFromText('POLYGON((0 0,50 0,50 50,0 50,0 0))'), null)");
stmt.execute(
"CREATE TABLE PolygonCodec2 (id int not null primary key auto_increment, t1 Polygon)");
stmt.execute("FLUSH TABLES");
@@ -380,7 +378,7 @@ private void sendParam(Connection con) throws Exception {
con.prepareStatement("INSERT INTO PolygonCodec2(t1) VALUES (?)")) {
prep.setObject(1, ls1);
prep.execute();
- prep.setObject(1, (Polygon) null);
+ prep.setObject(1, null);
prep.execute();
prep.setObject(1, ls2);
@@ -439,8 +437,8 @@ public void equal() {
});
assertEquals(testPoly, ls2);
assertEquals(testPoly.hashCode(), ls2.hashCode());
- assertFalse(ls2.equals(null));
- assertFalse(ls2.equals(""));
+ assertNotEquals(null, ls2);
+ assertNotEquals("", ls2);
assertNotEquals(
new Polygon(
new LineString[] {
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/SmallIntCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/SmallIntCodecTest.java
index 39b07a25a..6159d4f92 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/SmallIntCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/SmallIntCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -35,8 +34,8 @@ public static void beforeAll2() throws SQLException {
stmt.execute(
"CREATE TABLE SmallIntCodec2 (id int not null primary key auto_increment, t1 SMALLINT)");
stmt.execute(
- "CREATE TABLE SmallIntCodecUnsigned (t1 SMALLINT UNSIGNED, t2 SMALLINT UNSIGNED, t3 SMALLINT UNSIGNED, t4 SMALLINT "
- + "UNSIGNED)");
+ "CREATE TABLE SmallIntCodecUnsigned (t1 SMALLINT UNSIGNED, t2 SMALLINT UNSIGNED, t3"
+ + " SMALLINT UNSIGNED, t4 SMALLINT UNSIGNED)");
stmt.execute("INSERT INTO SmallIntCodec VALUES (0, 1, -1, null)");
stmt.execute("INSERT INTO SmallIntCodecUnsigned VALUES (0, 1, 65535, null)");
stmt.execute("FLUSH TABLES");
@@ -97,7 +96,7 @@ public void getObjectPrepared() throws SQLException {
}
private void getObject(ResultSet rs) throws SQLException {
- Object o = rs.getObject(1);
+ rs.getObject(1);
assertEquals(Short.valueOf("0"), rs.getObject(1));
assertFalse(rs.wasNull());
assertEquals(Short.valueOf("1"), rs.getObject(2));
@@ -972,7 +971,7 @@ private void sendParam(Connection con) throws SQLException {
assertTrue(rs.next());
assertEquals(2, rs.getShort(2));
- rs.updateObject("t1", (Short) null);
+ rs.updateObject("t1", null);
rs.updateRow();
assertEquals(0, rs.getShort(2));
assertTrue(rs.wasNull());
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/TimeCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/TimeCodecTest.java
index 4b68e51ca..ef2082828 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/TimeCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/TimeCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/TinyIntCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/TinyIntCodecTest.java
index 9e419ac27..86a2dc359 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/TinyIntCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/TinyIntCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -36,8 +35,8 @@ public static void beforeAll2() throws SQLException {
stmt.execute(
"CREATE TABLE TinyIntCodec2 (id int not null primary key auto_increment, t1 TINYINT)");
stmt.execute(
- "CREATE TABLE TinyIntCodecUnsigned (t1 TINYINT UNSIGNED, t2 TINYINT UNSIGNED, t3 TINYINT UNSIGNED, t4 TINYINT "
- + "UNSIGNED)");
+ "CREATE TABLE TinyIntCodecUnsigned (t1 TINYINT UNSIGNED, t2 TINYINT UNSIGNED, t3 TINYINT"
+ + " UNSIGNED, t4 TINYINT UNSIGNED)");
stmt.execute("INSERT INTO TinyIntCodec VALUES (0, 1, -1, null)");
stmt.execute("INSERT INTO TinyIntCodecUnsigned VALUES (0, 1, 255, null)");
stmt.execute("FLUSH TABLES");
@@ -1027,7 +1026,7 @@ private void sendParam(Connection con) throws SQLException {
assertTrue(rs.next());
assertEquals(2, rs.getByte(2));
- rs.updateObject(2, (Byte) null);
+ rs.updateObject(2, null);
rs.updateRow();
assertEquals(0, rs.getByte(2));
assertTrue(rs.wasNull());
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/UuidCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/UuidCodecTest.java
index fe1378b45..9c51ab78d 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/UuidCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/UuidCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -41,7 +40,9 @@ && minVersion(10, 7, 0)
stmt.execute("CREATE TABLE UuidCodec (t1 UUID, t2 UUID, t3 UUID, t4 UUID)");
stmt.execute("CREATE TABLE UuidCodec2 (t1 UUID)");
stmt.execute(
- "INSERT INTO UuidCodec VALUES ('123e4567-e89b-12d3-a456-426655440000', '93aac041-1a14-11ec-ab4e-f859713e4be4', 'ffffffff-ffff-ffff-ffff-fffffffffffe', null)");
+ "INSERT INTO UuidCodec VALUES ('123e4567-e89b-12d3-a456-426655440000',"
+ + " '93aac041-1a14-11ec-ab4e-f859713e4be4', 'ffffffff-ffff-ffff-ffff-fffffffffffe',"
+ + " null)");
}
private ResultSet get() throws SQLException {
@@ -56,20 +57,6 @@ private ResultSet get() throws SQLException {
return rs;
}
- private ResultSet getAdd(String additional) throws SQLException {
- try (Connection con = createCon(additional)) {
- java.sql.Statement stmt = con.createStatement();
- stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
- stmt.closeOnCompletion();
- ResultSet rs =
- stmt.executeQuery(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from UuidCodec");
- assertTrue(rs.next());
- con.commit();
- return rs;
- }
- }
-
private ResultSet getPrepare(Connection con) throws SQLException {
java.sql.Statement stmt = con.createStatement();
stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
@@ -350,7 +337,17 @@ public void getMetaData() throws SQLException {
assertEquals("", meta.getSchemaName(1));
assertEquals(36, meta.getColumnDisplaySize(1));
- rs = getAdd("&uuidAsString=True");
+ try (Connection con = createCon("&uuidAsString=True")) {
+ java.sql.Statement stmt = con.createStatement();
+ stmt.execute("START TRANSACTION"); // if MAXSCALE ensure using WRITER
+ stmt.closeOnCompletion();
+ rs =
+ stmt.executeQuery(
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from UuidCodec");
+ assertTrue(rs.next());
+ con.commit();
+ }
+
meta = rs.getMetaData();
assertEquals("uuid", meta.getColumnTypeName(1));
assertEquals(sharedConn.getCatalog(), meta.getCatalogName(1));
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/VarbinaryCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/VarbinaryCodecTest.java
index 3ec8b48fa..f244ac71e 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/VarbinaryCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/VarbinaryCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -35,11 +34,12 @@ public static void beforeAll2() throws SQLException {
drop();
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE VarbinaryCodec (t1 VARBINARY(20), t2 VARBINARY(30), t3 VARBINARY(20), t4 VARBINARY(20))");
+ "CREATE TABLE VarbinaryCodec (t1 VARBINARY(20), t2 VARBINARY(30), t3 VARBINARY(20), t4"
+ + " VARBINARY(20))");
stmt.execute("CREATE TABLE VarbinaryCodec2 (t1 VARBINARY(20))");
stmt.execute(
- "INSERT INTO VarbinaryCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31 23:59:59.152',"
- + " '23:54:51.840010', null)");
+ "INSERT INTO VarbinaryCodec VALUES ('0', '1', 'some🌟', null), ('2011-01-01', '2010-12-31"
+ + " 23:59:59.152', '23:54:51.840010', null)");
}
private ResultSet get() throws SQLException {
@@ -48,7 +48,8 @@ private ResultSet get() throws SQLException {
stmt.closeOnCompletion();
ResultSet rs =
stmt.executeQuery(
- "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from VarbinaryCodec");
+ "select t1 as t1alias, t2 as t2alias, t3 as t3alias, t4 as t4alias from"
+ + " VarbinaryCodec");
assertTrue(rs.next());
sharedConn.commit();
return rs;
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/VarcharCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/VarcharCodecTest.java
index 69ad76727..14b0f776b 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/VarcharCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/VarcharCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -41,8 +40,8 @@ public static void beforeAll2() throws SQLException {
after2();
Statement stmt = sharedConn.createStatement();
stmt.execute(
- "CREATE TABLE StringCodec (t1 VARCHAR(255), t2 VARCHAR(30), t3 VARCHAR(20), t4 VARCHAR(20)) CHARACTER "
- + "SET utf8mb4 COLLATE utf8mb4_unicode_ci");
+ "CREATE TABLE StringCodec (t1 VARCHAR(255), t2 VARCHAR(30), t3 VARCHAR(20), t4 VARCHAR(20))"
+ + " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
stmt.execute(
"INSERT INTO StringCodec VALUES ('0', '1', 'some🌟', null), "
+ "('2011-01-01', '2010-12-31 23:59:59.152', '23:54:51.840010', null), "
@@ -52,7 +51,8 @@ public static void beforeAll2() throws SQLException {
"CREATE TABLE StringParamCodec(id int not null primary key auto_increment, t1 VARCHAR(20)) "
+ "CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
stmt.execute(
- "CREATE TABLE StringCodecWrong (t1 VARCHAR(20)) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
+ "CREATE TABLE StringCodecWrong (t1 VARCHAR(20)) CHARACTER SET utf8mb4 COLLATE"
+ + " utf8mb4_unicode_ci");
stmt.execute("FLUSH TABLES");
}
@@ -1058,7 +1058,7 @@ private void sendParam(Connection con) throws SQLException {
@Test
public void wrongUtf8String() throws SQLException {
final byte[] utf8WrongBytes =
- new byte[] {(byte) 0xc2, (byte) 0f, (byte) 0xDB, (byte) 0, (byte) 0xE1, (byte) 0};
+ new byte[] {(byte) 0xc2, (byte) 0x0f, (byte) 0xDB, (byte) 0x00, (byte) 0xE1, (byte) 0x00};
String st = new String(utf8WrongBytes);
wrongUtf8(sharedConn, st);
diff --git a/src/test/java/org/mariadb/jdbc/integration/codec/YearCodecTest.java b/src/test/java/org/mariadb/jdbc/integration/codec/YearCodecTest.java
index 614830e4a..2a7002958 100644
--- a/src/test/java/org/mariadb/jdbc/integration/codec/YearCodecTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/codec/YearCodecTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.codec;
import static org.junit.jupiter.api.Assertions.*;
@@ -34,11 +33,13 @@ public static void beforeAll2() throws SQLException {
if (isMariaDBServer() && !isXpand()) {
stmt.execute("CREATE TABLE YearCodec (t1 YEAR(2), t2 YEAR(4), t3 YEAR(4), t4 YEAR(4))");
stmt.execute(
- "INSERT INTO YearCodec VALUES ('2010', '1901', '2155', null), (80, '1901', '2155', null)");
+ "INSERT INTO YearCodec VALUES ('2010', '1901', '2155', null), (80, '1901', '2155',"
+ + " null)");
} else {
stmt.execute("CREATE TABLE YearCodec (t1 YEAR(4), t2 YEAR(4), t3 YEAR(4), t4 YEAR(4))");
stmt.execute(
- "INSERT INTO YearCodec VALUES ('2010', '1901', '2155', null), (1980, '1901', '2155', null)");
+ "INSERT INTO YearCodec VALUES ('2010', '1901', '2155', null), (1980, '1901', '2155',"
+ + " null)");
}
stmt.execute("FLUSH TABLES");
}
@@ -253,14 +254,14 @@ public void getBooleanPrepare() throws SQLException {
}
public void getBoolean(ResultSet rs) throws SQLException {
- assertEquals(true, rs.getBoolean(1));
+ assertTrue(rs.getBoolean(1));
assertFalse(rs.wasNull());
- assertEquals(true, rs.getBoolean(2));
- assertEquals(true, rs.getBoolean("t2alias"));
+ assertTrue(rs.getBoolean(2));
+ assertTrue(rs.getBoolean("t2alias"));
assertFalse(rs.wasNull());
- assertEquals(true, rs.getBoolean(3));
+ assertTrue(rs.getBoolean(3));
assertFalse(rs.wasNull());
- assertEquals(false, rs.getBoolean(4));
+ assertFalse(rs.getBoolean(4));
assertTrue(rs.wasNull());
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/resultset/ReadResultSetTest.java b/src/test/java/org/mariadb/jdbc/integration/resultset/ReadResultSetTest.java
index feeed687b..fffa7719a 100644
--- a/src/test/java/org/mariadb/jdbc/integration/resultset/ReadResultSetTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/resultset/ReadResultSetTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.resultset;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/resultset/ResultSetMetadataTest.java b/src/test/java/org/mariadb/jdbc/integration/resultset/ResultSetMetadataTest.java
index 970642c1e..7c0b3d1d2 100644
--- a/src/test/java/org/mariadb/jdbc/integration/resultset/ResultSetMetadataTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/resultset/ResultSetMetadataTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.resultset;
import static org.junit.jupiter.api.Assertions.*;
@@ -34,8 +33,8 @@ public static void beforeAll2() throws SQLException {
stmt.execute("CREATE TABLE ResultSetTest (t1 int not null primary key auto_increment, t2 int)");
stmt.execute("INSERT INTO ResultSetTest(t2) values (1),(2),(3),(4),(5),(6),(7),(8)");
stmt.execute(
- "CREATE TABLE test_rsmd(id_col int not null primary key auto_increment, "
- + "nullable_col varchar(20), unikey_col int unique, char_col char(10), us smallint unsigned)");
+ "CREATE TABLE test_rsmd(id_col int not null primary key auto_increment, nullable_col"
+ + " varchar(20), unikey_col int unique, char_col char(10), us smallint unsigned)");
stmt.execute("CREATE TABLE resultsetmetadatatest1(id int, name varchar(20))");
stmt.execute("CREATE TABLE resultsetmetadatatest2(id int, name varchar(20))");
stmt.execute("CREATE TABLE resultsetmetadatatest3(id int, name varchar(20))");
@@ -128,7 +127,8 @@ public void conj84() throws Exception {
sharedConn
.createStatement()
.executeQuery(
- "select resultsetmetadatatest1.*, resultsetmetadatatest2.* FROM resultsetmetadatatest1 join resultsetmetadatatest2");
+ "select resultsetmetadatatest1.*, resultsetmetadatatest2.* FROM"
+ + " resultsetmetadatatest1 join resultsetmetadatatest2");
assertTrue(rs.next());
assertEquals(rs.findColumn("id"), 1);
assertEquals(rs.findColumn("name"), 2);
@@ -199,7 +199,8 @@ public void blankTableNameMeta() throws Exception {
sharedConn
.createStatement()
.executeQuery(
- "SELECT id AS id_alias FROM resultsetmetadatatest3 AS resultsetmetadatatest1_alias");
+ "SELECT id AS id_alias FROM resultsetmetadatatest3 AS"
+ + " resultsetmetadatatest1_alias");
ResultSetMetaData rsmd = rs.getMetaData();
assertEquals("resultsetmetadatatest3", rsmd.getTableName(1));
@@ -211,7 +212,8 @@ public void blankTableNameMeta() throws Exception {
connection
.createStatement()
.executeQuery(
- "SELECT id AS id_alias FROM resultsetmetadatatest3 AS resultsetmetadatatest1_alias");
+ "SELECT id AS id_alias FROM resultsetmetadatatest3 AS"
+ + " resultsetmetadatatest1_alias");
rsmd = rs.getMetaData();
assertEquals("", rsmd.getTableName(1));
@@ -242,5 +244,13 @@ public void databaseResultsetMeta() throws SQLException {
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals("TABLE_TYPE", rsMeta.getColumnName(1));
assertEquals("", rsMeta.getTableName(1));
+ assertEquals("TABLE", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("SYSTEM VIEW", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("VIEW", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("LOCAL TEMPORARY", rs.getString(1));
+ assertFalse(rs.next());
}
}
diff --git a/src/test/java/org/mariadb/jdbc/integration/resultset/RowChangeTest.java b/src/test/java/org/mariadb/jdbc/integration/resultset/RowChangeTest.java
index 0f74e0c0e..8edf80bd9 100644
--- a/src/test/java/org/mariadb/jdbc/integration/resultset/RowChangeTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/resultset/RowChangeTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.resultset;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/resultset/StreamingRowChangeTest.java b/src/test/java/org/mariadb/jdbc/integration/resultset/StreamingRowChangeTest.java
index f4ac13ac6..fe4130142 100644
--- a/src/test/java/org/mariadb/jdbc/integration/resultset/StreamingRowChangeTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/resultset/StreamingRowChangeTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.resultset;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxy.java b/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxy.java
index 5cb01193d..45c0eb24f 100644
--- a/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxy.java
+++ b/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxy.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.tools;
import java.io.IOException;
diff --git a/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxySocket.java b/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxySocket.java
index 6e46bc941..6cd5489c2 100644
--- a/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxySocket.java
+++ b/src/test/java/org/mariadb/jdbc/integration/tools/TcpProxySocket.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.tools;
import java.io.*;
diff --git a/src/test/java/org/mariadb/jdbc/integration/util/Env2CredentialPlugin.java b/src/test/java/org/mariadb/jdbc/integration/util/Env2CredentialPlugin.java
index 72ec03d8d..e7fa32a2b 100644
--- a/src/test/java/org/mariadb/jdbc/integration/util/Env2CredentialPlugin.java
+++ b/src/test/java/org/mariadb/jdbc/integration/util/Env2CredentialPlugin.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.util;
import org.mariadb.jdbc.plugin.Credential;
diff --git a/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryBasicTest.java b/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryBasicTest.java
index 1ecc12b7e..b944f59af 100644
--- a/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryBasicTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryBasicTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.util;
import java.io.IOException;
diff --git a/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryTest.java b/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryTest.java
index 3b5a9a933..604021eab 100644
--- a/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryTest.java
+++ b/src/test/java/org/mariadb/jdbc/integration/util/SocketFactoryTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.integration.util;
import java.io.IOException;
diff --git a/src/test/java/org/mariadb/jdbc/unit/client/HostnameVerifierTest.java b/src/test/java/org/mariadb/jdbc/unit/client/HostnameVerifierTest.java
index 0f7abf5f9..e75c1a437 100644
--- a/src/test/java/org/mariadb/jdbc/unit/client/HostnameVerifierTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/client/HostnameVerifierTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.client;
import static org.junit.jupiter.api.Assertions.*;
@@ -47,8 +46,7 @@ public void verifyCn() throws Exception {
// CN=test.com
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIC+zCCAeOgAwIBAgIJANin/585wAXHMA0GCSqGSIb3DQEBBQUAMBMxETAPBgNV\n"
+ "BAMMCHRlc3QuY29tMCAXDTE3MDYyMzEzNTI1NloYDzIxMTcwNTMwMTM1MjU2WjAT\n"
+ "MREwDwYDVQQDDAh0ZXN0LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC\n"
@@ -82,8 +80,7 @@ public void verifyNoSan() throws Exception {
// CN=*.mariadb.com
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIDLjCCAhYCFEWSUFTlr/qGo/jC5R1nNQdE5zmrMA0GCSqGSIb3DQEBCwUAMFIx\n"
+ "CzAJBgNVBAYTAkNOMQswCQYDVQQIDAJHRDELMAkGA1UEBwwCU1oxEjAQBgNVBAoM\n"
+ "CUFjbWUsSW5jLjEVMBMGA1UEAwwMQWNtZSBSb290IENBMCAXDTIxMDMzMDA5MjQ1\n"
@@ -115,8 +112,7 @@ public void verifyNonAsciiCn() throws Exception {
// CN=😎.com = "\uD83D\uDE0E"
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIDWTCCAkGgAwIBAgIJAI38v686DwcOMA0GCSqGSIb3DQEBBQUAMEIxCzAJBgNV\n"
+ "BAYTAlVTMQswCQYDVQQIDAJDQTETMBEGA1UECgwKQWNtZSwgSW5jLjERMA8GA1UE\n"
+ "AwwI8J+Yji5jb20wIBcNMTcwNjIzMTQyNzQ2WhgPMjExNzA1MzAxNDI3NDZaMEIx\n"
@@ -156,8 +152,7 @@ public void verifySubjectAlt() throws Exception {
// -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIDUzCCAjugAwIBAgIJAPMG38xrY9DcMA0GCSqGSIb3DQEBCwUAMFMxCzAJBgNV\n"
+ "BAYTAkNOMQswCQYDVQQIDAJHRDELMAkGA1UEBwwCU1oxEzARBgNVBAoMCkFjbWUs\n"
+ "IEluYy4xFTATBgNVBAMMDEFjbWUgUm9vdCBDQTAgFw0xNzA2MjMxNjEyNTlaGA8y\n"
@@ -203,8 +198,7 @@ public void verifySubjectAltOnly() throws Exception {
// subjectAlt=foo.com
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIESjCCAzKgAwIBAgIJAIz+EYMBU6aYMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n"
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n"
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAMU\n"
@@ -233,9 +227,9 @@ public void verifySubjectAltOnly() throws Exception {
verifyExceptionEqual(
"a.foo.com",
cert,
- "CN not found in certificate principal "
- + "\"EMAILADDRESS=juliusdavies@gmail.com, OU=test certificates, O=httpcomponents, L=Forest Hill, "
- + "ST=Maryland, C=US\" and DNS host \"a.foo.com\" doesn't correspond to SAN[{DNS:\"foo.com\"}]");
+ "CN not found in certificate principal \"EMAILADDRESS=juliusdavies@gmail.com, OU=test"
+ + " certificates, O=httpcomponents, L=Forest Hill, ST=Maryland, C=US\" and DNS host"
+ + " \"a.foo.com\" doesn't correspond to SAN[{DNS:\"foo.com\"}]");
}
@Test
@@ -267,7 +261,8 @@ public void noCn() throws Exception {
verifyExceptionEqual(
"a.foo.com",
cert,
- "CN not found in certificate principal \"O=Internet Widgits Pty Ltd, ST=Some-State, C=AU\" and certificate doesn't contain SAN");
+ "CN not found in certificate principal \"O=Internet Widgits Pty Ltd, ST=Some-State, C=AU\""
+ + " and certificate doesn't contain SAN");
}
@Test
@@ -275,8 +270,7 @@ public void verifyMultipleCn() throws Exception {
// CN=test1.org, CN=test2.org
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIDgzCCAmugAwIBAgIJAPqfD+J8D4gqMA0GCSqGSIb3DQEBBQUAMFcxCzAJBgNV\n"
+ "BAYTAlVTMQswCQYDVQQIDAJDQTETMBEGA1UECgwKQWNtZSwgSW5jLjESMBAGA1UE\n"
+ "AwwJdGVzdDEub3JnMRIwEAYDVQQDDAl0ZXN0Mi5vcmcwIBcNMTcwNjIzMTYxNDIx\n"
@@ -309,8 +303,7 @@ public void verifyWilcardCn() throws Exception {
// CN=*.foo.com
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIESDCCAzCgAwIBAgIJAIz+EYMBU6aUMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n"
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n"
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAMU\n"
@@ -351,8 +344,7 @@ public void verifyWilcardCnOnTld() throws Exception {
// CN=*.co.jp
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIERjCCAy6gAwIBAgIJAIz+EYMBU6aVMA0GCSqGSIb3DQEBBQUAMIGiMQswCQYD\n"
+ "VQQGEwJDQTELMAkGA1UECBMCQkMxEjAQBgNVBAcTCVZhbmNvdXZlcjEWMBQGA1UE\n"
+ "ChMNd3d3LmN1Y2JjLmNvbTEUMBIGA1UECxQLY29tbW9uc19zc2wxHTAbBgNVBAMU\n"
@@ -387,8 +379,7 @@ public void subjectAltUsesLocalDomainAndIp() throws Exception {
// subjectAltName=DNS:localhost.localdomain,DNS:localhost,IP:127.0.0.1
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIDfDCCAmSgAwIBAgIURZJQVOWv+oaj+MLlHWc1B0TnOaowDQYJKoZIhvcNAQEL\n"
+ "BQAwUjELMAkGA1UEBhMCQ04xCzAJBgNVBAgMAkdEMQswCQYDVQQHDAJTWjESMBAG\n"
+ "A1UECgwJQWNtZSxJbmMuMRUwEwYDVQQDDAxBY21lIFJvb3QgQ0EwIBcNMjEwMzMw\n"
@@ -418,22 +409,22 @@ public void subjectAltUsesLocalDomainAndIp() throws Exception {
verifyExceptionEqual(
"local.host",
cert,
- "DNS host \"local.host\" doesn't correspond to certificate "
- + "CN \"*.mariadb.org\" and SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
+ "DNS host \"local.host\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
HostnameVerifier.verify("127.0.0.1", cert, -1);
verifyExceptionEqual(
"127.0.0.2",
cert,
- "IPv4 host \"127.0.0.2\" doesn't correspond to certificate "
- + "CN \"*.mariadb.org\" and SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
+ "IPv4 host \"127.0.0.2\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
HostnameVerifier.verify("2001:db8:3902:3468:0:0:0:443", cert, -1);
verifyExceptionEqual(
"2001:db8:1::",
cert,
- "IPv6 host \"2001:db8:1::\" doesn't correspond to certificate "
- + "CN \"*.mariadb.org\" and SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
+ "IPv6 host \"2001:db8:1::\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"localhost.localdomain\"},{DNS:\"localhost\"},{IP:\"127.0.0.1\"},{IP:\"2001:db8:3902:3468:0:0:0:443\"}]");
}
@Test
@@ -441,8 +432,7 @@ public void wildcardsCannotMatchIpAddresses() throws Exception {
// openssl req -x509 -nodes -days 36500 -subj '/CN=*.0.0.1' -newkey rsa:512 -out cert.pem
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIDVzCCAj+gAwIBAgIJAN9L/Y9e1F7dMA0GCSqGSIb3DQEBBQUAMEExCzAJBgNV\n"
+ "BAYTAlVTMQswCQYDVQQIDAJDQTETMBEGA1UECgwKQWNtZSwgSW5jLjEQMA4GA1UE\n"
+ "AwwHKi4wLjAuMTAgFw0xNzA2MjMxNTU3MTdaGA8yMTE3MDUzMDE1NTcxN1owQTEL\n"
@@ -474,8 +464,7 @@ public void subjectAltNameWithWildcard() throws Exception {
// subjectAltName=DNS:*.other.org,DNS:a*b.other2.com
X509Certificate cert =
getCertificate(
- ""
- + "-----BEGIN CERTIFICATE-----\n"
+ "-----BEGIN CERTIFICATE-----\n"
+ "MIIDVjCCAj6gAwIBAgIJAPMG38xrY9DaMA0GCSqGSIb3DQEBCwUAMFMxCzAJBgNV\n"
+ "BAYTAkNOMQswCQYDVQQIDAJHRDELMAkGA1UEBwwCU1oxEzARBgNVBAoMCkFjbWUs\n"
+ "IEluYy4xFTATBgNVBAMMDEFjbWUgUm9vdCBDQTAgFw0xNzA2MjMxNjA1MTlaGA8y\n"
@@ -499,35 +488,35 @@ public void subjectAltNameWithWildcard() throws Exception {
verifyExceptionEqual(
"other.org",
cert,
- "DNS host \"other.org\" doesn't correspond "
- + "to certificate CN \"*.mariadb.org\" and SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
+ "DNS host \"other.org\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
HostnameVerifier.verify("www.other.org", cert, -1);
verifyExceptionEqual(
"other2.org",
cert,
- "DNS host \"other2.org\" doesn't correspond "
- + "to certificate CN \"*.mariadb.org\" and SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
+ "DNS host \"other2.org\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
verifyExceptionEqual(
"www.other2.org",
cert,
- "DNS host \"www.other2.org\" doesn't correspond "
- + "to certificate CN \"*.mariadb.org\" and SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
+ "DNS host \"www.other2.org\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
HostnameVerifier.verify("ab.other2.com", cert, -1);
HostnameVerifier.verify("axxxxb.other2.com", cert, -1);
verifyExceptionEqual(
"axxxxbc.other2.org",
cert,
- "DNS host \"axxxxbc.other2.org\" doesn't "
- + "correspond to certificate CN \"*.mariadb.org\" and SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
+ "DNS host \"axxxxbc.other2.org\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
verifyExceptionEqual(
"caxxxxb.other2.org",
cert,
- "DNS host \"caxxxxb.other2.org\" doesn't "
- + "correspond to certificate CN \"*.mariadb.org\" and SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
+ "DNS host \"caxxxxb.other2.org\" doesn't correspond to certificate CN \"*.mariadb.org\" and"
+ + " SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
verifyExceptionEqual(
"a.axxxxb.other2.org",
cert,
- "DNS host \"a.axxxxb.other2.org\" doesn't "
- + "correspond to certificate CN \"*.mariadb.org\" and SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
+ "DNS host \"a.axxxxb.other2.org\" doesn't correspond to certificate CN \"*.mariadb.org\""
+ + " and SAN[{DNS:\"*.other.org\"},{DNS:\"a*b.other2.com\"}]");
}
}
diff --git a/src/test/java/org/mariadb/jdbc/unit/client/PrepareCacheTest.java b/src/test/java/org/mariadb/jdbc/unit/client/PrepareCacheTest.java
index 6e5b31456..90761fc57 100644
--- a/src/test/java/org/mariadb/jdbc/unit/client/PrepareCacheTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/client/PrepareCacheTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.client;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/client/ServerVersionUtilityTest.java b/src/test/java/org/mariadb/jdbc/unit/client/ServerVersionUtilityTest.java
index 717635e1f..f99ad3864 100644
--- a/src/test/java/org/mariadb/jdbc/unit/client/ServerVersionUtilityTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/client/ServerVersionUtilityTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.client;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/client/result/CompleteResultTest.java b/src/test/java/org/mariadb/jdbc/unit/client/result/CompleteResultTest.java
index 170910ac5..93053fc85 100644
--- a/src/test/java/org/mariadb/jdbc/unit/client/result/CompleteResultTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/client/result/CompleteResultTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.client.result;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/client/socket/PacketWriterTest.java b/src/test/java/org/mariadb/jdbc/unit/client/socket/PacketWriterTest.java
index 0b86e166d..cfa91b87d 100644
--- a/src/test/java/org/mariadb/jdbc/unit/client/socket/PacketWriterTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/client/socket/PacketWriterTest.java
@@ -1,3 +1,6 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2023 MariaDB Corporation Ab
package org.mariadb.jdbc.unit.client.socket;
import java.io.IOException;
diff --git a/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509KeyManagerTest.java b/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509KeyManagerTest.java
index d4a0e315b..16fa4894f 100644
--- a/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509KeyManagerTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509KeyManagerTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.client.tls;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509TrustingManagerTest.java b/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509TrustingManagerTest.java
index 484a62731..bf2e09cb1 100644
--- a/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509TrustingManagerTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/client/tls/MariaDbX509TrustingManagerTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.client.tls;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/export/HaModeTest.java b/src/test/java/org/mariadb/jdbc/unit/export/HaModeTest.java
index b4bb8d3b1..f46bf63b8 100644
--- a/src/test/java/org/mariadb/jdbc/unit/export/HaModeTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/export/HaModeTest.java
@@ -1,7 +1,6 @@
-// SPDX-License-Identifier: LGPL-2.1-or-later
-// Copyright (c) 2012-2014 Monty Program Ab
-// Copyright (c) 2023 MariaDB Corporation Ab
-
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2023 MariaDB Corporation Ab
package org.mariadb.jdbc.unit.export;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -33,14 +32,16 @@ private void getAvailableHostWithoutConnectionNumber(HaMode haMode) {
ConcurrentMap denyList = new ConcurrentHashMap<>();
HostCounter hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), false);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, true);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), false);
}
assertEquals("prim1:34,prim2:33,prim3:33", hostCounter.results());
haMode.resetLast();
hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, false).get(), false);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, false);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), false);
}
assertEquals("slave1:34,slave2:33,slave3:33", hostCounter.results());
@@ -50,7 +51,8 @@ private void getAvailableHostWithoutConnectionNumber(HaMode haMode) {
hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), false);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, true);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), false);
}
assertEquals("prim1:50,prim3:50", hostCounter.results());
@@ -60,7 +62,8 @@ private void getAvailableHostWithoutConnectionNumber(HaMode haMode) {
denyList.put(hostAddresses.get(4), System.currentTimeMillis() + 1000);
hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, false).get(), false);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, false);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), false);
}
assertEquals("slave1:50,slave3:50", hostCounter.results());
}
@@ -96,7 +99,8 @@ private void getAvailableHostWithConnectionNumber(HaMode haMode) {
ConcurrentMap denyList = new ConcurrentHashMap<>();
HostCounter hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), true);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, true);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), true);
}
assertEquals("prim2:25,prim3:75", hostCounter.results());
@@ -105,7 +109,8 @@ private void getAvailableHostWithConnectionNumber(HaMode haMode) {
host3.setThreadsConnected(100);
hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), true);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, true);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), true);
}
assertEquals("prim1:34,prim2:33,prim3:33", hostCounter.results());
@@ -114,7 +119,8 @@ private void getAvailableHostWithConnectionNumber(HaMode haMode) {
slave3.setThreadsConnected(100);
hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, false).get(), true);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, false);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), true);
}
assertEquals("slave2:25,slave3:75", hostCounter.results());
@@ -125,7 +131,8 @@ private void getAvailableHostWithConnectionNumber(HaMode haMode) {
host3.setThreadsConnected(100);
hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, true).get(), true);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, true);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), true);
}
assertEquals("prim1:25,prim3:75", hostCounter.results());
@@ -137,12 +144,13 @@ private void getAvailableHostWithConnectionNumber(HaMode haMode) {
slave3.setThreadsConnected(100);
hostCounter = new HostCounter();
for (int i = 0; i < 100; i++) {
- hostCounter.add(haMode.getAvailableHost(hostAddresses, denyList, false).get(), true);
+ Optional availHost = haMode.getAvailableHost(hostAddresses, denyList, false);
+ if (availHost.isPresent()) hostCounter.add(availHost.get(), true);
}
assertEquals("slave1:25,slave3:75", hostCounter.results());
}
- private class HostCounter {
+ private static class HostCounter {
Map hosts = new HashMap<>();
public void add(HostAddress hostAddress, boolean increment) {
diff --git a/src/test/java/org/mariadb/jdbc/unit/plugin/AuthenticationPluginLoaderTest.java b/src/test/java/org/mariadb/jdbc/unit/plugin/AuthenticationPluginLoaderTest.java
index 460313365..3fe43bee5 100644
--- a/src/test/java/org/mariadb/jdbc/unit/plugin/AuthenticationPluginLoaderTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/plugin/AuthenticationPluginLoaderTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.plugin;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/plugin/TlsSocketPluginLoaderTest.java b/src/test/java/org/mariadb/jdbc/unit/plugin/TlsSocketPluginLoaderTest.java
index b02b9273c..d3fb58690 100644
--- a/src/test/java/org/mariadb/jdbc/unit/plugin/TlsSocketPluginLoaderTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/plugin/TlsSocketPluginLoaderTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.plugin;
import static org.junit.jupiter.api.Assertions.assertTrue;
diff --git a/src/test/java/org/mariadb/jdbc/unit/type/GeometryTest.java b/src/test/java/org/mariadb/jdbc/unit/type/GeometryTest.java
index 1a7ff792e..06dd727f0 100644
--- a/src/test/java/org/mariadb/jdbc/unit/type/GeometryTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/type/GeometryTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.type;
import static org.junit.jupiter.api.Assertions.*;
@@ -203,7 +202,7 @@ public void testMultiLinestringEncoding() throws SQLException {
});
assertEquals(ml, geo);
assertEquals(ml.hashCode(), geo.hashCode());
- assertFalse(geo.equals("wrong"));
+ assertNotEquals("wrong", geo);
}
@Test
@@ -257,7 +256,7 @@ public void testMultiPolygonEncoding() throws SQLException {
});
assertEquals(ml, geo);
assertEquals(ml.hashCode(), geo.hashCode());
- assertFalse(geo.equals("wrong"));
+ assertNotEquals("wrong", geo);
}
@Test
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/ClientParserTest.java b/src/test/java/org/mariadb/jdbc/unit/util/ClientParserTest.java
index aa2efc3a3..264ed7098 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/ClientParserTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/ClientParserTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java b/src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java
index 7d30b7fb1..ade5a6f18 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util;
import static org.junit.jupiter.api.Assertions.*;
@@ -55,15 +54,15 @@ public void testWrongHostFormat() {
@Test
public void testNoAdditionalPart() throws SQLException {
- assertEquals(null, Configuration.parse("jdbc:mariadb://localhost/").database());
- assertEquals(null, Configuration.parse("jdbc:mariadb://localhost/?socketTimeout=50").user());
- assertEquals(null, Configuration.parse("jdbc:mariadb://localhost").database());
- assertEquals(null, Configuration.parse("jdbc:mariadb://localhost").user());
+ assertNull(Configuration.parse("jdbc:mariadb://localhost/").database());
+ assertNull(Configuration.parse("jdbc:mariadb://localhost/?socketTimeout=50").user());
+ assertNull(Configuration.parse("jdbc:mariadb://localhost").database());
+ assertNull(Configuration.parse("jdbc:mariadb://localhost").user());
assertEquals(
50,
Configuration.parse("jdbc:mariadb://localhost?socketTimeout=50&file=/tmp/test")
.socketTimeout());
- assertEquals(null, Configuration.parse("jdbc:mariadb://localhost?").user());
+ assertNull(Configuration.parse("jdbc:mariadb://localhost?").user());
}
@Test
@@ -81,7 +80,7 @@ public void testAliases() throws SQLException {
@Test
public void testDatabaseOnly() throws SQLException {
assertEquals("DB", Configuration.parse("jdbc:mariadb://localhost/DB").database());
- assertEquals(null, Configuration.parse("jdbc:mariadb://localhost/DB").user());
+ assertNull(Configuration.parse("jdbc:mariadb://localhost/DB").user());
}
@Test
@@ -167,24 +166,24 @@ public void testAcceptsUrl() {
public void testConfigurationIsolation() throws Throwable {
Configuration conf =
Configuration.parse("jdbc:mariadb://localhost/test?transactionIsolation=REPEATABLE-READ");
- assertTrue(TransactionIsolation.REPEATABLE_READ == conf.transactionIsolation());
+ assertSame(TransactionIsolation.REPEATABLE_READ, conf.transactionIsolation());
conf = Configuration.parse("jdbc:mariadb://localhost/test");
assertNull(conf.transactionIsolation());
conf =
Configuration.parse("jdbc:mariadb://localhost/test?transactionIsolation=repeatable-read");
- assertTrue(TransactionIsolation.REPEATABLE_READ == conf.transactionIsolation());
+ assertSame(TransactionIsolation.REPEATABLE_READ, conf.transactionIsolation());
conf = Configuration.parse("jdbc:mariadb://localhost/test?transactionIsolation=readCommitted");
- assertTrue(TransactionIsolation.READ_COMMITTED == conf.transactionIsolation());
+ assertSame(TransactionIsolation.READ_COMMITTED, conf.transactionIsolation());
conf =
Configuration.parse("jdbc:mariadb://localhost/test?transactionIsolation=READ-UNCOMMITTED");
- assertTrue(TransactionIsolation.READ_UNCOMMITTED == conf.transactionIsolation());
+ assertSame(TransactionIsolation.READ_UNCOMMITTED, conf.transactionIsolation());
conf = Configuration.parse("jdbc:mariadb://localhost/test?transactionIsolation=SERIALIZABLE");
- assertTrue(TransactionIsolation.SERIALIZABLE == conf.transactionIsolation());
+ assertSame(TransactionIsolation.SERIALIZABLE, conf.transactionIsolation());
try {
Configuration.parse("jdbc:mariadb://localhost/test?transactionIsolation=wrong_val");
@@ -200,19 +199,19 @@ public void testConfigurationIsolation() throws Throwable {
conf =
Configuration.parse(
"jdbc:mysql://localhost/test?transactionIsolation=SERIALIZABLE&permitMysqlScheme");
- assertTrue(TransactionIsolation.SERIALIZABLE == conf.transactionIsolation());
+ assertSame(TransactionIsolation.SERIALIZABLE, conf.transactionIsolation());
}
@Test
public void testSslAlias() throws Throwable {
Configuration conf = Configuration.parse("jdbc:mariadb://localhost/test?sslMode=verify-full");
- assertTrue(SslMode.VERIFY_FULL == conf.sslMode());
+ assertSame(SslMode.VERIFY_FULL, conf.sslMode());
conf = Configuration.parse("jdbc:mariadb://localhost/test?sslMode=verify_full");
- assertTrue(SslMode.VERIFY_FULL == conf.sslMode());
+ assertSame(SslMode.VERIFY_FULL, conf.sslMode());
conf = Configuration.parse("jdbc:mariadb://localhost/test?sslMode=trust");
- assertTrue(SslMode.TRUST == conf.sslMode());
+ assertSame(SslMode.TRUST, conf.sslMode());
try {
Configuration.parse("jdbc:mariadb://localhost/test?sslMode=wrong_trust");
@@ -222,22 +221,22 @@ public void testSslAlias() throws Throwable {
}
conf = Configuration.parse("jdbc:mariadb://localhost/test?sslMode=verify-ca");
- assertTrue(SslMode.VERIFY_CA == conf.sslMode());
+ assertSame(SslMode.VERIFY_CA, conf.sslMode());
conf = Configuration.parse("jdbc:mariadb://localhost/test");
- assertTrue(SslMode.DISABLE == conf.sslMode());
+ assertSame(SslMode.DISABLE, conf.sslMode());
conf = Configuration.parse("jdbc:mariadb://localhost/test?sslMode");
- assertTrue(SslMode.DISABLE == conf.sslMode());
+ assertSame(SslMode.DISABLE, conf.sslMode());
conf = Configuration.parse("jdbc:mariadb://localhost/test?sslMode=0");
- assertTrue(SslMode.DISABLE == conf.sslMode());
+ assertSame(SslMode.DISABLE, conf.sslMode());
conf = Configuration.parse("jdbc:mariadb://localhost/test?sslMode=1");
- assertTrue(SslMode.VERIFY_FULL == conf.sslMode());
+ assertSame(SslMode.VERIFY_FULL, conf.sslMode());
conf = Configuration.parse("jdbc:mariadb://localhost/test?sslMode=true");
- assertTrue(SslMode.VERIFY_FULL == conf.sslMode());
+ assertSame(SslMode.VERIFY_FULL, conf.sslMode());
}
@Test
@@ -400,7 +399,7 @@ public void testJdbcParserSimpleIpv4basic() throws SQLException {
@Test
public void testJdbcParserSimpleIpv4basicError() throws SQLException {
Configuration Configuration = org.mariadb.jdbc.Configuration.parse(null);
- assertTrue(Configuration == null);
+ assertNull(Configuration);
}
@Test
@@ -489,7 +488,8 @@ public void testJdbcParserBooleanOption() {
assertTrue(
sqle.getMessage()
.contains(
- "Optional parameter autoReconnect must be boolean (true/false or 0/1) was \"truee\""));
+ "Optional parameter autoReconnect must be boolean (true/false or 0/1) was"
+ + " \"truee\""));
}
}
@@ -553,8 +553,8 @@ public void testJdbcParserParameter() throws SQLException {
assertEquals(HostAddress.from("master3", 3308, true), conf.addresses().get(2));
url =
- "jdbc:mariadb:replication://address=(port=3306)(host=master1),address=(port=3307)"
- + "(host=slave1) ,address=(host=slave2)(port=3308)(other=5/database?user=greg&password=pass";
+ "jdbc:mariadb:replication://address=(port=3306)(host=master1),address=(port=3307)(host=slave1)"
+ + " ,address=(host=slave2)(port=3308)(other=5/database?user=greg&password=pass";
conf = org.mariadb.jdbc.Configuration.parse(url);
assertEquals("database", conf.database());
assertEquals("greg", conf.user());
@@ -620,14 +620,14 @@ public void testJdbcParserParameterErrorEqual() {
public void testJdbcParserHaModeNone() throws SQLException {
String url = "jdbc:mariadb://localhost/database";
Configuration jdbc = Configuration.parse(url);
- assertTrue(jdbc.haMode().equals(HaMode.NONE));
+ assertEquals(jdbc.haMode(), HaMode.NONE);
}
@Test
public void testJdbcParserHaModeLoadReplication() throws SQLException {
String url = "jdbc:mariadb:replication://localhost/database";
Configuration jdbc = Configuration.parse(url);
- assertTrue(jdbc.haMode().equals(HaMode.REPLICATION));
+ assertEquals(jdbc.haMode(), HaMode.REPLICATION);
}
@Test
@@ -668,13 +668,13 @@ public void testJdbcParserReplicationParameterWithoutType() throws SQLException
@Test
public void checkOtherDriverCompatibility() throws SQLException {
Configuration jdbc = Configuration.parse("jdbc:h2:mem:RZM;DB_CLOSE_DELAY=-1");
- assertTrue(jdbc == null);
+ assertNull(jdbc);
}
@Test
public void checkDisable() throws SQLException {
Configuration jdbc = Configuration.parse("jdbc:mysql://localhost/test");
- assertTrue(jdbc == null);
+ assertNull(jdbc);
}
@Test
@@ -850,7 +850,8 @@ public void builder() throws SQLException {
.useCatalogTerm("schema")
.build();
assertEquals(
- "jdbc:mariadb://host1:3305,address=(host=host2)(port=3307)(type=replica)/db?user=me&password=***&timezone=UTC&autocommit=false&useCatalogTerm=UseSchema&createDatabaseIfNotExist=true&useLocalSessionState=true&transactionIsolation=REPEATABLE_READ&defaultFetchSize=10&maxQuerySizeToLog=100&maxAllowedPacket=8000&geometryDefaultType=default&restrictedAuth=mysql_native_password,client_ed25519&initSql=SET @@a='10'&socketFactory=someSocketFactory&connectTimeout=22&pipe=pipeName&localSocket=localSocket&uuidAsString=true&tcpKeepAlive=false&tcpKeepIdle=10&tcpKeepCount=50&tcpKeepInterval=50&tcpAbortiveClose=true&localSocketAddress=localSocketAddress&socketTimeout=1000&useReadAheadInput=true&tlsSocketType=TLStype&sslMode=TRUST&serverSslCert=mycertPath&keyStore=/tmp&keyStorePassword=MyPWD&keyStoreType=JKS&trustStoreType=JKS&enabledSslCipherSuites=myCipher,cipher2&enabledSslProtocolSuites=TLSv1.2&allowMultiQueries=true&allowLocalInfile=false&useCompression=true&useAffectedRows=true&disablePipeline=true&cachePrepStmts=false&prepStmtCacheSize=2&useServerPrepStmts=true&credentialType=ENV&sessionVariables=blabla&connectionAttributes=bla=bla&servicePrincipalName=SPN&blankTableNameMeta=true&tinyInt1isBit=false&yearIsDateType=false&dumpQueriesOnException=true&includeInnodbStatusInDeadlockExceptions=true&includeThreadDumpInDeadlockExceptions=true&retriesAllDown=10&galeraAllowedState=A,B&transactionReplay=true&pool=true&poolName=myPool&maxPoolSize=16&minPoolSize=12&maxIdleTime=25000®isterJmxPool=false&poolValidMinDelay=260&useResetConnection=true&serverRsaPublicKeyFile=RSAPath&allowPublicKeyRetrieval=true",
+ "jdbc:mariadb://host1:3305,address=(host=host2)(port=3307)(type=replica)/db?user=me&password=***&timezone=UTC&autocommit=false&useCatalogTerm=UseSchema&createDatabaseIfNotExist=true&useLocalSessionState=true&transactionIsolation=REPEATABLE_READ&defaultFetchSize=10&maxQuerySizeToLog=100&maxAllowedPacket=8000&geometryDefaultType=default&restrictedAuth=mysql_native_password,client_ed25519&initSql=SET"
+ + " @@a='10'&socketFactory=someSocketFactory&connectTimeout=22&pipe=pipeName&localSocket=localSocket&uuidAsString=true&tcpKeepAlive=false&tcpKeepIdle=10&tcpKeepCount=50&tcpKeepInterval=50&tcpAbortiveClose=true&localSocketAddress=localSocketAddress&socketTimeout=1000&useReadAheadInput=true&tlsSocketType=TLStype&sslMode=TRUST&serverSslCert=mycertPath&keyStore=/tmp&keyStorePassword=MyPWD&keyStoreType=JKS&trustStoreType=JKS&enabledSslCipherSuites=myCipher,cipher2&enabledSslProtocolSuites=TLSv1.2&allowMultiQueries=true&allowLocalInfile=false&useCompression=true&useAffectedRows=true&disablePipeline=true&cachePrepStmts=false&prepStmtCacheSize=2&useServerPrepStmts=true&credentialType=ENV&sessionVariables=blabla&connectionAttributes=bla=bla&servicePrincipalName=SPN&blankTableNameMeta=true&tinyInt1isBit=false&yearIsDateType=false&dumpQueriesOnException=true&includeInnodbStatusInDeadlockExceptions=true&includeThreadDumpInDeadlockExceptions=true&retriesAllDown=10&galeraAllowedState=A,B&transactionReplay=true&pool=true&poolName=myPool&maxPoolSize=16&minPoolSize=12&maxIdleTime=25000®isterJmxPool=false&poolValidMinDelay=260&useResetConnection=true&serverRsaPublicKeyFile=RSAPath&allowPublicKeyRetrieval=true",
conf.toString());
}
@@ -920,13 +921,15 @@ public void toConf() throws SQLException {
"jdbc:mariadb:loadbalance://host1:3305,address=(host=host2)(port=3307)(type=replica)/db?nonExisting&nonExistingWithValue=tt&user=me&password=***&timezone=UTC&autocommit=false&createDatabaseIfNotExist=true&")
.startsWith(
"Configuration:\n"
- + " * resulting Url : jdbc:mariadb:loadbalance://address=(host=host1)(port=3305)(type=primary),address=(host=host2)(port=3307)(type=replica)/db?user=me&password=***&nonExisting=&nonExistingWithValue=tt&timezone=UTC&autocommit=false&createDatabaseIfNotExist=true\n"
+ + " * resulting Url :"
+ + " jdbc:mariadb:loadbalance://address=(host=host1)(port=3305)(type=primary),address=(host=host2)(port=3307)(type=replica)/db?user=me&password=***&nonExisting=&nonExistingWithValue=tt&timezone=UTC&autocommit=false&createDatabaseIfNotExist=true\n"
+ "Unknown options : \n"
+ " * nonExisting : \n"
+ " * nonExistingWithValue : tt\n"
+ "\n"
+ "Non default options : \n"
- + " * addresses : [address=(host=host1)(port=3305)(type=primary), address=(host=host2)(port=3307)(type=replica)]\n"
+ + " * addresses : [address=(host=host1)(port=3305)(type=primary),"
+ + " address=(host=host2)(port=3307)(type=replica)]\n"
+ " * autocommit : false\n"
+ " * createDatabaseIfNotExist : true\n"
+ " * database : db\n"
@@ -945,7 +948,8 @@ public void toConf() throws SQLException {
"jdbc:mariadb://localhost/test?user=root&sslMode=verify-ca&serverSslCert=/tmp/t.pem&trustStoreType=JKS&keyStore=/tmp/keystore&keyStorePassword=kspass")
.startsWith(
"Configuration:\n"
- + " * resulting Url : jdbc:mariadb://localhost/test?user=root&sslMode=VERIFY_CA&serverSslCert=/tmp/t.pem&keyStore=/tmp/keystore&keyStorePassword=kspass&trustStoreType=JKS\n"
+ + " * resulting Url :"
+ + " jdbc:mariadb://localhost/test?user=root&sslMode=VERIFY_CA&serverSslCert=/tmp/t.pem&keyStore=/tmp/keystore&keyStorePassword=kspass&trustStoreType=JKS\n"
+ "Unknown options : None\n"
+ "\n"
+ "Non default options : \n"
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/ParameterListTest.java b/src/test/java/org/mariadb/jdbc/unit/util/ParameterListTest.java
index 12f2ea6f9..0b316b663 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/ParameterListTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/ParameterListTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/SecurityTest.java b/src/test/java/org/mariadb/jdbc/unit/util/SecurityTest.java
index d89c27407..59affa49f 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/SecurityTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/SecurityTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/VersionFactoryTest.java b/src/test/java/org/mariadb/jdbc/unit/util/VersionFactoryTest.java
index 38e635272..47905587c 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/VersionFactoryTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/VersionFactoryTest.java
@@ -1,3 +1,6 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2023 MariaDB Corporation Ab
package org.mariadb.jdbc.unit.util;
import static org.junit.jupiter.api.Assertions.assertNotNull;
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/VersionTest.java b/src/test/java/org/mariadb/jdbc/unit/util/VersionTest.java
index 7f6b5802f..cc4d07687 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/VersionTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/VersionTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/constant/HaModeTest.java b/src/test/java/org/mariadb/jdbc/unit/util/constant/HaModeTest.java
index c451ac1ad..0b670b554 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/constant/HaModeTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/constant/HaModeTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util.constant;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -124,7 +123,7 @@ public void loadBalanceTest() throws InterruptedException {
denyList.putIfAbsent(host1, System.currentTimeMillis() + 1000000);
res = loopPercReturn(available, denyList, true);
- Assertions.assertEquals(null, res.get(host1));
+ Assertions.assertNull(res.get(host1));
Assertions.assertEquals(500, res.get(host2));
Assertions.assertEquals(500, res.get(host3));
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/ConsoleLoggerTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/ConsoleLoggerTest.java
index ce4ac25a7..e5e1cd6b3 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/log/ConsoleLoggerTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/log/ConsoleLoggerTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util.log;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/JdkLoggerTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/JdkLoggerTest.java
index 83277820a..c1d21f6ed 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/log/JdkLoggerTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/log/JdkLoggerTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util.log;
import static org.junit.jupiter.api.Assertions.*;
@@ -16,54 +15,6 @@
public class JdkLoggerTest {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
- public class BufHandler extends StreamHandler {
- public BufHandler() {
- super(out, new MySimpleFormatter());
- }
-
- public void publish(LogRecord record) {
- super.publish(record);
- this.flush();
- }
-
- public void close() {
- this.flush();
- }
- }
-
- public static class MySimpleFormatter extends Formatter {
-
- public MySimpleFormatter() {}
-
- public String format(LogRecord record) {
- ZonedDateTime zdt = ZonedDateTime.now();
- String source;
- if (record.getSourceClassName() != null) {
- source = record.getSourceClassName();
- if (record.getSourceMethodName() != null) {
- source = source + " " + record.getSourceMethodName();
- }
- } else {
- source = record.getLoggerName();
- }
-
- String message = this.formatMessage(record);
- String throwable = "";
- if (record.getThrown() != null) {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- pw.println();
- record.getThrown().printStackTrace(pw);
- pw.close();
- throwable = sw.toString();
- }
-
- return String.format(
- "[%4$-7s] %5$s %n",
- zdt, source, record.getLoggerName(), Level.FINEST, message, throwable);
- }
- }
-
@Test
public void logger() {
@@ -116,4 +67,52 @@ public void logger() {
+ "[FINEST ] warn msg2 ";
assertTrue(outSt.contains(expected) || outSt.replace("\r\n", "\n").contains(expected));
}
+
+ public static class MySimpleFormatter extends Formatter {
+
+ public MySimpleFormatter() {}
+
+ public String format(LogRecord record) {
+ ZonedDateTime zdt = ZonedDateTime.now();
+ String source;
+ if (record.getSourceClassName() != null) {
+ source = record.getSourceClassName();
+ if (record.getSourceMethodName() != null) {
+ source = source + " " + record.getSourceMethodName();
+ }
+ } else {
+ source = record.getLoggerName();
+ }
+
+ String message = this.formatMessage(record);
+ String throwable = "";
+ if (record.getThrown() != null) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ pw.println();
+ record.getThrown().printStackTrace(pw);
+ pw.close();
+ throwable = sw.toString();
+ }
+
+ return String.format(
+ "[%4$-7s] %5$s %n",
+ zdt, source, record.getLoggerName(), Level.FINEST, message, throwable);
+ }
+ }
+
+ public class BufHandler extends StreamHandler {
+ public BufHandler() {
+ super(out, new MySimpleFormatter());
+ }
+
+ public void publish(LogRecord record) {
+ super.publish(record);
+ this.flush();
+ }
+
+ public void close() {
+ this.flush();
+ }
+ }
}
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerFactoryTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerFactoryTest.java
index b7f27bb31..83a00adc5 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerFactoryTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerFactoryTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util.log;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerHelperTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerHelperTest.java
index 119bafdd4..0a6a42785 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerHelperTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggerHelperTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util.log;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggersTest.java b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggersTest.java
index e26b17ed8..48549fac8 100644
--- a/src/test/java/org/mariadb/jdbc/unit/util/log/LoggersTest.java
+++ b/src/test/java/org/mariadb/jdbc/unit/util/log/LoggersTest.java
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2023 MariaDB Corporation Ab
-
package org.mariadb.jdbc.unit.util.log;
import static org.junit.jupiter.api.Assertions.*;
diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml
index 5587c716c..078becf77 100644
--- a/src/test/resources/logback-test.xml
+++ b/src/test/resources/logback-test.xml
@@ -1,20 +1,20 @@
-
-
-
- %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
-
-
-
+
+
+
+ %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
+
+
+
-
-
-
+
+
+
-
-
-
+
+
+