eldest) {
- if (this.size() > maxSize) {
- eldest.getValue().unCache(con);
- return true;
- }
- return false;
- }
-
- public synchronized CachedPrepareResultPacket get(
- String key, ServerPreparedStatement preparedStatement) {
- CachedPrepareResultPacket prepare = super.get(key);
- if (prepare != null && preparedStatement != null) {
- prepare.incrementUse(preparedStatement);
- }
- return prepare;
- }
-
- public synchronized CachedPrepareResultPacket put(
- String key, CachedPrepareResultPacket result, ServerPreparedStatement preparedStatement) {
- CachedPrepareResultPacket cached = super.get(key);
-
- // if there is already some cached data, return existing cached data
- if (cached != null) {
- cached.incrementUse(preparedStatement);
- result.unCache(con);
- return cached;
- }
+import org.mariadb.jdbc.export.Prepare;
- if (result.cache()) {
- result.incrementUse(preparedStatement);
- super.put(key, result);
- }
- return null;
- }
+public interface PrepareCache {
- public CachedPrepareResultPacket get(Object key) {
- throw new IllegalStateException("not available method");
- }
+ Prepare get(String key, ServerPreparedStatement preparedStatement);
- @SuppressWarnings("unused")
- public CachedPrepareResultPacket put(String key, PrepareResultPacket result) {
- throw new IllegalStateException("not available method");
- }
+ Prepare put(String key, Prepare result, ServerPreparedStatement preparedStatement);
- public void reset() {
- for (CachedPrepareResultPacket prep : values()) {
- prep.reset();
- }
- this.clear();
- }
+ void reset();
}
diff --git a/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java b/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java
index ff21eb81a..4c5fb109c 100644
--- a/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java
+++ b/src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java
@@ -4,261 +4,84 @@
package org.mariadb.jdbc.client;
-import java.nio.charset.StandardCharsets;
import org.mariadb.jdbc.MariaDbBlob;
-import org.mariadb.jdbc.util.MutableInt;
-
-public final class ReadableByteBuf {
- private final MutableInt sequence;
- private int limit;
- private byte[] buf;
- private int pos;
- private int mark;
-
- public ReadableByteBuf(MutableInt sequence, byte[] buf, int limit) {
- this.sequence = sequence;
- this.pos = 0;
- this.buf = buf;
- this.limit = limit;
- this.mark = -1;
- }
-
- public int readableBytes() {
- return limit - pos;
- }
-
- public int pos() {
- return pos;
- }
-
- public byte[] buf() {
- return buf;
- }
-
- public ReadableByteBuf buf(byte[] buf, int limit) {
- this.buf = buf;
- this.limit = limit;
- return this;
- }
-
- public void pos(int pos) {
- this.pos = pos;
- }
-
- public void mark() {
- mark = pos;
- }
-
- public void reset() {
- if (mark == -1) throw new IllegalStateException("mark was not set");
- pos = mark;
- }
-
- public void skip() {
- pos++;
- }
-
- public ReadableByteBuf skip(int length) {
- pos += length;
- return this;
- }
-
- public MariaDbBlob readBlob(int length) {
- pos += length;
- return MariaDbBlob.safeMariaDbBlob(buf, pos - length, length);
- }
-
- public MutableInt getSequence() {
- return sequence;
- }
-
- public byte getByte() {
- return buf[pos];
- }
-
- public byte getByte(int index) {
- return buf[index];
- }
-
- public short getUnsignedByte() {
- return (short) (buf[pos] & 0xff);
- }
-
- public int readLengthNotNull() {
- int type = (buf[pos++] & 0xff);
- switch (type) {
- case 252:
- return readUnsignedShort();
- case 253:
- return readUnsignedMedium();
- case 254:
- return (int) readLong();
- default:
- return type;
- }
- }
-
- /**
- * Identifier can have a max length of 256 (alias) So no need to check whole length encoding.
- *
- * @return current pos
- */
- public int skipIdentifier() {
- int type = (buf[pos++] & 0xff);
- if (type == 252) {
- pos += readUnsignedShort();
- return pos;
- }
- pos += type;
- return pos;
- }
-
- public Integer readLength() {
- int type = readUnsignedByte();
- switch (type) {
- case 251:
- return null;
- case 252:
- return readUnsignedShort();
- case 253:
- return readUnsignedMedium();
- case 254:
- return (int) readLong();
- default:
- return type;
- }
- }
-
- public byte readByte() {
- return buf[pos++];
- }
-
- public short readUnsignedByte() {
- return (short) (buf[pos++] & 0xff);
- }
-
- public short readShort() {
- return (short) ((buf[pos++] & 0xff) | (buf[pos++] << 8));
- }
-
- public int readUnsignedShort() {
- return ((buf[pos++] & 0xff) | (buf[pos++] << 8)) & 0xffff;
- }
-
- public int readMedium() {
- int value = readUnsignedMedium();
- if ((value & 0x800000) != 0) {
- value |= 0xff000000;
- }
- return value;
- }
-
- public int readUnsignedMedium() {
- return ((buf[pos++] & 0xff) + ((buf[pos++] & 0xff) << 8) + ((buf[pos++] & 0xff) << 16));
- }
-
- public int readInt() {
- return ((buf[pos++] & 0xff)
- + ((buf[pos++] & 0xff) << 8)
- + ((buf[pos++] & 0xff) << 16)
- + ((buf[pos++] & 0xff) << 24));
- }
-
- public int readIntBE() {
- return (((buf[pos++] & 0xff) << 24)
- + ((buf[pos++] & 0xff) << 16)
- + ((buf[pos++] & 0xff) << 8)
- + (buf[pos++] & 0xff));
- }
-
- public long readUnsignedInt() {
- return ((buf[pos++] & 0xff)
- + ((buf[pos++] & 0xff) << 8)
- + ((buf[pos++] & 0xff) << 16)
- + ((long) (buf[pos++] & 0xff) << 24))
- & 0xffffffffL;
- }
-
- public long readLong() {
- return ((buf[pos++] & 0xffL)
- + ((buf[pos++] & 0xffL) << 8)
- + ((buf[pos++] & 0xffL) << 16)
- + ((buf[pos++] & 0xffL) << 24)
- + ((buf[pos++] & 0xffL) << 32)
- + ((buf[pos++] & 0xffL) << 40)
- + ((buf[pos++] & 0xffL) << 48)
- + ((buf[pos++] & 0xffL) << 56));
- }
-
- public long readLongBE() {
- return (((buf[pos++] & 0xffL) << 56)
- + ((buf[pos++] & 0xffL) << 48)
- + ((buf[pos++] & 0xffL) << 40)
- + ((buf[pos++] & 0xffL) << 32)
- + ((buf[pos++] & 0xffL) << 24)
- + ((buf[pos++] & 0xffL) << 16)
- + ((buf[pos++] & 0xffL) << 8)
- + (buf[pos++] & 0xffL));
- }
-
- public ReadableByteBuf readBytes(byte[] dst) {
- System.arraycopy(buf, pos, dst, 0, dst.length);
- pos += dst.length;
- return this;
- }
-
- public byte[] readBytesNullEnd() {
- int initialPosition = pos;
- int cnt = 0;
- while (readableBytes() > 0 && (buf[pos++] != 0)) {
- cnt++;
- }
- byte[] dst = new byte[cnt];
- System.arraycopy(buf, initialPosition, dst, 0, dst.length);
- return dst;
- }
-
- public ReadableByteBuf readLengthBuffer() {
- int len = readLengthNotNull();
- byte[] tmp = new byte[len];
- readBytes(tmp);
- return new ReadableByteBuf(sequence, tmp, len);
- }
-
- public String readString(int length) {
- pos += length;
- return new String(buf, pos - length, length, StandardCharsets.UTF_8);
- }
-
- public String readAscii(int length) {
- pos += length;
- return new String(buf, pos - length, length, StandardCharsets.US_ASCII);
- }
-
- public String readStringNullEnd() {
- int initialPosition = pos;
- int cnt = 0;
- while (readableBytes() > 0 && (buf[pos++] != 0)) {
- cnt++;
- }
- return new String(buf, initialPosition, cnt, StandardCharsets.UTF_8);
- }
-
- public String readStringEof() {
- int initialPosition = pos;
- pos = limit;
- return new String(buf, initialPosition, pos - initialPosition, StandardCharsets.UTF_8);
- }
-
- public float readFloat() {
- return Float.intBitsToFloat(readInt());
- }
-
- public double readDouble() {
- return Double.longBitsToDouble(readLong());
- }
-
- public double readDoubleBE() {
- return Double.longBitsToDouble(readLongBE());
- }
+import org.mariadb.jdbc.client.util.MutableInt;
+
+public interface ReadableByteBuf {
+
+ int readableBytes();
+
+ int pos();
+
+ byte[] buf();
+
+ ReadableByteBuf buf(byte[] buf, int limit);
+
+ void pos(int pos);
+
+ void mark();
+
+ void reset();
+
+ void skip();
+
+ ReadableByteBuf skip(int length);
+
+ MariaDbBlob readBlob(int length);
+
+ MutableInt getSequence();
+
+ byte getByte();
+
+ byte getByte(int index);
+
+ short getUnsignedByte();
+
+ int readLengthNotNull();
+
+ int skipIdentifier();
+
+ Integer readLength();
+
+ byte readByte();
+
+ short readUnsignedByte();
+
+ short readShort();
+
+ int readUnsignedShort();
+
+ int readMedium();
+
+ int readUnsignedMedium();
+
+ int readInt();
+
+ int readIntBE();
+
+ long readUnsignedInt();
+
+ long readLong();
+
+ long readLongBE();
+
+ ReadableByteBuf readBytes(byte[] dst);
+
+ byte[] readBytesNullEnd();
+
+ ReadableByteBuf readLengthBuffer();
+
+ String readString(int length);
+
+ String readAscii(int length);
+
+ String readStringNullEnd();
+
+ String readStringEof();
+
+ float readFloat();
+
+ double readDouble();
+
+ double readDoubleBE();
}
diff --git a/src/main/java/org/mariadb/jdbc/client/ServerVersion.java b/src/main/java/org/mariadb/jdbc/client/ServerVersion.java
index 13ced33c6..1cf2bbc55 100644
--- a/src/main/java/org/mariadb/jdbc/client/ServerVersion.java
+++ b/src/main/java/org/mariadb/jdbc/client/ServerVersion.java
@@ -4,18 +4,27 @@
package org.mariadb.jdbc.client;
-import org.mariadb.jdbc.util.Version;
+public interface ServerVersion {
-public final class ServerVersion extends Version {
+ String getVersion();
- private final boolean mariaDBServer;
+ int getMajorVersion();
- public ServerVersion(String serverVersion, boolean mariaDBServer) {
- super(serverVersion);
- this.mariaDBServer = mariaDBServer;
- }
+ int getMinorVersion();
- public boolean isMariaDBServer() {
- return mariaDBServer;
- }
+ int getPatchVersion();
+
+ String getQualifier();
+
+ /**
+ * Utility method to check if database version is greater than parameters.
+ *
+ * @param major major version
+ * @param minor minor version
+ * @param patch patch version
+ * @return true if version is greater than parameters
+ */
+ boolean versionGreaterOrEqual(int major, int minor, int patch);
+
+ boolean isMariaDBServer();
}
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 80c96511e..dd2c36b72 100644
--- a/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java
+++ b/src/main/java/org/mariadb/jdbc/client/context/BaseContext.java
@@ -5,11 +5,12 @@
package org.mariadb.jdbc.client.context;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.PrepareCache;
import org.mariadb.jdbc.client.ServerVersion;
+import org.mariadb.jdbc.export.ExceptionFactory;
import org.mariadb.jdbc.message.server.InitialHandshakePacket;
import org.mariadb.jdbc.util.constants.Capabilities;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
public class BaseContext implements Context {
@@ -121,6 +122,10 @@ public PrepareCache getPrepareCache() {
return prepareCache;
}
+ public void resetPrepareCache() {
+ prepareCache.reset();
+ }
+
public int getStateFlag() {
return stateFlag;
}
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 a50f21902..ed7cace6d 100644
--- a/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java
+++ b/src/main/java/org/mariadb/jdbc/client/context/RedoContext.java
@@ -6,12 +6,12 @@
import org.mariadb.jdbc.Configuration;
import org.mariadb.jdbc.client.PrepareCache;
-import org.mariadb.jdbc.client.TransactionSaver;
-import org.mariadb.jdbc.message.client.ClientMessage;
+import org.mariadb.jdbc.client.impl.TransactionSaver;
+import org.mariadb.jdbc.export.ExceptionFactory;
+import org.mariadb.jdbc.message.ClientMessage;
import org.mariadb.jdbc.message.client.RedoableClientMessage;
import org.mariadb.jdbc.message.server.InitialHandshakePacket;
import org.mariadb.jdbc.util.constants.ServerStatus;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
public class RedoContext extends BaseContext {
diff --git a/src/main/java/org/mariadb/jdbc/client/ConnectionHelper.java b/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java
similarity index 96%
rename from src/main/java/org/mariadb/jdbc/client/ConnectionHelper.java
rename to src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java
index 22aaad366..fb4dc412e 100644
--- a/src/main/java/org/mariadb/jdbc/client/ConnectionHelper.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/ConnectionHelper.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client;
+package org.mariadb.jdbc.client.impl;
import java.io.IOException;
import java.lang.reflect.Constructor;
@@ -19,12 +19,13 @@
import javax.net.ssl.SSLSocketFactory;
import org.mariadb.jdbc.Configuration;
import org.mariadb.jdbc.HostAddress;
-import org.mariadb.jdbc.SslMode;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.client.socket.SocketHandlerFunction;
-import org.mariadb.jdbc.client.socket.SocketUtility;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.ReadableByteBuf;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.client.socket.impl.SocketHandlerFunction;
+import org.mariadb.jdbc.client.socket.impl.SocketUtility;
+import org.mariadb.jdbc.export.SslMode;
import org.mariadb.jdbc.message.client.SslRequestPacket;
import org.mariadb.jdbc.message.server.AuthSwitchPacket;
import org.mariadb.jdbc.message.server.ErrorPacket;
@@ -204,7 +205,7 @@ public static byte decideLanguage(InitialHandshakePacket handshake) {
}
public static void authenticationHandler(
- Credential credential, PacketWriter writer, PacketReader reader, Context context)
+ Credential credential, Writer writer, Reader reader, Context context)
throws SQLException, IOException {
writer.permitTrace(true);
@@ -277,7 +278,7 @@ public static SSLSocket sslWrapper(
long clientCapabilities,
final byte exchangeCharset,
Context context,
- PacketWriter writer)
+ Writer writer)
throws SQLException, IOException {
Configuration conf = context.getConf();
diff --git a/src/main/java/org/mariadb/jdbc/client/MultiPrimaryClient.java b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java
similarity index 94%
rename from src/main/java/org/mariadb/jdbc/client/MultiPrimaryClient.java
rename to src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java
index ea99c0c3d..999cb9110 100644
--- a/src/main/java/org/mariadb/jdbc/client/MultiPrimaryClient.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryClient.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client;
+package org.mariadb.jdbc.client.impl;
import java.sql.*;
import java.util.*;
@@ -13,17 +13,18 @@
import org.mariadb.jdbc.Configuration;
import org.mariadb.jdbc.HostAddress;
import org.mariadb.jdbc.Statement;
-import org.mariadb.jdbc.client.context.Context;
+import org.mariadb.jdbc.client.Client;
+import org.mariadb.jdbc.client.Completion;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.context.RedoContext;
+import org.mariadb.jdbc.export.ExceptionFactory;
+import org.mariadb.jdbc.export.Prepare;
+import org.mariadb.jdbc.message.ClientMessage;
import org.mariadb.jdbc.message.client.ChangeDbPacket;
-import org.mariadb.jdbc.message.client.ClientMessage;
import org.mariadb.jdbc.message.client.QueryPacket;
import org.mariadb.jdbc.message.client.RedoableWithPrepareClientMessage;
-import org.mariadb.jdbc.message.server.Completion;
-import org.mariadb.jdbc.message.server.PrepareResultPacket;
import org.mariadb.jdbc.util.constants.ConnectionState;
import org.mariadb.jdbc.util.constants.ServerStatus;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
import org.mariadb.jdbc.util.log.Logger;
import org.mariadb.jdbc.util.log.Loggers;
@@ -73,8 +74,8 @@ protected Client connectHost(boolean readOnly, boolean failFast) throws SQLExcep
.isPresent()) {
try {
return conf.transactionReplay()
- ? new ClientReplayImpl(conf, host.get(), lock, false)
- : new ClientImpl(conf, host.get(), lock, false);
+ ? new ReplayClient(conf, host.get(), lock, false)
+ : new StandardClient(conf, host.get(), lock, false);
} catch (SQLNonTransientConnectionException sqle) {
lastSqle = sqle;
denyList.putIfAbsent(host.get(), System.currentTimeMillis() + deniedListTimeout);
@@ -107,8 +108,8 @@ protected Client connectHost(boolean readOnly, boolean failFast) throws SQLExcep
if (host.isPresent()) {
Client client =
conf.transactionReplay()
- ? new ClientReplayImpl(conf, host.get(), lock, false)
- : new ClientImpl(conf, host.get(), lock, false);
+ ? new ReplayClient(conf, host.get(), lock, false)
+ : new StandardClient(conf, host.get(), lock, false);
denyList.remove(host.get());
return client;
}
@@ -141,7 +142,7 @@ protected void reConnect() throws SQLException {
try {
Client oldClient = currentClient;
// remove cached prepare from existing server prepare statement
- oldClient.getContext().getPrepareCache().reset();
+ oldClient.getContext().resetPrepareCache();
currentClient = connectHost(false, false);
syncNewState(oldClient);
@@ -172,7 +173,7 @@ protected void executeTransactionReplay(Client oldCli) throws SQLException {
// transaction replay
if ((oldCli.getContext().getServerStatus() & ServerStatus.IN_TRANSACTION) > 0) {
RedoContext ctx = (RedoContext) oldCli.getContext();
- ((ClientReplayImpl) currentClient).transactionReplay(ctx.getTransactionSaver());
+ ((ReplayClient) currentClient).transactionReplay(ctx.getTransactionSaver());
}
}
@@ -372,7 +373,7 @@ public void readStreamingResults(
}
@Override
- public void closePrepare(PrepareResultPacket prepare) throws SQLException {
+ public void closePrepare(Prepare prepare) throws SQLException {
if (closed) {
throw new SQLNonTransientConnectionException("Connection is closed", "08000", 1220);
}
@@ -459,6 +460,6 @@ public boolean isPrimary() {
@Override
public void reset() {
currentClient.getContext().resetStateFlag();
- currentClient.getContext().getPrepareCache().reset();
+ currentClient.getContext().resetPrepareCache();
}
}
diff --git a/src/main/java/org/mariadb/jdbc/client/MultiPrimaryReplicaClient.java b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java
similarity index 94%
rename from src/main/java/org/mariadb/jdbc/client/MultiPrimaryReplicaClient.java
rename to src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java
index 39e7b9bc4..1c412b7ba 100644
--- a/src/main/java/org/mariadb/jdbc/client/MultiPrimaryReplicaClient.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/MultiPrimaryReplicaClient.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client;
+package org.mariadb.jdbc.client.impl;
import java.sql.SQLException;
import java.sql.SQLNonTransientConnectionException;
@@ -13,12 +13,13 @@
import org.mariadb.jdbc.Configuration;
import org.mariadb.jdbc.HostAddress;
import org.mariadb.jdbc.Statement;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.message.client.ClientMessage;
-import org.mariadb.jdbc.message.server.Completion;
-import org.mariadb.jdbc.message.server.PrepareResultPacket;
+import org.mariadb.jdbc.client.Client;
+import org.mariadb.jdbc.client.Completion;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.export.ExceptionFactory;
+import org.mariadb.jdbc.export.Prepare;
+import org.mariadb.jdbc.message.ClientMessage;
import org.mariadb.jdbc.util.constants.ServerStatus;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
import org.mariadb.jdbc.util.log.Logger;
import org.mariadb.jdbc.util.log.Loggers;
@@ -81,8 +82,8 @@ private void reconnectIfNeeded() {
}
/**
- * Reconnect connection, trying to continue transparently if possible. Different cases. * replica
- * fails => reconnect to replica or to master if no replica available
+ * Reconnect connection, trying to continue transparently if possible. Different possible cases :
+ * replica fails, then reconnect to replica or to master if no replica available
*
* if reconnect succeed on replica / use master, no problem, continuing without interruption //
* if reconnect primary, then replay transaction / throw exception if was in transaction.
@@ -103,7 +104,7 @@ protected void reConnect() throws SQLException {
}
// remove cached prepare from existing server prepare statement
- oldClient.getContext().getPrepareCache().reset();
+ oldClient.getContext().resetPrepareCache();
try {
currentClient = connectHost(requestReadOnly, requestReadOnly);
@@ -226,7 +227,7 @@ public void readStreamingResults(
}
@Override
- public void closePrepare(PrepareResultPacket prepare) throws SQLException {
+ public void closePrepare(Prepare prepare) throws SQLException {
reconnectIfNeeded();
super.closePrepare(prepare);
}
@@ -337,11 +338,11 @@ public boolean isPrimary() {
public void reset() {
if (replicaClient != null) {
replicaClient.getContext().resetStateFlag();
- replicaClient.getContext().getPrepareCache().reset();
+ replicaClient.getContext().resetPrepareCache();
}
if (primaryClient != null) {
primaryClient.getContext().resetStateFlag();
- primaryClient.getContext().getPrepareCache().reset();
+ primaryClient.getContext().resetPrepareCache();
}
}
}
diff --git a/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java b/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java
new file mode 100644
index 000000000..c5d19288a
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/client/impl/PrepareCache.java
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2021 MariaDB Corporation Ab
+
+package org.mariadb.jdbc.client.impl;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.mariadb.jdbc.ServerPreparedStatement;
+import org.mariadb.jdbc.export.Prepare;
+import org.mariadb.jdbc.message.server.CachedPrepareResultPacket;
+import org.mariadb.jdbc.message.server.PrepareResultPacket;
+
+public final class PrepareCache extends LinkedHashMap
+ implements org.mariadb.jdbc.client.PrepareCache {
+
+ private static final long serialVersionUID = -8922905563713952695L;
+ private final int maxSize;
+ private final StandardClient con;
+
+ public PrepareCache(int size, StandardClient con) {
+ super(size, .75f, true);
+ this.maxSize = size;
+ this.con = con;
+ }
+
+ @Override
+ public boolean removeEldestEntry(Map.Entry eldest) {
+ if (this.size() > maxSize) {
+ eldest.getValue().unCache(con);
+ return true;
+ }
+ return false;
+ }
+
+ public synchronized Prepare get(String key, ServerPreparedStatement preparedStatement) {
+ CachedPrepareResultPacket prepare = super.get(key);
+ if (prepare != null && preparedStatement != null) {
+ prepare.incrementUse(preparedStatement);
+ }
+ return prepare;
+ }
+
+ public synchronized Prepare put(
+ String key, Prepare result, ServerPreparedStatement preparedStatement) {
+ CachedPrepareResultPacket cached = super.get(key);
+
+ // if there is already some cached data, return existing cached data
+ if (cached != null) {
+ cached.incrementUse(preparedStatement);
+ ((CachedPrepareResultPacket) result).unCache(con);
+ return cached;
+ }
+
+ if (((CachedPrepareResultPacket) result).cache()) {
+ ((CachedPrepareResultPacket) result).incrementUse(preparedStatement);
+ super.put(key, (CachedPrepareResultPacket) result);
+ }
+ return null;
+ }
+
+ public CachedPrepareResultPacket get(Object key) {
+ throw new IllegalStateException("not available method");
+ }
+
+ @SuppressWarnings("unused")
+ public CachedPrepareResultPacket put(String key, PrepareResultPacket result) {
+ throw new IllegalStateException("not available method");
+ }
+
+ public void reset() {
+ for (CachedPrepareResultPacket prep : values()) {
+ prep.reset();
+ }
+ this.clear();
+ }
+}
diff --git a/src/main/java/org/mariadb/jdbc/client/ClientReplayImpl.java b/src/main/java/org/mariadb/jdbc/client/impl/ReplayClient.java
similarity index 93%
rename from src/main/java/org/mariadb/jdbc/client/ClientReplayImpl.java
rename to src/main/java/org/mariadb/jdbc/client/impl/ReplayClient.java
index 07e672dd7..548a0040d 100644
--- a/src/main/java/org/mariadb/jdbc/client/ClientReplayImpl.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/ReplayClient.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client;
+package org.mariadb.jdbc.client.impl;
import java.io.IOException;
import java.sql.SQLException;
@@ -10,15 +10,17 @@
import java.util.concurrent.locks.ReentrantLock;
import org.mariadb.jdbc.Configuration;
import org.mariadb.jdbc.HostAddress;
+import org.mariadb.jdbc.client.Completion;
import org.mariadb.jdbc.client.context.RedoContext;
+import org.mariadb.jdbc.export.MaxAllowedPacketException;
+import org.mariadb.jdbc.export.Prepare;
+import org.mariadb.jdbc.message.ClientMessage;
import org.mariadb.jdbc.message.client.*;
-import org.mariadb.jdbc.message.server.Completion;
import org.mariadb.jdbc.message.server.PrepareResultPacket;
-import org.mariadb.jdbc.util.exceptions.MaxAllowedPacketException;
-public class ClientReplayImpl extends ClientImpl {
+public class ReplayClient extends StandardClient {
- public ClientReplayImpl(
+ public ReplayClient(
Configuration conf, HostAddress hostAddress, ReentrantLock lock, boolean skipPostCommands)
throws SQLException {
super(conf, hostAddress, lock, skipPostCommands);
@@ -104,7 +106,7 @@ public void transactionReplay(TransactionSaver transactionSaver) throws SQLExcep
List buffers = transactionSaver.getBuffers();
try {
// replay all but last
- PrepareResultPacket prepare;
+ Prepare prepare;
for (RedoableClientMessage querySaver : buffers) {
int responseNo;
if (querySaver instanceof RedoableWithPrepareClientMessage) {
diff --git a/src/main/java/org/mariadb/jdbc/client/SocketHelper.java b/src/main/java/org/mariadb/jdbc/client/impl/SocketHelper.java
similarity index 95%
rename from src/main/java/org/mariadb/jdbc/client/SocketHelper.java
rename to src/main/java/org/mariadb/jdbc/client/impl/SocketHelper.java
index 2e0c9d0c8..de377e8af 100644
--- a/src/main/java/org/mariadb/jdbc/client/SocketHelper.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/SocketHelper.java
@@ -1,4 +1,4 @@
-package org.mariadb.jdbc.client;
+package org.mariadb.jdbc.client.impl;
import java.io.IOException;
import java.net.InetSocketAddress;
diff --git a/src/main/java/org/mariadb/jdbc/client/ClientImpl.java b/src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java
similarity index 95%
rename from src/main/java/org/mariadb/jdbc/client/ClientImpl.java
rename to src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java
index 29332c77f..7387dffd7 100644
--- a/src/main/java/org/mariadb/jdbc/client/ClientImpl.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/StandardClient.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client;
+package org.mariadb.jdbc.client.impl;
import java.io.BufferedInputStream;
import java.io.IOException;
@@ -25,30 +25,36 @@
import org.mariadb.jdbc.Configuration;
import org.mariadb.jdbc.HostAddress;
import org.mariadb.jdbc.ServerPreparedStatement;
+import org.mariadb.jdbc.client.Client;
+import org.mariadb.jdbc.client.Completion;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.ReadableByteBuf;
import org.mariadb.jdbc.client.context.BaseContext;
-import org.mariadb.jdbc.client.context.Context;
import org.mariadb.jdbc.client.context.RedoContext;
import org.mariadb.jdbc.client.result.Result;
import org.mariadb.jdbc.client.result.StreamingResult;
-import org.mariadb.jdbc.client.socket.*;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.client.socket.impl.*;
+import org.mariadb.jdbc.client.util.MutableInt;
+import org.mariadb.jdbc.export.ExceptionFactory;
+import org.mariadb.jdbc.export.MaxAllowedPacketException;
+import org.mariadb.jdbc.export.Prepare;
+import org.mariadb.jdbc.message.ClientMessage;
import org.mariadb.jdbc.message.client.*;
-import org.mariadb.jdbc.message.server.Completion;
import org.mariadb.jdbc.message.server.ErrorPacket;
import org.mariadb.jdbc.message.server.InitialHandshakePacket;
import org.mariadb.jdbc.message.server.PrepareResultPacket;
import org.mariadb.jdbc.plugin.Credential;
import org.mariadb.jdbc.plugin.CredentialPlugin;
-import org.mariadb.jdbc.util.MutableInt;
import org.mariadb.jdbc.util.Security;
import org.mariadb.jdbc.util.constants.Capabilities;
import org.mariadb.jdbc.util.constants.ServerStatus;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
-import org.mariadb.jdbc.util.exceptions.MaxAllowedPacketException;
import org.mariadb.jdbc.util.log.Logger;
import org.mariadb.jdbc.util.log.Loggers;
-public class ClientImpl implements Client, AutoCloseable {
- private static final Logger logger = Loggers.getLogger(ClientImpl.class);
+public class StandardClient implements Client, AutoCloseable {
+ private static final Logger logger = Loggers.getLogger(StandardClient.class);
private final Socket socket;
private final MutableInt sequence = new MutableInt();
private final MutableInt compressionSequence = new MutableInt();
@@ -57,8 +63,8 @@ public class ClientImpl implements Client, AutoCloseable {
private final HostAddress hostAddress;
private boolean closed = false;
protected final ExceptionFactory exceptionFactory;
- protected PacketWriter writer;
- private PacketReader reader;
+ protected Writer writer;
+ private Reader reader;
private org.mariadb.jdbc.Statement streamStmt = null;
private ClientMessage streamMsg = null;
private int socketTimeout;
@@ -66,7 +72,7 @@ public class ClientImpl implements Client, AutoCloseable {
private final boolean disablePipeline;
protected Context context;
- public ClientImpl(
+ public StandardClient(
Configuration conf, HostAddress hostAddress, ReentrantLock lock, boolean skipPostCommands)
throws SQLException {
@@ -590,7 +596,7 @@ public void readResponse(ClientMessage message) throws SQLException {
false);
}
- public void closePrepare(PrepareResultPacket prepare) throws SQLException {
+ public void closePrepare(Prepare prepare) throws SQLException {
checkNotClosed();
try {
new ClosePreparePacket(prepare.getStatementId()).encode(writer, context);
@@ -670,9 +676,11 @@ public Completion readPacket(ClientMessage message) throws SQLException {
* @param stmt current statement (null if internal)
* @param message current message
* @param fetchSize default fetch size
+ * @param maxRows maximum row number
* @param resultSetConcurrency concurrency
* @param resultSetType type
* @param closeOnCompletion must resultset close statement on completion
+ * @return Completion
* @throws SQLException if any exception
*/
public Completion readPacket(
@@ -775,11 +783,12 @@ public void abort(Executor executor) throws SQLException {
if (!this.closed) {
this.closed = true;
-
+ logger.debug("aborting connection {}", context.getThreadId());
if (!lockStatus) {
// lock not available : query is running
// force end by executing an KILL connection
- try (ClientImpl cli = new ClientImpl(conf, hostAddress, new ReentrantLock(), true)) {
+ try (StandardClient cli =
+ new StandardClient(conf, hostAddress, new ReentrantLock(), true)) {
cli.execute(new QueryPacket("KILL " + context.getThreadId()));
} catch (SQLException e) {
// eat
@@ -847,6 +856,6 @@ public HostAddress getHostAddress() {
public void reset() {
context.resetStateFlag();
- context.getPrepareCache().reset();
+ context.resetPrepareCache();
}
}
diff --git a/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java b/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java
new file mode 100644
index 000000000..c81aebde8
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/client/impl/StandardReadableByteBuf.java
@@ -0,0 +1,265 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2021 MariaDB Corporation Ab
+
+package org.mariadb.jdbc.client.impl;
+
+import java.nio.charset.StandardCharsets;
+import org.mariadb.jdbc.MariaDbBlob;
+import org.mariadb.jdbc.client.ReadableByteBuf;
+import org.mariadb.jdbc.client.util.MutableInt;
+
+public final class StandardReadableByteBuf implements ReadableByteBuf {
+ private final MutableInt sequence;
+ private int limit;
+ private byte[] buf;
+ private int pos;
+ private int mark;
+
+ public StandardReadableByteBuf(MutableInt sequence, byte[] buf, int limit) {
+ this.sequence = sequence;
+ this.pos = 0;
+ this.buf = buf;
+ this.limit = limit;
+ this.mark = -1;
+ }
+
+ public int readableBytes() {
+ return limit - pos;
+ }
+
+ public int pos() {
+ return pos;
+ }
+
+ public byte[] buf() {
+ return buf;
+ }
+
+ public StandardReadableByteBuf buf(byte[] buf, int limit) {
+ this.buf = buf;
+ this.limit = limit;
+ return this;
+ }
+
+ public void pos(int pos) {
+ this.pos = pos;
+ }
+
+ public void mark() {
+ mark = pos;
+ }
+
+ public void reset() {
+ if (mark == -1) throw new IllegalStateException("mark was not set");
+ pos = mark;
+ }
+
+ public void skip() {
+ pos++;
+ }
+
+ public StandardReadableByteBuf skip(int length) {
+ pos += length;
+ return this;
+ }
+
+ public MariaDbBlob readBlob(int length) {
+ pos += length;
+ return MariaDbBlob.safeMariaDbBlob(buf, pos - length, length);
+ }
+
+ public MutableInt getSequence() {
+ return sequence;
+ }
+
+ public byte getByte() {
+ return buf[pos];
+ }
+
+ public byte getByte(int index) {
+ return buf[index];
+ }
+
+ public short getUnsignedByte() {
+ return (short) (buf[pos] & 0xff);
+ }
+
+ public int readLengthNotNull() {
+ int type = (buf[pos++] & 0xff);
+ switch (type) {
+ case 252:
+ return readUnsignedShort();
+ case 253:
+ return readUnsignedMedium();
+ case 254:
+ return (int) readLong();
+ default:
+ return type;
+ }
+ }
+
+ /**
+ * Identifier can have a max length of 256 (alias) So no need to check whole length encoding.
+ *
+ * @return current pos
+ */
+ public int skipIdentifier() {
+ int type = (buf[pos++] & 0xff);
+ if (type == 252) {
+ pos += readUnsignedShort();
+ return pos;
+ }
+ pos += type;
+ return pos;
+ }
+
+ public Integer readLength() {
+ int type = readUnsignedByte();
+ switch (type) {
+ case 251:
+ return null;
+ case 252:
+ return readUnsignedShort();
+ case 253:
+ return readUnsignedMedium();
+ case 254:
+ return (int) readLong();
+ default:
+ return type;
+ }
+ }
+
+ public byte readByte() {
+ return buf[pos++];
+ }
+
+ public short readUnsignedByte() {
+ return (short) (buf[pos++] & 0xff);
+ }
+
+ public short readShort() {
+ return (short) ((buf[pos++] & 0xff) | (buf[pos++] << 8));
+ }
+
+ public int readUnsignedShort() {
+ return ((buf[pos++] & 0xff) | (buf[pos++] << 8)) & 0xffff;
+ }
+
+ public int readMedium() {
+ int value = readUnsignedMedium();
+ if ((value & 0x800000) != 0) {
+ value |= 0xff000000;
+ }
+ return value;
+ }
+
+ public int readUnsignedMedium() {
+ return ((buf[pos++] & 0xff) + ((buf[pos++] & 0xff) << 8) + ((buf[pos++] & 0xff) << 16));
+ }
+
+ public int readInt() {
+ return ((buf[pos++] & 0xff)
+ + ((buf[pos++] & 0xff) << 8)
+ + ((buf[pos++] & 0xff) << 16)
+ + ((buf[pos++] & 0xff) << 24));
+ }
+
+ public int readIntBE() {
+ return (((buf[pos++] & 0xff) << 24)
+ + ((buf[pos++] & 0xff) << 16)
+ + ((buf[pos++] & 0xff) << 8)
+ + (buf[pos++] & 0xff));
+ }
+
+ public long readUnsignedInt() {
+ return ((buf[pos++] & 0xff)
+ + ((buf[pos++] & 0xff) << 8)
+ + ((buf[pos++] & 0xff) << 16)
+ + ((long) (buf[pos++] & 0xff) << 24))
+ & 0xffffffffL;
+ }
+
+ public long readLong() {
+ return ((buf[pos++] & 0xffL)
+ + ((buf[pos++] & 0xffL) << 8)
+ + ((buf[pos++] & 0xffL) << 16)
+ + ((buf[pos++] & 0xffL) << 24)
+ + ((buf[pos++] & 0xffL) << 32)
+ + ((buf[pos++] & 0xffL) << 40)
+ + ((buf[pos++] & 0xffL) << 48)
+ + ((buf[pos++] & 0xffL) << 56));
+ }
+
+ public long readLongBE() {
+ return (((buf[pos++] & 0xffL) << 56)
+ + ((buf[pos++] & 0xffL) << 48)
+ + ((buf[pos++] & 0xffL) << 40)
+ + ((buf[pos++] & 0xffL) << 32)
+ + ((buf[pos++] & 0xffL) << 24)
+ + ((buf[pos++] & 0xffL) << 16)
+ + ((buf[pos++] & 0xffL) << 8)
+ + (buf[pos++] & 0xffL));
+ }
+
+ public StandardReadableByteBuf readBytes(byte[] dst) {
+ System.arraycopy(buf, pos, dst, 0, dst.length);
+ pos += dst.length;
+ return this;
+ }
+
+ public byte[] readBytesNullEnd() {
+ int initialPosition = pos;
+ int cnt = 0;
+ while (readableBytes() > 0 && (buf[pos++] != 0)) {
+ cnt++;
+ }
+ byte[] dst = new byte[cnt];
+ System.arraycopy(buf, initialPosition, dst, 0, dst.length);
+ return dst;
+ }
+
+ public StandardReadableByteBuf readLengthBuffer() {
+ int len = readLengthNotNull();
+ byte[] tmp = new byte[len];
+ readBytes(tmp);
+ return new StandardReadableByteBuf(sequence, tmp, len);
+ }
+
+ public String readString(int length) {
+ pos += length;
+ return new String(buf, pos - length, length, StandardCharsets.UTF_8);
+ }
+
+ public String readAscii(int length) {
+ pos += length;
+ return new String(buf, pos - length, length, StandardCharsets.US_ASCII);
+ }
+
+ public String readStringNullEnd() {
+ int initialPosition = pos;
+ int cnt = 0;
+ while (readableBytes() > 0 && (buf[pos++] != 0)) {
+ cnt++;
+ }
+ return new String(buf, initialPosition, cnt, StandardCharsets.UTF_8);
+ }
+
+ public String readStringEof() {
+ int initialPosition = pos;
+ pos = limit;
+ return new String(buf, initialPosition, pos - initialPosition, StandardCharsets.UTF_8);
+ }
+
+ public float readFloat() {
+ return Float.intBitsToFloat(readInt());
+ }
+
+ public double readDouble() {
+ return Double.longBitsToDouble(readLong());
+ }
+
+ public double readDoubleBE() {
+ return Double.longBitsToDouble(readLongBE());
+ }
+}
diff --git a/src/main/java/org/mariadb/jdbc/client/TransactionSaver.java b/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java
similarity index 93%
rename from src/main/java/org/mariadb/jdbc/client/TransactionSaver.java
rename to src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java
index ae156139e..44083ce9f 100644
--- a/src/main/java/org/mariadb/jdbc/client/TransactionSaver.java
+++ b/src/main/java/org/mariadb/jdbc/client/impl/TransactionSaver.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client;
+package org.mariadb.jdbc.client.impl;
import java.util.ArrayList;
import java.util.List;
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 1f6f8751b..ff2381981 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/CompleteResult.java
@@ -12,9 +12,10 @@
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import org.mariadb.jdbc.Statement;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.codec.DataType;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
+import org.mariadb.jdbc.client.socket.Reader;
import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
public class CompleteResult extends Result {
@@ -25,8 +26,8 @@ public CompleteResult(
Statement stmt,
boolean binaryProtocol,
long maxRows,
- ColumnDefinitionPacket[] metadataList,
- PacketReader reader,
+ Column[] metadataList,
+ Reader reader,
Context context,
int resultSetType,
boolean closeOnCompletion,
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 ea56cfdbb..eb594fe4b 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/Result.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/Result.java
@@ -17,29 +17,30 @@
import java.util.Calendar;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Completion;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
+import org.mariadb.jdbc.client.impl.StandardReadableByteBuf;
import org.mariadb.jdbc.codec.BinaryRowDecoder;
import org.mariadb.jdbc.codec.RowDecoder;
import org.mariadb.jdbc.codec.TextRowDecoder;
-import org.mariadb.jdbc.codec.list.*;
+import org.mariadb.jdbc.export.ExceptionFactory;
import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
-import org.mariadb.jdbc.message.server.Completion;
import org.mariadb.jdbc.message.server.ErrorPacket;
import org.mariadb.jdbc.plugin.Codec;
+import org.mariadb.jdbc.plugin.codec.*;
import org.mariadb.jdbc.util.constants.ServerStatus;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
public abstract class Result implements ResultSet, Completion {
protected final int resultSetType;
protected final ExceptionFactory exceptionFactory;
- protected final PacketReader reader;
+ protected final org.mariadb.jdbc.client.socket.Reader reader;
protected final Context context;
private final int maxIndex;
private final boolean closeOnCompletion;
- protected final ColumnDefinitionPacket[] metadataList;
+ protected final Column[] metadataList;
protected final RowDecoder row;
protected int dataSize = 0;
protected byte[][] data;
@@ -56,8 +57,8 @@ public Result(
org.mariadb.jdbc.Statement stmt,
boolean binaryProtocol,
long maxRows,
- ColumnDefinitionPacket[] metadataList,
- PacketReader reader,
+ Column[] metadataList,
+ org.mariadb.jdbc.client.socket.Reader reader,
Context context,
int resultSetType,
boolean closeOnCompletion,
@@ -100,14 +101,14 @@ protected boolean readNext() throws SQLException, IOException {
case (byte) 0xFF:
loaded = true;
ErrorPacket errorPacket =
- new ErrorPacket(new ReadableByteBuf(null, buf, buf.length), context);
+ new ErrorPacket(new StandardReadableByteBuf(null, buf, buf.length), context);
throw exceptionFactory.create(
errorPacket.getMessage(), errorPacket.getSqlState(), errorPacket.getErrorCode());
case (byte) 0xFE:
if ((context.isEofDeprecated() && buf.length < 16777215)
|| (!context.isEofDeprecated() && buf.length < 8)) {
- ReadableByteBuf readBuf = new ReadableByteBuf(null, buf, buf.length);
+ ReadableByteBuf readBuf = new StandardReadableByteBuf(null, buf, buf.length);
readBuf.skip(); // skip header
int serverStatus;
int warnings;
@@ -820,7 +821,7 @@ public void setStatement(Statement stmt) {
}
public void useAliasAsName() {
- for (ColumnDefinitionPacket packet : metadataList) {
+ for (Column packet : metadataList) {
packet.useAliasAsName();
}
forceAlias = true;
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 433bd49f3..272134a8b 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/ResultSetMetaData.java
@@ -8,15 +8,15 @@
import java.sql.Types;
import java.util.Locale;
import org.mariadb.jdbc.Configuration;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.DataType;
+import org.mariadb.jdbc.export.ExceptionFactory;
import org.mariadb.jdbc.util.constants.ColumnFlags;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
public class ResultSetMetaData implements java.sql.ResultSetMetaData {
private final ExceptionFactory exceptionFactory;
- private final ColumnDefinitionPacket[] fieldPackets;
+ private final Column[] fieldPackets;
private final Configuration conf;
private final boolean forceAlias;
@@ -30,7 +30,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData {
*/
public ResultSetMetaData(
final ExceptionFactory exceptionFactory,
- final ColumnDefinitionPacket[] fieldPackets,
+ final Column[] fieldPackets,
final Configuration conf,
final boolean forceAlias) {
this.exceptionFactory = exceptionFactory;
@@ -149,8 +149,8 @@ public String getColumnLabel(final int column) throws SQLException {
* @throws SQLException if a database access error occurs
*/
public String getColumnName(final int idx) throws SQLException {
- ColumnDefinitionPacket column = getColumn(idx);
- String columnName = column.getColumn();
+ Column column = getColumn(idx);
+ String columnName = column.getColumnName();
if ("".equals(columnName) || forceAlias) {
return column.getColumnAlias();
}
@@ -240,7 +240,7 @@ public int getColumnType(final int column) throws SQLException {
* @throws SQLException if a database access error occurs
*/
public String getColumnTypeName(final int index) throws SQLException {
- ColumnDefinitionPacket column = getColumn(index);
+ Column column = getColumn(index);
DataType dataType = column.getType();
if (dataType == DataType.GEOMETRY && column.getExtTypeName() != null) {
return column.getExtTypeName().toUpperCase(Locale.ROOT);
@@ -256,8 +256,8 @@ public String getColumnTypeName(final int index) throws SQLException {
* @throws SQLException if a database access error occurs or in case of wrong index
*/
public boolean isReadOnly(final int column) throws SQLException {
- ColumnDefinitionPacket ci = getColumn(column);
- return ci.getColumn().isEmpty();
+ Column ci = getColumn(column);
+ return ci.getColumnName().isEmpty();
}
/**
@@ -297,7 +297,7 @@ public String getColumnClassName(int column) throws SQLException {
return getColumn(column).getDefaultCodec(conf).className();
}
- private ColumnDefinitionPacket getColumn(int column) throws SQLException {
+ private Column getColumn(int column) throws SQLException {
if (column >= 1 && column <= fieldPackets.length) {
return fieldPackets[column - 1];
}
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 cc1fe570a..b7eb0d0ff 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/StreamingResult.java
@@ -8,9 +8,9 @@
import java.sql.SQLException;
import java.util.concurrent.locks.ReentrantLock;
import org.mariadb.jdbc.Statement;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Reader;
public class StreamingResult extends Result {
@@ -22,8 +22,8 @@ public StreamingResult(
Statement stmt,
boolean binaryProtocol,
long maxRows,
- ColumnDefinitionPacket[] metadataList,
- PacketReader reader,
+ Column[] metadataList,
+ Reader reader,
Context context,
int fetchSize,
ReentrantLock lock,
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 608229fbd..18510f2f8 100644
--- a/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java
+++ b/src/main/java/org/mariadb/jdbc/client/result/UpdatableResult.java
@@ -12,12 +12,11 @@
import org.mariadb.jdbc.BasePreparedStatement;
import org.mariadb.jdbc.Connection;
import org.mariadb.jdbc.Statement;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.codec.*;
-import org.mariadb.jdbc.codec.list.*;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
import org.mariadb.jdbc.plugin.Codec;
+import org.mariadb.jdbc.plugin.codec.*;
import org.mariadb.jdbc.util.ParameterList;
public class UpdatableResult extends CompleteResult {
@@ -42,8 +41,8 @@ public UpdatableResult(
Statement stmt,
boolean binaryProtocol,
long maxRows,
- ColumnDefinitionPacket[] metadataList,
- PacketReader reader,
+ Column[] metadataList,
+ org.mariadb.jdbc.client.socket.Reader reader,
Context context,
int resultSetType,
boolean closeOnCompletion,
@@ -71,7 +70,7 @@ private void checkIfUpdatable() throws SQLException {
// check that resultSet concern one table and database exactly
database = null;
table = null;
- for (ColumnDefinitionPacket columnDefinition : metadataList) {
+ for (Column columnDefinition : metadataList) {
if (columnDefinition.getTable().isEmpty()) {
cannotUpdateInsertRow(
"The result-set contains fields without without any database/table information");
@@ -95,7 +94,7 @@ private void checkIfUpdatable() throws SQLException {
}
// check that listed column contain primary field
- for (ColumnDefinitionPacket col : metadataList) {
+ for (Column col : metadataList) {
if (col.isPrimaryKey()) {
isAutoincrementPk = col.isAutoIncrement();
return;
@@ -403,8 +402,9 @@ public void insertRow() throws SQLException {
int paramPos = 0;
for (int pos = 0; pos < metadataList.length; pos++) {
- ColumnDefinitionPacket colInfo = metadataList[pos];
- Parameter> param = parameters.size() > pos ? parameters.get(pos) : null;
+ Column colInfo = metadataList[pos];
+ org.mariadb.jdbc.client.util.Parameter param =
+ parameters.size() > pos ? parameters.get(pos) : null;
if (param != null) {
((BasePreparedStatement) insertPreparedStatement).setParameter(paramPos++, param);
} else if (!colInfo.isPrimaryKey() && !colInfo.hasDefault()) {
@@ -455,20 +455,21 @@ private String buildInsertQuery() throws SQLException {
boolean firstParam = true;
for (int pos = 0; pos < metadataList.length; pos++) {
- ColumnDefinitionPacket colInfo = metadataList[pos];
+ Column colInfo = metadataList[pos];
if (pos != 0) {
returningClause.append(", ");
}
- returningClause.append("`").append(colInfo.getColumn()).append("`");
+ returningClause.append("`").append(colInfo.getColumnName()).append("`");
- Parameter> param = parameters.size() > pos ? parameters.get(pos) : null;
+ org.mariadb.jdbc.client.util.Parameter param =
+ parameters.size() > pos ? parameters.get(pos) : null;
if (param != null) {
if (!firstParam) {
insertSql.append(",");
valueClause.append(", ");
}
- insertSql.append("`").append(colInfo.getColumn()).append("`");
+ insertSql.append("`").append(colInfo.getColumnName()).append("`");
valueClause.append("?");
firstParam = false;
} else {
@@ -483,13 +484,13 @@ private String buildInsertQuery() throws SQLException {
String.format(
"Cannot call insertRow() not setting value for primary key %s "
+ "with default value before server 10.5",
- colInfo.getColumn()));
+ colInfo.getColumnName()));
}
} else {
throw exceptionFactory.create(
String.format(
"Cannot call insertRow() not setting value for primary key %s",
- colInfo.getColumn()));
+ colInfo.getColumnName()));
}
} else if (!colInfo.hasDefault()) {
if (!firstParam) {
@@ -497,7 +498,7 @@ private String buildInsertQuery() throws SQLException {
valueClause.append(", ");
}
firstParam = false;
- insertSql.append("`").append(colInfo.getColumn()).append("`");
+ insertSql.append("`").append(colInfo.getColumnName()).append("`");
valueClause.append("?");
}
}
@@ -518,18 +519,18 @@ private String refreshStmt() {
boolean firstPrimary = true;
for (int pos = 0; pos < metadataList.length; pos++) {
- ColumnDefinitionPacket colInfo = metadataList[pos];
+ Column colInfo = metadataList[pos];
if (pos != 0) {
selectSql.append(",");
}
- selectSql.append("`").append(colInfo.getColumn()).append("`");
+ selectSql.append("`").append(colInfo.getColumnName()).append("`");
if (colInfo.isPrimaryKey()) {
if (!firstPrimary) {
whereClause.append("AND ");
}
firstPrimary = false;
- whereClause.append("`").append(colInfo.getColumn()).append("` = ? ");
+ whereClause.append("`").append(colInfo.getColumnName()).append("` = ? ");
}
}
selectSql
@@ -558,12 +559,12 @@ private byte[] refreshRawData() throws SQLException {
int fieldsPrimaryIndex = 0;
try (PreparedStatement refreshPreparedStatement = prepareRefreshStmt()) {
for (int pos = 0; pos < metadataList.length; pos++) {
- ColumnDefinitionPacket colInfo = metadataList[pos];
+ Column colInfo = metadataList[pos];
if (colInfo.isPrimaryKey()) {
if ((state != STATE_STANDARD) && parameters.size() > pos && parameters.get(pos) != null) {
// Row has just been updated using updateRow() methods.
// updateRow might have changed primary key, so must use the new value.
- Parameter> value = parameters.get(pos);
+ org.mariadb.jdbc.client.util.Parameter value = parameters.get(pos);
((BasePreparedStatement) refreshPreparedStatement)
.setParameter(fieldsPrimaryIndex++, value);
} else {
@@ -585,14 +586,14 @@ private String updateQuery() {
boolean firstUpdate = true;
boolean firstPrimary = true;
for (int pos = 0; pos < metadataList.length; pos++) {
- ColumnDefinitionPacket colInfo = metadataList[pos];
+ Column colInfo = metadataList[pos];
if (colInfo.isPrimaryKey()) {
if (!firstPrimary) {
whereClause.append("AND ");
}
firstPrimary = false;
- whereClause.append("`").append(colInfo.getColumn()).append("` = ? ");
+ whereClause.append("`").append(colInfo.getColumnName()).append("` = ? ");
}
if (parameters.size() > pos && parameters.get(pos) != null) {
@@ -600,7 +601,7 @@ private String updateQuery() {
updateSql.append(",");
}
firstUpdate = false;
- updateSql.append("`").append(colInfo.getColumn()).append("` = ? ");
+ updateSql.append("`").append(colInfo.getColumnName()).append("` = ? ");
}
}
if (firstUpdate) return null;
@@ -641,7 +642,7 @@ public void updateRow() throws SQLException {
int fieldsIndex = 0;
for (int pos = 0; pos < metadataList.length; pos++) {
if (parameters.size() > pos) {
- Parameter> param = parameters.get(pos);
+ org.mariadb.jdbc.client.util.Parameter param = parameters.get(pos);
if (param != null) {
((BasePreparedStatement) preparedStatement).setParameter(fieldsIndex++, param);
}
@@ -649,7 +650,7 @@ public void updateRow() throws SQLException {
}
for (int pos = 0; pos < metadataList.length; pos++) {
- ColumnDefinitionPacket colInfo = metadataList[pos];
+ Column colInfo = metadataList[pos];
if (colInfo.isPrimaryKey()) {
preparedStatement.setObject(++fieldsIndex, getObject(pos + 1));
}
@@ -684,13 +685,13 @@ public void deleteRow() throws SQLException {
StringBuilder deleteSql =
new StringBuilder("DELETE FROM `" + database + "`.`" + table + "` WHERE ");
boolean firstPrimary = true;
- for (ColumnDefinitionPacket colInfo : metadataList) {
+ for (Column colInfo : metadataList) {
if (colInfo.isPrimaryKey()) {
if (!firstPrimary) {
deleteSql.append("AND ");
}
firstPrimary = false;
- deleteSql.append("`").append(colInfo.getColumn()).append("` = ? ");
+ deleteSql.append("`").append(colInfo.getColumnName()).append("` = ? ");
}
}
@@ -705,7 +706,7 @@ public void deleteRow() throws SQLException {
int fieldsPrimaryIndex = 1;
for (int pos = 0; pos < metadataList.length; pos++) {
- ColumnDefinitionPacket colInfo = metadataList[pos];
+ Column colInfo = metadataList[pos];
if (colInfo.isPrimaryKey()) {
deletePreparedStatement.setObject(fieldsPrimaryIndex++, getObject(pos + 1));
}
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/Reader.java b/src/main/java/org/mariadb/jdbc/client/socket/Reader.java
new file mode 100644
index 000000000..c67fbf8e9
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/client/socket/Reader.java
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2021 MariaDB Corporation Ab
+
+package org.mariadb.jdbc.client.socket;
+
+import java.io.IOException;
+import org.mariadb.jdbc.HostAddress;
+import org.mariadb.jdbc.client.ReadableByteBuf;
+import org.mariadb.jdbc.client.util.MutableInt;
+
+public interface Reader {
+
+ /**
+ * Get next MySQL packet. If packet is more than 16M, read as many packet needed to finish reading
+ * MySQL packet. (first that has not length = 16Mb)
+ *
+ * @param reUsable if packet can use existing reusable buf to avoid creating array
+ * @return array packet.
+ * @throws IOException if socket exception occur.
+ */
+ ReadableByteBuf readPacket(boolean reUsable) throws IOException;
+
+ /**
+ * Get next MySQL packet. If packet is more than 16M, read as many packet needed to finish reading
+ * MySQL packet. (first that has not length = 16Mb)
+ *
+ * @param reUsable if packet can use existing reusable buf to avoid creating array
+ * @param traceEnable must trace packet.
+ * @return array packet.
+ * @throws IOException if socket exception occur.
+ */
+ ReadableByteBuf readPacket(boolean reUsable, boolean traceEnable) throws IOException;
+
+ MutableInt getSequence();
+
+ void close() throws IOException;
+
+ /**
+ * Set server thread id.
+ *
+ * @param serverThreadId current server thread id.
+ * @param hostAddress host information
+ */
+ void setServerThreadId(Long serverThreadId, HostAddress hostAddress);
+}
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/Writer.java b/src/main/java/org/mariadb/jdbc/client/socket/Writer.java
new file mode 100644
index 000000000..009ca7fcf
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/client/socket/Writer.java
@@ -0,0 +1,152 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2021 MariaDB Corporation Ab
+
+package org.mariadb.jdbc.client.socket;
+
+import java.io.IOException;
+import org.mariadb.jdbc.HostAddress;
+
+public interface Writer {
+
+ int pos();
+
+ void pos(int pos) throws IOException;
+
+ /**
+ * Write byte into buf, flush buf to socket if needed.
+ *
+ * @param value byte to send
+ * @throws IOException if socket error occur.
+ */
+ void writeByte(int value) throws IOException;
+
+ /**
+ * Write short value into buf. flush buf if too small.
+ *
+ * @param value short value
+ * @throws IOException if socket error occur
+ */
+ void writeShort(short value) throws IOException;
+
+ /**
+ * Write int value into buf. flush buf if too small.
+ *
+ * @param value int value
+ * @throws IOException if socket error occur
+ */
+ void writeInt(int value) throws IOException;
+
+ /**
+ * Write long value into buf. flush buf if too small.
+ *
+ * @param value long value
+ * @throws IOException if socket error occur
+ */
+ void writeLong(long value) throws IOException;
+
+ void writeDouble(double value) throws IOException;
+
+ void writeFloat(float value) throws IOException;
+
+ void writeBytes(byte[] arr) throws IOException;
+
+ void writeBytesAtPos(byte[] arr, int pos);
+
+ /**
+ * Write byte array to buf. If buf is full, flush socket.
+ *
+ * @param arr byte array
+ * @param off offset
+ * @param len byte length to write
+ * @throws IOException if socket error occur
+ */
+ void writeBytes(byte[] arr, int off, int len) throws IOException;
+
+ /**
+ * Write field length into buf, flush socket if needed.
+ *
+ * @param length field length
+ * @throws IOException if socket error occur.
+ */
+ void writeLength(long length) throws IOException;
+
+ void writeAscii(String str) throws IOException;
+
+ void writeString(String str) throws IOException;
+
+ /**
+ * Write string to socket.
+ *
+ * @param str string
+ * @param noBackslashEscapes escape method
+ * @throws IOException if socket error occur
+ */
+ void writeStringEscaped(String str, boolean noBackslashEscapes) throws IOException;
+
+ /**
+ * Write escape bytes to socket.
+ *
+ * @param bytes bytes
+ * @param len len to write
+ * @param noBackslashEscapes escape method
+ * @throws IOException if socket error occur
+ */
+ void writeBytesEscaped(byte[] bytes, int len, boolean noBackslashEscapes) throws IOException;
+
+ /**
+ * Send empty packet.
+ *
+ * @throws IOException if socket error occur.
+ */
+ void writeEmptyPacket() throws IOException;
+
+ /**
+ * Send packet to socket.
+ *
+ * @throws IOException if socket error occur.
+ */
+ void flush() throws IOException;
+
+ boolean throwMaxAllowedLength(int length);
+
+ long getCmdLength();
+
+ void setMaxAllowedPacket(int maxAllowedPacket);
+
+ void permitTrace(boolean permitTrace);
+
+ /**
+ * Set server thread id.
+ *
+ * @param serverThreadId current server thread id.
+ * @param hostAddress host information
+ */
+ void setServerThreadId(Long serverThreadId, HostAddress hostAddress);
+
+ void mark();
+
+ boolean isMarked();
+
+ boolean hasFlushed();
+
+ /**
+ * Flush to last mark.
+ *
+ * @throws IOException if flush fail.
+ */
+ void flushBufferStopAtMark() throws IOException;
+
+ boolean bufIsDataAfterMark();
+
+ /**
+ * Reset mark flag and send bytes after mark flag.
+ *
+ * @return bytes after mark flag
+ */
+ byte[] resetMark();
+
+ void initPacket();
+
+ void close() throws IOException;
+}
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/CompressInputStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java
similarity index 99%
rename from src/main/java/org/mariadb/jdbc/client/socket/CompressInputStream.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java
index b6c66d6fd..803f125d6 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/CompressInputStream.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressInputStream.java
@@ -2,14 +2,14 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
-import org.mariadb.jdbc.util.MutableInt;
+import org.mariadb.jdbc.client.util.MutableInt;
public class CompressInputStream extends InputStream {
private final InputStream in;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/CompressOutputStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java
similarity index 98%
rename from src/main/java/org/mariadb/jdbc/client/socket/CompressOutputStream.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java
index 5cf7e0e07..a4a07872a 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/CompressOutputStream.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/CompressOutputStream.java
@@ -2,13 +2,13 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.DeflaterOutputStream;
-import org.mariadb.jdbc.util.MutableInt;
+import org.mariadb.jdbc.client.util.MutableInt;
public class CompressOutputStream extends OutputStream {
private static final int MIN_COMPRESSION_SIZE = 1536; // TCP-IP single packet
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/NamedPipeSocket.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java
similarity index 98%
rename from src/main/java/org/mariadb/jdbc/client/socket/NamedPipeSocket.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java
index d8ce52c4b..9d8f0aa02 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/NamedPipeSocket.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/NamedPipeSocket.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import com.sun.jna.platform.win32.Kernel32;
import java.io.*;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/PacketReader.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java
similarity index 95%
rename from src/main/java/org/mariadb/jdbc/client/socket/PacketReader.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java
index f39f29acd..1543a092a 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/PacketReader.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketReader.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import java.io.EOFException;
import java.io.IOException;
@@ -10,12 +10,14 @@
import org.mariadb.jdbc.Configuration;
import org.mariadb.jdbc.HostAddress;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.util.MutableInt;
+import org.mariadb.jdbc.client.impl.StandardReadableByteBuf;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.util.MutableInt;
import org.mariadb.jdbc.util.log.Logger;
import org.mariadb.jdbc.util.log.LoggerHelper;
import org.mariadb.jdbc.util.log.Loggers;
-public class PacketReader {
+public class PacketReader implements Reader {
private static final int REUSABLE_BUFFER_LENGTH = 1024;
private static final int MAX_PACKET_SIZE = 0xffffff;
@@ -174,7 +176,7 @@ public ReadableByteBuf readPacket(boolean reUsable, boolean traceEnable) throws
} while (packetLength == MAX_PACKET_SIZE);
}
- return new ReadableByteBuf(sequence, rawBytes, lastPacketLength);
+ return new StandardReadableByteBuf(sequence, rawBytes, lastPacketLength);
}
public MutableInt getSequence() {
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/PacketWriter.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java
similarity index 97%
rename from src/main/java/org/mariadb/jdbc/client/socket/PacketWriter.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java
index bcf6ae6c3..9ddf07166 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/PacketWriter.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/PacketWriter.java
@@ -2,21 +2,22 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.mariadb.jdbc.HostAddress;
-import org.mariadb.jdbc.util.MutableInt;
-import org.mariadb.jdbc.util.exceptions.MaxAllowedPacketException;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.client.util.MutableInt;
+import org.mariadb.jdbc.export.MaxAllowedPacketException;
import org.mariadb.jdbc.util.log.Logger;
import org.mariadb.jdbc.util.log.LoggerHelper;
import org.mariadb.jdbc.util.log.Loggers;
@SuppressWarnings("SameReturnValue")
-public class PacketWriter {
+public class PacketWriter implements Writer {
public static final int SMALL_BUFFER_SIZE = 8192;
private static final Logger logger = Loggers.getLogger(PacketWriter.class);
@@ -68,6 +69,10 @@ public void pos(int pos) throws IOException {
this.pos = pos;
}
+ public long getCmdLength() {
+ return cmdLength;
+ }
+
/**
* Write byte into buf, flush buf to socket if needed.
*
@@ -677,7 +682,7 @@ public void flush() throws IOException {
* @param length additional length to query size
* @throws MaxAllowedPacketException if query has not to be sent.
*/
- public void checkMaxAllowedLength(int length) throws MaxAllowedPacketException {
+ private void checkMaxAllowedLength(int length) throws MaxAllowedPacketException {
if (cmdLength + length >= maxAllowedPacket) {
// launch exception only if no packet has been sent.
throw new MaxAllowedPacketException(
@@ -690,6 +695,10 @@ public void checkMaxAllowedLength(int length) throws MaxAllowedPacketException {
}
}
+ public boolean throwMaxAllowedLength(int length) {
+ return cmdLength + length >= maxAllowedPacket;
+ }
+
public void setMaxAllowedPacket(int maxAllowedPacket) {
this.maxAllowedPacket = maxAllowedPacket;
maxPacketLength = Math.min(MAX_PACKET_LENGTH, maxAllowedPacket + 4);
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/ReadAheadBufferedStream.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java
similarity index 98%
rename from src/main/java/org/mariadb/jdbc/client/socket/ReadAheadBufferedStream.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java
index 46cfa829e..88905fed4 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/ReadAheadBufferedStream.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/ReadAheadBufferedStream.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import java.io.FilterInputStream;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/SocketHandlerFunction.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java
similarity index 91%
rename from src/main/java/org/mariadb/jdbc/client/socket/SocketHandlerFunction.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java
index 020b4df83..b5a40df00 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/SocketHandlerFunction.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketHandlerFunction.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import java.io.IOException;
import java.net.Socket;
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/SocketUtility.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java
similarity index 92%
rename from src/main/java/org/mariadb/jdbc/client/socket/SocketUtility.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java
index 35387e3ca..79965c167 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/SocketUtility.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/SocketUtility.java
@@ -2,11 +2,11 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import com.sun.jna.Platform;
import java.io.IOException;
-import org.mariadb.jdbc.client.ConnectionHelper;
+import org.mariadb.jdbc.client.impl.ConnectionHelper;
public class SocketUtility {
diff --git a/src/main/java/org/mariadb/jdbc/client/socket/UnixDomainSocket.java b/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java
similarity index 99%
rename from src/main/java/org/mariadb/jdbc/client/socket/UnixDomainSocket.java
rename to src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java
index a89c6585b..afb32a814 100644
--- a/src/main/java/org/mariadb/jdbc/client/socket/UnixDomainSocket.java
+++ b/src/main/java/org/mariadb/jdbc/client/socket/impl/UnixDomainSocket.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.client.socket;
+package org.mariadb.jdbc.client.socket.impl;
import com.sun.jna.LastErrorException;
import com.sun.jna.Native;
diff --git a/src/main/java/org/mariadb/jdbc/util/MutableInt.java b/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java
similarity index 90%
rename from src/main/java/org/mariadb/jdbc/util/MutableInt.java
rename to src/main/java/org/mariadb/jdbc/client/util/MutableInt.java
index a78245435..eb2fe2c48 100644
--- a/src/main/java/org/mariadb/jdbc/util/MutableInt.java
+++ b/src/main/java/org/mariadb/jdbc/client/util/MutableInt.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.util;
+package org.mariadb.jdbc.client.util;
public class MutableInt {
private byte value = -1;
diff --git a/src/main/java/org/mariadb/jdbc/client/util/Parameter.java b/src/main/java/org/mariadb/jdbc/client/util/Parameter.java
new file mode 100644
index 000000000..7c53f6f1b
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/client/util/Parameter.java
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2021 MariaDB Corporation Ab
+
+package org.mariadb.jdbc.client.util;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+
+public interface Parameter {
+
+ void encodeText(Writer encoder, Context context) throws IOException, SQLException;
+
+ void encodeBinary(Writer encoder) throws IOException, SQLException;
+
+ void encodeLongData(Writer encoder) throws IOException, SQLException;
+
+ byte[] encodeData() throws IOException, SQLException;
+
+ boolean canEncodeLongData();
+
+ int getBinaryEncodeType();
+
+ boolean isNull();
+}
diff --git a/src/main/java/org/mariadb/jdbc/client/util/Parameters.java b/src/main/java/org/mariadb/jdbc/client/util/Parameters.java
new file mode 100644
index 000000000..a0c2e6451
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/client/util/Parameters.java
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2021 MariaDB Corporation Ab
+
+package org.mariadb.jdbc.client.util;
+
+public interface Parameters {
+
+ Parameter get(int index);
+
+ boolean containsKey(int index);
+
+ void set(int index, Parameter element);
+
+ int size();
+
+ Parameters clone();
+}
diff --git a/src/main/java/org/mariadb/jdbc/codec/BinaryRowDecoder.java b/src/main/java/org/mariadb/jdbc/codec/BinaryRowDecoder.java
index b4f6dc45d..aab498892 100644
--- a/src/main/java/org/mariadb/jdbc/codec/BinaryRowDecoder.java
+++ b/src/main/java/org/mariadb/jdbc/codec/BinaryRowDecoder.java
@@ -7,15 +7,15 @@
import java.sql.SQLException;
import java.util.Calendar;
import org.mariadb.jdbc.Configuration;
-import org.mariadb.jdbc.codec.list.*;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.Column;
import org.mariadb.jdbc.plugin.Codec;
+import org.mariadb.jdbc.plugin.codec.*;
public class BinaryRowDecoder extends RowDecoder {
private byte[] nullBitmap;
- public BinaryRowDecoder(int columnCount, ColumnDefinitionPacket[] columns, Configuration conf) {
+ public BinaryRowDecoder(int columnCount, Column[] columns, Configuration conf) {
super(columnCount, columns, conf);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/Parameter.java b/src/main/java/org/mariadb/jdbc/codec/Parameter.java
index aea8ac446..031e43790 100644
--- a/src/main/java/org/mariadb/jdbc/codec/Parameter.java
+++ b/src/main/java/org/mariadb/jdbc/codec/Parameter.java
@@ -6,11 +6,12 @@
import java.io.IOException;
import java.sql.SQLException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
-public class Parameter {
+public class Parameter implements org.mariadb.jdbc.client.util.Parameter {
@SuppressWarnings({"rawtypes", "unchecked"})
public static final Parameter> NULL_PARAMETER =
new Parameter(null, null) {
@@ -41,15 +42,15 @@ public Parameter(Codec codec, T value, Long length) {
this.length = length;
}
- public void encodeText(PacketWriter encoder, Context context) throws IOException, SQLException {
+ public void encodeText(Writer encoder, Context context) throws IOException, SQLException {
codec.encodeText(encoder, context, this.value, null, length);
}
- public void encodeBinary(PacketWriter encoder) throws IOException, SQLException {
+ public void encodeBinary(Writer encoder) throws IOException, SQLException {
codec.encodeBinary(encoder, this.value, null, length);
}
- public void encodeLongData(PacketWriter encoder) throws IOException, SQLException {
+ public void encodeLongData(Writer encoder) throws IOException, SQLException {
codec.encodeLongData(encoder, this.value, length);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java b/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java
index 67c94cfcf..bfcd18a41 100644
--- a/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java
+++ b/src/main/java/org/mariadb/jdbc/codec/ParameterWithCal.java
@@ -7,8 +7,8 @@
import java.io.IOException;
import java.sql.SQLException;
import java.util.Calendar;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class ParameterWithCal extends Parameter {
@@ -21,12 +21,12 @@ public ParameterWithCal(Codec codec, T value, Calendar cal) {
}
@Override
- public void encodeText(PacketWriter encoder, Context context) throws IOException, SQLException {
+ public void encodeText(Writer encoder, Context context) throws IOException, SQLException {
codec.encodeText(encoder, context, this.value, this.cal, length);
}
@Override
- public void encodeBinary(PacketWriter encoder) throws IOException, SQLException {
+ public void encodeBinary(Writer encoder) throws IOException, SQLException {
codec.encodeBinary(encoder, this.value, this.cal, length);
}
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/RowDecoder.java b/src/main/java/org/mariadb/jdbc/codec/RowDecoder.java
index f9d3bd905..605a7c96f 100644
--- a/src/main/java/org/mariadb/jdbc/codec/RowDecoder.java
+++ b/src/main/java/org/mariadb/jdbc/codec/RowDecoder.java
@@ -8,22 +8,23 @@
import java.sql.SQLException;
import java.util.*;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Column;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.impl.StandardReadableByteBuf;
import org.mariadb.jdbc.plugin.Codec;
public abstract class RowDecoder {
protected static final int NULL_LENGTH = -1;
private final Configuration conf;
- protected final ReadableByteBuf readBuf = new ReadableByteBuf(null, null, 0);
- protected final ColumnDefinitionPacket[] columns;
+ protected final ReadableByteBuf readBuf = new StandardReadableByteBuf(null, null, 0);
+ protected final Column[] columns;
protected int length;
protected int index;
protected final int columnCount;
private Map mapper = null;
- public RowDecoder(int columnCount, ColumnDefinitionPacket[] columns, Configuration conf) {
+ public RowDecoder(int columnCount, Column[] columns, Configuration conf) {
this.columnCount = columnCount;
this.columns = columns;
this.conf = conf;
@@ -64,7 +65,7 @@ public T getValue(int index, Class type, Calendar calendar) throws SQLExc
return null;
}
- ColumnDefinitionPacket column = columns[index - 1];
+ Column column = columns[index - 1];
// type generic, return "natural" java type
if (Object.class.equals(type) || type == null) {
Codec defaultCodec = ((Codec) column.getDefaultCodec(conf));
@@ -177,7 +178,7 @@ public int getIndex(String label) throws SQLException {
if (mapper == null) {
mapper = new HashMap<>();
for (int i = 0; i < columnCount; i++) {
- ColumnDefinitionPacket ci = columns[i];
+ Column ci = columns[i];
String columnAlias = ci.getColumnAlias();
if (columnAlias != null) {
columnAlias = columnAlias.toLowerCase(Locale.ROOT);
diff --git a/src/main/java/org/mariadb/jdbc/codec/TextRowDecoder.java b/src/main/java/org/mariadb/jdbc/codec/TextRowDecoder.java
index 3e62280b8..dda345ec7 100644
--- a/src/main/java/org/mariadb/jdbc/codec/TextRowDecoder.java
+++ b/src/main/java/org/mariadb/jdbc/codec/TextRowDecoder.java
@@ -7,13 +7,13 @@
import java.sql.SQLException;
import java.util.Calendar;
import org.mariadb.jdbc.Configuration;
-import org.mariadb.jdbc.codec.list.*;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.Column;
import org.mariadb.jdbc.plugin.Codec;
+import org.mariadb.jdbc.plugin.codec.*;
public class TextRowDecoder extends RowDecoder {
- public TextRowDecoder(int columnCount, ColumnDefinitionPacket[] columns, Configuration conf) {
+ public TextRowDecoder(int columnCount, Column[] columns, Configuration conf) {
super(columnCount, columns, conf);
}
diff --git a/src/main/java/org/mariadb/jdbc/util/exceptions/ExceptionFactory.java b/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java
similarity index 98%
rename from src/main/java/org/mariadb/jdbc/util/exceptions/ExceptionFactory.java
rename to src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java
index 811349863..26782cd2e 100644
--- a/src/main/java/org/mariadb/jdbc/util/exceptions/ExceptionFactory.java
+++ b/src/main/java/org/mariadb/jdbc/export/ExceptionFactory.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.util.exceptions;
+package org.mariadb.jdbc.export;
import java.sql.*;
import java.util.Arrays;
@@ -13,7 +13,7 @@
import org.mariadb.jdbc.Connection;
import org.mariadb.jdbc.HostAddress;
import org.mariadb.jdbc.MariaDbPoolConnection;
-import org.mariadb.jdbc.message.server.Completion;
+import org.mariadb.jdbc.client.Completion;
import org.mariadb.jdbc.message.server.OkPacket;
public class ExceptionFactory {
diff --git a/src/main/java/org/mariadb/jdbc/util/constants/HaMode.java b/src/main/java/org/mariadb/jdbc/export/HaMode.java
similarity index 98%
rename from src/main/java/org/mariadb/jdbc/util/constants/HaMode.java
rename to src/main/java/org/mariadb/jdbc/export/HaMode.java
index 9ce32bb6c..e06263984 100644
--- a/src/main/java/org/mariadb/jdbc/util/constants/HaMode.java
+++ b/src/main/java/org/mariadb/jdbc/export/HaMode.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.util.constants;
+package org.mariadb.jdbc.export;
import java.util.*;
import java.util.concurrent.ConcurrentMap;
diff --git a/src/main/java/org/mariadb/jdbc/util/exceptions/MaxAllowedPacketException.java b/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java
similarity index 92%
rename from src/main/java/org/mariadb/jdbc/util/exceptions/MaxAllowedPacketException.java
rename to src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java
index 60f1bc004..b72a1ee89 100644
--- a/src/main/java/org/mariadb/jdbc/util/exceptions/MaxAllowedPacketException.java
+++ b/src/main/java/org/mariadb/jdbc/export/MaxAllowedPacketException.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.util.exceptions;
+package org.mariadb.jdbc.export;
import java.io.IOException;
diff --git a/src/main/java/org/mariadb/jdbc/export/Prepare.java b/src/main/java/org/mariadb/jdbc/export/Prepare.java
new file mode 100644
index 000000000..f6c3e18bd
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/export/Prepare.java
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2021 MariaDB Corporation Ab
+
+package org.mariadb.jdbc.export;
+
+import java.sql.SQLException;
+import org.mariadb.jdbc.ServerPreparedStatement;
+import org.mariadb.jdbc.client.Client;
+import org.mariadb.jdbc.client.Column;
+
+public interface Prepare {
+ void close(Client con) throws SQLException;
+
+ void decrementUse(Client con, ServerPreparedStatement preparedStatement) throws SQLException;
+
+ int getStatementId();
+
+ Column[] getParameters();
+
+ Column[] getColumns();
+
+ void setColumns(Column[] columns);
+}
diff --git a/src/main/java/org/mariadb/jdbc/SslMode.java b/src/main/java/org/mariadb/jdbc/export/SslMode.java
similarity index 97%
rename from src/main/java/org/mariadb/jdbc/SslMode.java
rename to src/main/java/org/mariadb/jdbc/export/SslMode.java
index 15b771786..43b14b6b3 100644
--- a/src/main/java/org/mariadb/jdbc/SslMode.java
+++ b/src/main/java/org/mariadb/jdbc/export/SslMode.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc;
+package org.mariadb.jdbc.export;
public enum SslMode {
// NO SSL
diff --git a/src/main/java/org/mariadb/jdbc/message/client/ClientMessage.java b/src/main/java/org/mariadb/jdbc/message/ClientMessage.java
similarity index 92%
rename from src/main/java/org/mariadb/jdbc/message/client/ClientMessage.java
rename to src/main/java/org/mariadb/jdbc/message/ClientMessage.java
index 4e5cc3b8e..43670cc72 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ClientMessage.java
+++ b/src/main/java/org/mariadb/jdbc/message/ClientMessage.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.message.client;
+package org.mariadb.jdbc.message;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -13,23 +13,24 @@
import java.util.concurrent.locks.ReentrantLock;
import org.mariadb.jdbc.BasePreparedStatement;
import org.mariadb.jdbc.Statement;
-import org.mariadb.jdbc.client.*;
-import org.mariadb.jdbc.client.context.Context;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Completion;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.ReadableByteBuf;
import org.mariadb.jdbc.client.result.CompleteResult;
import org.mariadb.jdbc.client.result.StreamingResult;
import org.mariadb.jdbc.client.result.UpdatableResult;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.export.ExceptionFactory;
import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
-import org.mariadb.jdbc.message.server.Completion;
import org.mariadb.jdbc.message.server.ErrorPacket;
import org.mariadb.jdbc.message.server.OkPacket;
import org.mariadb.jdbc.util.constants.ServerStatus;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
public interface ClientMessage {
- int encode(PacketWriter writer, Context context) throws IOException, SQLException;
+ int encode(Writer writer, Context context) throws IOException, SQLException;
default int batchUpdateLength() {
return 0;
@@ -54,8 +55,8 @@ default Completion readPacket(
int resultSetConcurrency,
int resultSetType,
boolean closeOnCompletion,
- PacketReader reader,
- PacketWriter writer,
+ Reader reader,
+ Writer writer,
Context context,
ExceptionFactory exceptionFactory,
ReentrantLock lock,
@@ -135,14 +136,14 @@ default Completion readPacket(
default:
int fieldCount = buf.readLengthNotNull();
- ColumnDefinitionPacket[] ci;
+ Column[] ci;
if (context.canSkipMeta() && this.canSkipMeta()) {
boolean skipMeta = buf.readByte() == 0;
if (skipMeta) {
ci = ((BasePreparedStatement) stmt).getMeta();
} else {
// read columns information's
- ci = new ColumnDefinitionPacket[fieldCount];
+ ci = new Column[fieldCount];
for (int i = 0; i < fieldCount; i++) {
ci[i] =
new ColumnDefinitionPacket(
diff --git a/src/main/java/org/mariadb/jdbc/message/server/ServerMessage.java b/src/main/java/org/mariadb/jdbc/message/ServerMessage.java
similarity index 81%
rename from src/main/java/org/mariadb/jdbc/message/server/ServerMessage.java
rename to src/main/java/org/mariadb/jdbc/message/ServerMessage.java
index 8e0e3e537..ad40b11f7 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/ServerMessage.java
+++ b/src/main/java/org/mariadb/jdbc/message/ServerMessage.java
@@ -2,6 +2,6 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.message.server;
+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 767dffc80..18d3ed26c 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/AuthMoreRawPacket.java
@@ -5,8 +5,9 @@
package org.mariadb.jdbc.message.client;
import java.io.IOException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.message.ClientMessage;
public final class AuthMoreRawPacket implements ClientMessage {
@@ -17,7 +18,7 @@ public AuthMoreRawPacket(byte[] raw) {
}
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
if (raw.length == 0) {
writer.writeEmptyPacket();
} else {
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 df319159b..39096b8dd 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/BulkExecutePacket.java
@@ -10,21 +10,23 @@
import java.util.Iterator;
import java.util.List;
import org.mariadb.jdbc.ServerPreparedStatement;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.Parameter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.client.util.Parameter;
+import org.mariadb.jdbc.client.util.Parameters;
+import org.mariadb.jdbc.export.MaxAllowedPacketException;
+import org.mariadb.jdbc.export.Prepare;
import org.mariadb.jdbc.message.server.PrepareResultPacket;
-import org.mariadb.jdbc.util.ParameterList;
public final class BulkExecutePacket implements RedoableWithPrepareClientMessage {
- private List batchParameterList;
+ private List batchParameterList;
private final String command;
private final ServerPreparedStatement prep;
- private PrepareResultPacket prepareResult;
+ private Prepare prepareResult;
public BulkExecutePacket(
- PrepareResultPacket prepareResult,
- List batchParameterList,
+ Prepare prepareResult,
+ List batchParameterList,
String command,
ServerPreparedStatement prep) {
this.batchParameterList = batchParameterList;
@@ -34,14 +36,14 @@ public BulkExecutePacket(
}
public void saveParameters() {
- List savedList = new ArrayList<>(batchParameterList.size());
- for (ParameterList parameterList : batchParameterList) {
+ List savedList = new ArrayList<>(batchParameterList.size());
+ for (Parameters parameterList : batchParameterList) {
savedList.add(parameterList.clone());
}
this.batchParameterList = savedList;
}
- public int encode(PacketWriter writer, Context context, PrepareResultPacket newPrepareResult)
+ public int encode(Writer writer, Context context, Prepare newPrepareResult)
throws IOException, SQLException {
int statementId =
@@ -49,12 +51,12 @@ public int encode(PacketWriter writer, Context context, PrepareResultPacket newP
? newPrepareResult.getStatementId()
: (this.prepareResult != null ? this.prepareResult.getStatementId() : -1);
- Iterator paramIterator = batchParameterList.iterator();
- ParameterList parameters = paramIterator.next();
+ Iterator paramIterator = batchParameterList.iterator();
+ Parameters parameters = paramIterator.next();
int parameterCount = parameters.size();
@SuppressWarnings("rawtypes")
- Parameter>[] parameterHeaderType = new Parameter[parameterCount];
+ Parameter[] parameterHeaderType = new Parameter[parameterCount];
// set header type
for (int i = 0; i < parameterCount; i++) {
parameterHeaderType[i] = parameters.get(i);
@@ -82,7 +84,10 @@ public int encode(PacketWriter writer, Context context, PrepareResultPacket newP
}
if (lastCmdData != null) {
- writer.checkMaxAllowedLength(lastCmdData.length);
+ if (writer.throwMaxAllowedLength(lastCmdData.length)) {
+ throw new MaxAllowedPacketException(
+ "query size is >= to max_allowed_packet", writer.getCmdLength() != 0);
+ }
writer.writeBytes(lastCmdData);
writer.mark();
lastCmdData = null;
@@ -95,7 +100,7 @@ public int encode(PacketWriter writer, Context context, PrepareResultPacket newP
parameter_loop:
while (true) {
for (int i = 0; i < parameterCount; i++) {
- Parameter> param = parameters.get(i);
+ Parameter param = parameters.get(i);
if (param.isNull()) {
writer.writeByte(0x01); // value is null
} else {
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 e2fd92e24..4584b3fd4 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/ChangeDbPacket.java
@@ -5,8 +5,8 @@
package org.mariadb.jdbc.message.client;
import java.io.IOException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
public final class ChangeDbPacket implements RedoableClientMessage {
@@ -17,7 +17,7 @@ public ChangeDbPacket(String database) {
}
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
writer.initPacket();
writer.writeByte(0x02);
writer.writeString(this.database);
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 51493ce36..bca132d0f 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/ClosePreparePacket.java
@@ -5,8 +5,9 @@
package org.mariadb.jdbc.message.client;
import java.io.IOException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.message.ClientMessage;
public final class ClosePreparePacket implements ClientMessage {
@@ -21,7 +22,7 @@ public ClosePreparePacket(int statementId) {
* https://mariadb.com/kb/en/3-binary-protocol-prepared-statements-com_stmt_close/
*/
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
writer.initPacket();
writer.writeByte(0x19);
writer.writeInt(statementId);
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 1ed8a88f9..07fe907cc 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/ExecutePacket.java
@@ -7,25 +7,23 @@
import java.io.IOException;
import java.sql.SQLException;
import org.mariadb.jdbc.ServerPreparedStatement;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.Parameter;
-import org.mariadb.jdbc.codec.list.ByteArrayCodec;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.client.util.Parameter;
+import org.mariadb.jdbc.client.util.Parameters;
+import org.mariadb.jdbc.export.Prepare;
import org.mariadb.jdbc.message.server.PrepareResultPacket;
-import org.mariadb.jdbc.util.ParameterList;
+import org.mariadb.jdbc.plugin.codec.ByteArrayCodec;
/** See https://mariadb.com/kb/en/com_stmt_execute/ for documentation */
public final class ExecutePacket implements RedoableWithPrepareClientMessage {
- private ParameterList parameters;
+ private Parameters parameters;
private final String command;
private final ServerPreparedStatement prep;
- private PrepareResultPacket prepareResult;
+ private Prepare prepareResult;
public ExecutePacket(
- PrepareResultPacket prepareResult,
- ParameterList parameters,
- String command,
- ServerPreparedStatement prep) {
+ Prepare prepareResult, Parameters parameters, String command, ServerPreparedStatement prep) {
this.parameters = parameters;
this.prepareResult = prepareResult;
this.command = command;
@@ -40,14 +38,15 @@ public void saveParameters() {
public void ensureReplayable(Context context) throws IOException, SQLException {
int parameterCount = parameters.size();
for (int i = 0; i < parameterCount; i++) {
- Parameter> p = parameters.get(i);
+ Parameter p = parameters.get(i);
if (!p.isNull() && p.canEncodeLongData()) {
- this.parameters.set(i, new Parameter<>(ByteArrayCodec.INSTANCE, p.encodeData()));
+ this.parameters.set(
+ i, new org.mariadb.jdbc.codec.Parameter<>(ByteArrayCodec.INSTANCE, p.encodeData()));
}
}
}
- public int encode(PacketWriter writer, Context context, PrepareResultPacket newPrepareResult)
+ public int encode(Writer writer, Context context, Prepare newPrepareResult)
throws IOException, SQLException {
int statementId =
@@ -59,7 +58,7 @@ public int encode(PacketWriter writer, Context context, PrepareResultPacket newP
// send long data value in separate packet
for (int i = 0; i < parameterCount; i++) {
- Parameter> p = parameters.get(i);
+ Parameter p = parameters.get(i);
if (!p.isNull() && p.canEncodeLongData()) {
new LongDataPacket(statementId, p, i).encode(writer, context);
}
@@ -84,7 +83,7 @@ public int encode(PacketWriter writer, Context context, PrepareResultPacket newP
// Store types of parameters in first package that is sent to the server.
for (int i = 0; i < parameterCount; i++) {
- Parameter> p = parameters.get(i);
+ Parameter p = parameters.get(i);
writer.writeByte(p.getBinaryEncodeType());
writer.writeByte(0);
if (p.isNull()) {
@@ -97,7 +96,7 @@ public int encode(PacketWriter writer, Context context, PrepareResultPacket newP
// send not null parameter, not long data
for (int i = 0; i < parameterCount; i++) {
- Parameter> p = parameters.get(i);
+ Parameter p = parameters.get(i);
if (!p.isNull() && !p.canEncodeLongData()) {
p.encodeBinary(writer);
}
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 923050294..53fd81e0b 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/HandshakeResponse.java
@@ -8,8 +8,9 @@
import java.nio.charset.StandardCharsets;
import java.util.StringTokenizer;
import org.mariadb.jdbc.Configuration;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+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.VersionFactory;
@@ -54,21 +55,20 @@ public HandshakeResponse(
this.exchangeCharset = exchangeCharset;
}
- private static void writeStringLengthAscii(PacketWriter encoder, String value)
- throws IOException {
+ private static void writeStringLengthAscii(Writer encoder, String value) throws IOException {
byte[] valBytes = value.getBytes(StandardCharsets.US_ASCII);
encoder.writeLength(valBytes.length);
encoder.writeBytes(valBytes);
}
- private static void writeStringLength(PacketWriter encoder, String value) throws IOException {
+ private static void writeStringLength(Writer encoder, String value) throws IOException {
byte[] valBytes = value.getBytes(StandardCharsets.UTF_8);
encoder.writeLength(valBytes.length);
encoder.writeBytes(valBytes);
}
private static void writeConnectAttributes(
- PacketWriter writer, String connectionAttributes, String host) throws IOException {
+ Writer writer, String connectionAttributes, String host) throws IOException {
writer.mark();
writer.writeInt(0);
@@ -123,7 +123,7 @@ private static void writeConnectAttributes(
}
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
final byte[] authData;
if ("mysql_clear_password".equals(authenticationPluginType)) {
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 b1c6bc49d..fe869dbac 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/LongDataPacket.java
@@ -6,9 +6,10 @@
import java.io.IOException;
import java.sql.SQLException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.Parameter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.client.util.Parameter;
+import org.mariadb.jdbc.message.ClientMessage;
/**
* COM_STMT_SEND_LONG_DATA
@@ -21,17 +22,17 @@
public final class LongDataPacket implements ClientMessage {
private final int statementId;
- private final Parameter> parameter;
+ private final Parameter parameter;
private final int index;
- public LongDataPacket(int statementId, Parameter> parameter, int index) {
+ public LongDataPacket(int statementId, Parameter parameter, int index) {
this.statementId = statementId;
this.parameter = parameter;
this.index = index;
}
@Override
- public int encode(PacketWriter writer, Context context) throws IOException, SQLException {
+ public int encode(Writer writer, Context context) throws IOException, SQLException {
writer.initPacket();
writer.writeByte(0x18);
writer.writeInt(statementId);
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 216fec2bd..a9c9bbafd 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/PingPacket.java
@@ -5,15 +5,16 @@
package org.mariadb.jdbc.message.client;
import java.io.IOException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.message.ClientMessage;
public final class PingPacket implements ClientMessage {
public static final PingPacket INSTANCE = new PingPacket();
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
writer.initPacket();
writer.writeByte(0x0e);
writer.flush();
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 a97509af2..fdfddf550 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/PreparePacket.java
@@ -10,15 +10,16 @@
import org.mariadb.jdbc.BasePreparedStatement;
import org.mariadb.jdbc.ServerPreparedStatement;
import org.mariadb.jdbc.Statement;
-import org.mariadb.jdbc.client.*;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Completion;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.ReadableByteBuf;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.export.ExceptionFactory;
+import org.mariadb.jdbc.message.ClientMessage;
import org.mariadb.jdbc.message.server.CachedPrepareResultPacket;
-import org.mariadb.jdbc.message.server.Completion;
import org.mariadb.jdbc.message.server.ErrorPacket;
import org.mariadb.jdbc.message.server.PrepareResultPacket;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
public final class PreparePacket implements ClientMessage {
private final String sql;
@@ -28,7 +29,7 @@ public PreparePacket(String sql) {
}
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
writer.initPacket();
writer.writeByte(0x16);
writer.writeString(this.sql);
@@ -44,8 +45,8 @@ public Completion readPacket(
int resultSetConcurrency,
int resultSetType,
boolean closeOnCompletion,
- PacketReader reader,
- PacketWriter writer,
+ Reader reader,
+ Writer writer,
Context context,
ExceptionFactory exceptionFactory,
ReentrantLock lock,
@@ -68,14 +69,17 @@ public Completion readPacket(
if (context.getConf().useServerPrepStmts()
&& context.getConf().cachePrepStmts()
&& sql.length() < 8192) {
- CachedPrepareResultPacket prepare = new CachedPrepareResultPacket(buf, reader, context);
+ PrepareResultPacket prepare = new CachedPrepareResultPacket(buf, reader, context);
PrepareResultPacket previousCached =
- context
- .getPrepareCache()
- .put(
- sql,
- prepare,
- stmt instanceof ServerPreparedStatement ? (ServerPreparedStatement) stmt : null);
+ (PrepareResultPacket)
+ context
+ .getPrepareCache()
+ .put(
+ sql,
+ prepare,
+ stmt instanceof ServerPreparedStatement
+ ? (ServerPreparedStatement) stmt
+ : null);
if (stmt != null) {
((BasePreparedStatement) stmt)
.setPrepareResult(previousCached != null ? previousCached : prepare);
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 f831e4c2f..71091b17e 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/QueryPacket.java
@@ -5,8 +5,8 @@
package org.mariadb.jdbc.message.client;
import java.io.IOException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
public final class QueryPacket implements RedoableClientMessage {
@@ -21,7 +21,7 @@ public int batchUpdateLength() {
}
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
writer.initPacket();
writer.writeByte(0x03);
writer.writeString(this.sql);
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 feac53a88..3eb2fb2e2 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java
@@ -6,21 +6,20 @@
import java.io.IOException;
import java.sql.SQLException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.Parameter;
-import org.mariadb.jdbc.codec.list.ByteArrayCodec;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.client.util.Parameter;
+import org.mariadb.jdbc.client.util.Parameters;
+import org.mariadb.jdbc.plugin.codec.ByteArrayCodec;
import org.mariadb.jdbc.util.ClientParser;
-import org.mariadb.jdbc.util.ParameterList;
public final class QueryWithParametersPacket implements RedoableClientMessage {
private final String preSqlCmd;
private final ClientParser parser;
- private ParameterList parameters;
+ private Parameters parameters;
- public QueryWithParametersPacket(
- String preSqlCmd, ClientParser parser, ParameterList parameters) {
+ public QueryWithParametersPacket(String preSqlCmd, ClientParser parser, Parameters parameters) {
this.preSqlCmd = preSqlCmd;
this.parser = parser;
this.parameters = parameters;
@@ -30,9 +29,10 @@ public QueryWithParametersPacket(
public void ensureReplayable(Context context) throws IOException, SQLException {
int parameterCount = parameters.size();
for (int i = 0; i < parameterCount; i++) {
- Parameter> p = parameters.get(i);
+ Parameter p = parameters.get(i);
if (!p.isNull() && p.canEncodeLongData()) {
- this.parameters.set(i, new Parameter<>(ByteArrayCodec.INSTANCE, p.encodeData()));
+ this.parameters.set(
+ i, new org.mariadb.jdbc.codec.Parameter<>(ByteArrayCodec.INSTANCE, p.encodeData()));
}
}
}
@@ -42,7 +42,7 @@ public void saveParameters() {
}
@Override
- public int encode(PacketWriter encoder, Context context) throws IOException, SQLException {
+ public int encode(Writer encoder, Context context) throws IOException, SQLException {
encoder.initPacket();
encoder.writeByte(0x03);
if (!preSqlCmd.isEmpty()) encoder.writeAscii(preSqlCmd);
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 c4c91ec5e..9c2faf199 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/QuitPacket.java
@@ -5,14 +5,15 @@
package org.mariadb.jdbc.message.client;
import java.io.IOException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.message.ClientMessage;
public final class QuitPacket implements ClientMessage {
public static final QuitPacket INSTANCE = new QuitPacket();
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
writer.initPacket();
writer.writeByte(0x01);
writer.flush();
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 9174ffa28..bb463f48a 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/RedoableClientMessage.java
@@ -6,9 +6,10 @@
import java.io.IOException;
import java.sql.SQLException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.message.server.PrepareResultPacket;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.export.Prepare;
+import org.mariadb.jdbc.message.ClientMessage;
public interface RedoableClientMessage extends ClientMessage {
@@ -16,12 +17,12 @@ default void saveParameters() {}
default void ensureReplayable(Context context) throws IOException, SQLException {}
- default int encode(PacketWriter writer, Context context, PrepareResultPacket newPrepareResult)
+ default int encode(Writer writer, Context context, Prepare newPrepareResult)
throws IOException, SQLException {
return encode(writer, context);
}
- default int reEncode(PacketWriter writer, Context context, PrepareResultPacket newPrepareResult)
+ default int reEncode(Writer writer, Context context, Prepare newPrepareResult)
throws IOException, SQLException {
return encode(writer, context, newPrepareResult);
}
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 03c524e61..15949c02d 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/RedoableWithPrepareClientMessage.java
@@ -9,8 +9,9 @@
import java.sql.SQLException;
import org.mariadb.jdbc.ServerPreparedStatement;
import org.mariadb.jdbc.client.Client;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.export.Prepare;
import org.mariadb.jdbc.message.server.PrepareResultPacket;
public interface RedoableWithPrepareClientMessage extends RedoableClientMessage {
@@ -18,15 +19,15 @@ public interface RedoableWithPrepareClientMessage extends RedoableClientMessage
ServerPreparedStatement prep();
- default int encode(PacketWriter writer, Context context) throws IOException, SQLException {
+ default int encode(Writer writer, Context context) throws IOException, SQLException {
return encode(writer, context, null);
}
- int encode(PacketWriter writer, Context context, PrepareResultPacket newPrepareResult)
+ int encode(Writer writer, Context context, Prepare newPrepareResult)
throws IOException, SQLException;
@Override
- default int reEncode(PacketWriter writer, Context context, PrepareResultPacket newPrepareResult)
+ default int reEncode(Writer writer, Context context, Prepare newPrepareResult)
throws IOException, SQLException {
return encode(writer, context, newPrepareResult);
}
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 8f2f65f5f..23f7d7fee 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/ResetPacket.java
@@ -5,15 +5,16 @@
package org.mariadb.jdbc.message.client;
import java.io.IOException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.message.ClientMessage;
public final class ResetPacket implements ClientMessage {
public static final ResetPacket INSTANCE = new ResetPacket();
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
writer.initPacket();
writer.writeByte(0x1f);
writer.flush();
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 f998b0bba..d906357d5 100644
--- a/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/client/SslRequestPacket.java
@@ -5,8 +5,9 @@
package org.mariadb.jdbc.message.client;
import java.io.IOException;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.message.ClientMessage;
public final class SslRequestPacket implements ClientMessage {
@@ -23,7 +24,7 @@ public static SslRequestPacket create(long clientCapabilities, byte exchangeChar
}
@Override
- public int encode(PacketWriter writer, Context context) throws IOException {
+ public int encode(Writer writer, Context context) throws IOException {
writer.writeInt((int) clientCapabilities);
writer.writeInt(1024 * 1024 * 1024);
writer.writeByte(exchangeCharset); // 1 byte
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 b9a4d6ce7..5873c9bb1 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/AuthSwitchPacket.java
@@ -6,6 +6,7 @@
import java.util.Arrays;
import org.mariadb.jdbc.client.ReadableByteBuf;
+import org.mariadb.jdbc.message.ServerMessage;
public class AuthSwitchPacket implements ServerMessage {
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 8fe2d385c..cfb9ce635 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/CachedPrepareResultPacket.java
@@ -11,9 +11,9 @@
import java.util.concurrent.atomic.AtomicBoolean;
import org.mariadb.jdbc.ServerPreparedStatement;
import org.mariadb.jdbc.client.Client;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
+import org.mariadb.jdbc.client.socket.Reader;
public final class CachedPrepareResultPacket extends PrepareResultPacket {
@@ -21,7 +21,7 @@ public final class CachedPrepareResultPacket extends PrepareResultPacket {
private final AtomicBoolean cached = new AtomicBoolean();
private final List statements = new ArrayList<>();
- public CachedPrepareResultPacket(ReadableByteBuf buffer, PacketReader reader, Context context)
+ public CachedPrepareResultPacket(ReadableByteBuf buffer, Reader reader, Context context)
throws IOException {
super(buffer, reader, context);
}
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 904778066..ac95fc7f5 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java
@@ -8,14 +8,17 @@
import java.sql.Types;
import java.util.Objects;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.codec.list.*;
+import org.mariadb.jdbc.client.impl.StandardReadableByteBuf;
+import org.mariadb.jdbc.message.ServerMessage;
import org.mariadb.jdbc.plugin.Codec;
+import org.mariadb.jdbc.plugin.codec.*;
import org.mariadb.jdbc.util.CharsetEncodingLength;
import org.mariadb.jdbc.util.constants.ColumnFlags;
-public class ColumnDefinitionPacket implements ServerMessage {
+public class ColumnDefinitionPacket implements Column, ServerMessage {
private final ReadableByteBuf buf;
private final int charset;
@@ -122,7 +125,7 @@ public static ColumnDefinitionPacket create(String name, DataType type) {
}
return new ColumnDefinitionPacket(
- new ReadableByteBuf(null, arr, arr.length), len, type, stringPos);
+ new StandardReadableByteBuf(null, arr, arr.length), len, type, stringPos);
}
public String getSchema() {
@@ -145,7 +148,7 @@ public String getColumnAlias() {
return buf.readString(buf.readLengthNotNull());
}
- public String getColumn() {
+ public String getColumnName() {
buf.pos(stringPos[4]);
return buf.readString(buf.readLengthNotNull());
}
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 acb0206a7..74f63e2b9 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/ErrorPacket.java
@@ -4,8 +4,9 @@
package org.mariadb.jdbc.message.server;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
+import org.mariadb.jdbc.message.ServerMessage;
import org.mariadb.jdbc.util.constants.ServerStatus;
import org.mariadb.jdbc.util.log.Logger;
import org.mariadb.jdbc.util.log.Loggers;
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 ced69a967..f69b23954 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/InitialHandshakePacket.java
@@ -6,6 +6,8 @@
import org.mariadb.jdbc.client.ReadableByteBuf;
import org.mariadb.jdbc.client.ServerVersion;
+import org.mariadb.jdbc.message.ServerMessage;
+import org.mariadb.jdbc.message.server.util.ServerVersionUtility;
import org.mariadb.jdbc.util.constants.Capabilities;
public final class InitialHandshakePacket implements ServerMessage {
@@ -36,7 +38,7 @@ private InitialHandshakePacket(
this.defaultCollation = defaultCollation;
this.serverStatus = serverStatus;
this.authenticationPluginType = authenticationPluginType;
- this.version = new ServerVersion(serverVersion, mariaDBServer);
+ this.version = new ServerVersionUtility(serverVersion, mariaDBServer);
}
public static InitialHandshakePacket decode(ReadableByteBuf reader) {
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 37cca6cdc..517221b6b 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/OkPacket.java
@@ -4,8 +4,9 @@
package org.mariadb.jdbc.message.server;
+import org.mariadb.jdbc.client.Completion;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
import org.mariadb.jdbc.util.constants.Capabilities;
import org.mariadb.jdbc.util.constants.StateChange;
import org.mariadb.jdbc.util.log.Logger;
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 f3eb1cfdb..66edaf4b8 100644
--- a/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java
+++ b/src/main/java/org/mariadb/jdbc/message/server/PrepareResultPacket.java
@@ -7,29 +7,33 @@
import java.io.IOException;
import java.sql.SQLException;
import org.mariadb.jdbc.ServerPreparedStatement;
-import org.mariadb.jdbc.client.*;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
+import org.mariadb.jdbc.client.Client;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Completion;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.ReadableByteBuf;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.export.Prepare;
import org.mariadb.jdbc.util.constants.Capabilities;
import org.mariadb.jdbc.util.log.Logger;
import org.mariadb.jdbc.util.log.Loggers;
/** See https://mariadb.com/kb/en/com_stmt_prepare/#COM_STMT_PREPARE_OK */
-public class PrepareResultPacket implements Completion {
+public class PrepareResultPacket implements Completion, Prepare {
private static final Logger logger = Loggers.getLogger(PrepareResultPacket.class);
- private final ColumnDefinitionPacket[] parameters;
- private ColumnDefinitionPacket[] columns;
+ private final Column[] parameters;
+ private Column[] columns;
protected int statementId;
- public PrepareResultPacket(ReadableByteBuf buffer, PacketReader reader, Context context)
+ public PrepareResultPacket(ReadableByteBuf buffer, Reader reader, Context context)
throws IOException {
boolean trace = logger.isTraceEnabled();
buffer.readByte(); /* skip COM_STMT_PREPARE_OK */
this.statementId = buffer.readInt();
final int numColumns = buffer.readUnsignedShort();
final int numParams = buffer.readUnsignedShort();
- this.parameters = new ColumnDefinitionPacket[numParams];
- this.columns = new ColumnDefinitionPacket[numColumns];
+ this.parameters = new Column[numParams];
+ this.columns = new Column[numColumns];
if (numParams > 0) {
for (int i = 0; i < numParams; i++) {
parameters[i] =
@@ -69,15 +73,15 @@ public int getStatementId() {
return statementId;
}
- public ColumnDefinitionPacket[] getParameters() {
+ public Column[] getParameters() {
return parameters;
}
- public ColumnDefinitionPacket[] getColumns() {
+ public Column[] getColumns() {
return columns;
}
- public void setColumns(ColumnDefinitionPacket[] columns) {
+ public void setColumns(Column[] columns) {
this.columns = columns;
}
}
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
new file mode 100644
index 000000000..76f653b95
--- /dev/null
+++ b/src/main/java/org/mariadb/jdbc/message/server/util/ServerVersionUtility.java
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (c) 2012-2014 Monty Program Ab
+// Copyright (c) 2015-2021 MariaDB Corporation Ab
+
+package org.mariadb.jdbc.message.server.util;
+
+import org.mariadb.jdbc.client.ServerVersion;
+import org.mariadb.jdbc.util.Version;
+
+public final class ServerVersionUtility extends Version implements ServerVersion {
+
+ private final boolean mariaDBServer;
+
+ public ServerVersionUtility(String serverVersion, boolean mariaDBServer) {
+ super(serverVersion);
+ this.mariaDBServer = mariaDBServer;
+ }
+
+ public boolean isMariaDBServer() {
+ return mariaDBServer;
+ }
+}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java
index 3571a8739..aff2713fa 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/AuthenticationPlugin.java
@@ -7,10 +7,10 @@
import java.io.IOException;
import java.sql.SQLException;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
public interface AuthenticationPlugin {
@@ -40,6 +40,6 @@ public interface AuthenticationPlugin {
* @throws IOException if socket error
* @throws SQLException if plugin exception
*/
- ReadableByteBuf process(PacketWriter encoder, PacketReader decoder, Context context)
+ ReadableByteBuf process(Writer encoder, Reader decoder, Context context)
throws IOException, SQLException;
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/Codec.java b/src/main/java/org/mariadb/jdbc/plugin/Codec.java
index 85ec32731..6f1a28699 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/Codec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/Codec.java
@@ -8,44 +8,38 @@
import java.sql.SQLDataException;
import java.sql.SQLException;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
public interface Codec {
String className();
- boolean canDecode(ColumnDefinitionPacket column, Class> type);
+ boolean canDecode(Column column, Class> type);
boolean canEncode(Object value);
T decodeText(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException;
T decodeBinary(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException;
- void encodeText(PacketWriter encoder, Context context, Object value, Calendar cal, Long length)
+ void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long length)
throws IOException, SQLException;
- void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long length)
+ void encodeBinary(Writer encoder, Object value, Calendar cal, Long length)
throws IOException, SQLException;
default boolean canEncodeLongData() {
return false;
}
- default void encodeLongData(PacketWriter encoder, T value, Long length)
+ default void encodeLongData(Writer encoder, T value, Long length)
throws IOException, SQLException {
throw new SQLException("Data is not supposed to be send in COM_STMT_LONG_DATA");
}
diff --git a/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java b/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java
index 336884bb1..47dc4bcdc 100644
--- a/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/TlsSocketPlugin.java
@@ -12,7 +12,7 @@
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import org.mariadb.jdbc.Configuration;
-import org.mariadb.jdbc.util.exceptions.ExceptionFactory;
+import org.mariadb.jdbc.export.ExceptionFactory;
public interface TlsSocketPlugin {
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 873387236..1f015c61b 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
@@ -7,10 +7,10 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.AuthenticationPlugin;
public class ClearPasswordPlugin implements AuthenticationPlugin {
@@ -37,8 +37,7 @@ public void initialize(String authenticationData, byte[] authData, Configuration
* @return response packet
* @throws IOException if socket error
*/
- public ReadableByteBuf process(PacketWriter out, PacketReader in, Context context)
- throws IOException {
+ public ReadableByteBuf process(Writer out, Reader in, Context context) throws IOException {
if (authenticationData == null) {
out.writeEmptyPacket();
} else {
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 492817c48..b64ee368c 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
@@ -7,10 +7,11 @@
import java.io.IOException;
import java.sql.SQLException;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.impl.StandardReadableByteBuf;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.AuthenticationPlugin;
import org.mariadb.jdbc.plugin.authentication.addon.gssapi.GssUtility;
import org.mariadb.jdbc.plugin.authentication.addon.gssapi.GssapiAuth;
@@ -61,9 +62,9 @@ public void initialize(String authenticationData, byte[] seed, Configuration con
* @throws IOException if socket error
* @throws SQLException if plugin exception
*/
- public ReadableByteBuf process(PacketWriter out, PacketReader in, Context context)
+ public ReadableByteBuf process(Writer out, Reader in, Context context)
throws IOException, SQLException {
- ReadableByteBuf buf = new ReadableByteBuf(in.getSequence(), seed, seed.length);
+ ReadableByteBuf buf = new StandardReadableByteBuf(in.getSequence(), seed, seed.length);
final String serverSpn = buf.readStringNullEnd();
// using provided connection string SPN if set, or if not, using to server information
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 fe585e449..664145bca 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
@@ -6,12 +6,11 @@
import java.io.IOException;
import java.sql.SQLException;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
public interface GssapiAuth {
- void authenticate(
- PacketWriter writer, PacketReader in, String servicePrincipalName, String mechanisms)
+ void authenticate(Writer writer, Reader in, String servicePrincipalName, String mechanisms)
throws SQLException, 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 c74b03ad3..67e0e1189 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
@@ -13,8 +13,8 @@
import javax.security.auth.login.LoginException;
import org.ietf.jgss.*;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
public class StandardGssapiAuthentication implements GssapiAuth {
@@ -29,10 +29,7 @@ public class StandardGssapiAuthentication implements GssapiAuth {
* @throws SQLException in any Exception occur
*/
public void authenticate(
- final PacketWriter out,
- final PacketReader in,
- final String servicePrincipalName,
- String mechanisms)
+ final Writer out, final Reader in, final String servicePrincipalName, String mechanisms)
throws SQLException, IOException {
if ("".equals(servicePrincipalName)) {
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 be9ca7e72..c2b4f4225 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
@@ -8,8 +8,8 @@
import com.sun.jna.platform.win32.SspiUtil;
import java.io.IOException;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
import waffle.windows.auth.IWindowsSecurityContext;
import waffle.windows.auth.impl.WindowsSecurityContextImpl;
@@ -25,10 +25,7 @@ public class WindowsNativeSspiAuthentication implements GssapiAuth {
* @throws IOException if socket error
*/
public void authenticate(
- final PacketWriter out,
- final PacketReader in,
- final String servicePrincipalName,
- final String mechanisms)
+ final Writer out, final Reader in, final String servicePrincipalName, final String mechanisms)
throws IOException {
// initialize a security context on the client
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 06e794de3..d32ed97e6 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
@@ -18,11 +18,11 @@
import java.util.Base64;
import javax.crypto.Cipher;
import org.mariadb.jdbc.Configuration;
-import org.mariadb.jdbc.SslMode;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
+import org.mariadb.jdbc.export.SslMode;
import org.mariadb.jdbc.message.client.AuthMoreRawPacket;
import org.mariadb.jdbc.message.server.AuthSwitchPacket;
import org.mariadb.jdbc.plugin.AuthenticationPlugin;
@@ -98,7 +98,7 @@ public void initialize(String authenticationData, byte[] seed, Configuration con
* @return response packet
* @throws IOException if socket error
*/
- public ReadableByteBuf process(PacketWriter out, PacketReader in, Context context)
+ public ReadableByteBuf process(Writer out, Reader in, Context context)
throws IOException, SQLException {
byte[] fastCryptPwd = sha256encryptPassword(authenticationData, seed);
new AuthMoreRawPacket(fastCryptPwd).encode(out, context);
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 8d8a5a376..7d742ab8c 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
@@ -11,10 +11,10 @@
import java.sql.SQLException;
import java.util.Arrays;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.AuthenticationPlugin;
import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.GroupElement;
import org.mariadb.jdbc.plugin.authentication.standard.ed25519.math.ed25519.Ed25519ScalarOps;
@@ -101,7 +101,7 @@ public void initialize(String authenticationData, byte[] seed, Configuration con
* @return response packet
* @throws IOException if socket error
*/
- public ReadableByteBuf process(PacketWriter out, PacketReader in, Context context)
+ public ReadableByteBuf process(Writer out, Reader in, Context context)
throws SQLException, IOException {
if (authenticationData == null) {
out.writeEmptyPacket();
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 bab5278b6..5b0f1b75e 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
@@ -9,10 +9,10 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.message.server.AuthSwitchPacket;
import org.mariadb.jdbc.plugin.AuthenticationPlugin;
@@ -97,8 +97,7 @@ public void initialize(String authenticationData, byte[] seed, Configuration con
* @return response packet
* @throws IOException if socket error
*/
- public ReadableByteBuf process(PacketWriter out, PacketReader in, Context context)
- throws IOException {
+ public ReadableByteBuf process(Writer out, Reader in, Context context) throws IOException {
if (authenticationData == null) {
out.writeEmptyPacket();
} else {
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 9eb15e8d2..f70a5d215 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
@@ -8,10 +8,10 @@
import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import org.mariadb.jdbc.Configuration;
+import org.mariadb.jdbc.client.Context;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketReader;
-import org.mariadb.jdbc.client.socket.PacketWriter;
+import org.mariadb.jdbc.client.socket.Reader;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.AuthenticationPlugin;
public class SendPamAuthPacket implements AuthenticationPlugin {
@@ -47,7 +47,7 @@ public void initialize(String authenticationData, byte[] seed, Configuration con
* @return response packet
* @throws IOException if socket error
*/
- public ReadableByteBuf process(PacketWriter out, PacketReader in, Context context)
+ public ReadableByteBuf process(Writer out, Reader in, Context context)
throws SQLException, IOException {
while (true) {
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/BigDecimalCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java
similarity index 87%
rename from src/main/java/org/mariadb/jdbc/codec/list/BigDecimalCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java
index bd887886a..81d8f1ae9 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/BigDecimalCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BigDecimalCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
@@ -11,11 +11,11 @@
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class BigDecimalCodec implements Codec {
@@ -46,7 +46,7 @@ public String className() {
return BigDecimal.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(BigDecimal.class);
}
@@ -56,8 +56,7 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public BigDecimal decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public BigDecimal decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
case TINYINT:
@@ -112,8 +111,7 @@ public BigDecimal decodeText(
@Override
@SuppressWarnings("fallthrough")
- public BigDecimal decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public BigDecimal decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
@@ -195,7 +193,7 @@ public BigDecimal decodeBinary(
}
}
- static BigInteger getBigInteger(ReadableByteBuf buf, ColumnDefinitionPacket column) {
+ static BigInteger getBigInteger(ReadableByteBuf buf, Column column) {
BigInteger val;
if (column.isSigned()) {
val = BigInteger.valueOf(buf.readLong());
@@ -211,14 +209,13 @@ static BigInteger getBigInteger(ReadableByteBuf buf, ColumnDefinitionPacket colu
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long length)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long length)
throws IOException {
encoder.writeAscii(((BigDecimal) value).toPlainString());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
String asciiFormat = ((BigDecimal) value).toPlainString();
encoder.writeLength(asciiFormat.length());
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/BigIntegerCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java
similarity index 88%
rename from src/main/java/org/mariadb/jdbc/codec/list/BigIntegerCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java
index 9276dd8d8..24e65f226 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/BigIntegerCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BigIntegerCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
@@ -10,11 +10,11 @@
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class BigIntegerCodec implements Codec {
@@ -45,7 +45,7 @@ public String className() {
return BigInteger.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(BigInteger.class);
}
@@ -55,8 +55,7 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public BigInteger decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public BigInteger decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
@@ -114,8 +113,7 @@ public BigInteger decodeText(
@Override
@SuppressWarnings("fallthrough")
- public BigInteger decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public BigInteger decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
@@ -203,14 +201,13 @@ public BigInteger decodeBinary(
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long length)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long length)
throws IOException {
encoder.writeAscii(value.toString());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
String asciiFormat = value.toString();
encoder.writeLength(asciiFormat.length());
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/BitSetCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java
similarity index 71%
rename from src/main/java/org/mariadb/jdbc/codec/list/BitSetCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java
index 6a3000188..df3934655 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/BitSetCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BitSetCodec.java
@@ -2,16 +2,16 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.util.BitSet;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class BitSetCodec implements Codec {
@@ -42,19 +42,17 @@ public String className() {
return BitSet.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return column.getType() == DataType.BIT && type.isAssignableFrom(BitSet.class);
}
@Override
- public BitSet decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal) {
+ public BitSet decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal) {
return parseBit(buf, length);
}
@Override
- public BitSet decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal) {
+ public BitSet decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal) {
return parseBit(buf, length);
}
@@ -63,8 +61,7 @@ public boolean canEncode(Object value) {
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long length)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long length)
throws IOException {
byte[] bytes = ((BitSet) value).toByteArray();
revertOrder(bytes);
@@ -78,7 +75,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
byte[] bytes = ((BitSet) value).toByteArray();
revertOrder(bytes);
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/BlobCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java
similarity index 88%
rename from src/main/java/org/mariadb/jdbc/codec/list/BlobCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java
index 2e073a7d2..5af34b5c5 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/BlobCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BlobCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -14,11 +14,11 @@
import java.util.Calendar;
import java.util.EnumSet;
import org.mariadb.jdbc.MariaDbBlob;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.util.constants.ServerStatus;
@@ -41,7 +41,7 @@ public String className() {
return Blob.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(Blob.class);
}
@@ -51,8 +51,7 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public Blob decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Blob decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
case STRING:
@@ -87,8 +86,7 @@ public Blob decodeText(
@Override
@SuppressWarnings("fallthrough")
- public Blob decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Blob decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
case STRING:
@@ -124,7 +122,7 @@ public Blob decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException, SQLException {
encoder.writeBytes(ByteArrayCodec.BINARY_PREFIX);
byte[] array = new byte[4096];
@@ -150,7 +148,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException, SQLException {
long length;
InputStream is = ((Blob) value).getBinaryStream();
@@ -177,7 +175,7 @@ public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long
}
@Override
- public void encodeLongData(PacketWriter encoder, Blob value, Long maxLength)
+ public void encodeLongData(Writer encoder, Blob value, Long maxLength)
throws IOException, SQLException {
byte[] array = new byte[4096];
InputStream is = value.getBinaryStream();
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/BooleanCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java
similarity index 84%
rename from src/main/java/org/mariadb/jdbc/codec/list/BooleanCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java
index cd739dc6c..7916060ad 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/BooleanCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/BooleanCodec.java
@@ -2,18 +2,18 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class BooleanCodec implements Codec {
@@ -45,7 +45,7 @@ public String className() {
return Boolean.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& ((type.isPrimitive() && type == Boolean.TYPE) || type.isAssignableFrom(Boolean.class));
}
@@ -55,16 +55,13 @@ public boolean canEncode(Object value) {
}
public Boolean decodeText(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeTextBoolean(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public boolean decodeTextBoolean(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public boolean decodeTextBoolean(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
switch (column.getType()) {
case BIT:
@@ -108,16 +105,13 @@ public boolean decodeTextBoolean(ReadableByteBuf buf, int length, ColumnDefiniti
}
public Boolean decodeBinary(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeBinaryBoolean(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public boolean decodeBinaryBoolean(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public boolean decodeBinaryBoolean(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
switch (column.getType()) {
case BIT:
@@ -172,13 +166,13 @@ public boolean decodeBinaryBoolean(ReadableByteBuf buf, int length, ColumnDefini
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeAscii(((Boolean) value) ? "1" : "0");
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeByte(((Boolean) value) ? 1 : 0);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/ByteArrayCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java
similarity index 77%
rename from src/main/java/org/mariadb/jdbc/codec/list/ByteArrayCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java
index 01114790a..19d8831f5 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/ByteArrayCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteArrayCodec.java
@@ -2,17 +2,17 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.util.constants.ServerStatus;
@@ -38,7 +38,7 @@ public String className() {
return byte[].class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& ((type.isPrimitive() && type == Byte.TYPE && type.isArray())
|| type.isAssignableFrom(byte[].class));
@@ -49,14 +49,12 @@ public boolean canEncode(Object value) {
}
@Override
- public byte[] decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public byte[] decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return getBytes(buf, length, column);
}
- private byte[] getBytes(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
- throws SQLDataException {
+ private byte[] getBytes(ReadableByteBuf buf, int length, Column column) throws SQLDataException {
switch (column.getType()) {
case BLOB:
case TINYBLOB:
@@ -78,15 +76,14 @@ private byte[] getBytes(ReadableByteBuf buf, int length, ColumnDefinitionPacket
}
@Override
- public byte[] decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public byte[] decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return getBytes(buf, length, column);
}
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
int length = ((byte[]) value).length;
@@ -99,7 +96,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
int length = ((byte[]) value).length;
if (maxLength != null) length = Math.min(length, maxLength.intValue());
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/ByteCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java
similarity index 90%
rename from src/main/java/org/mariadb/jdbc/codec/list/ByteCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java
index 1d017d6d0..5c8141695 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/ByteCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ByteCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
@@ -11,11 +11,11 @@
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class ByteCodec implements Codec {
@@ -61,7 +61,7 @@ public String className() {
return Byte.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& ((type.isPrimitive() && type == Byte.TYPE) || type.isAssignableFrom(Byte.class));
}
@@ -72,15 +72,12 @@ public boolean canEncode(Object value) {
@Override
public Byte decodeText(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeTextByte(buffer, length, column);
}
- public byte decodeTextByte(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public byte decodeTextByte(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
long result;
@@ -152,15 +149,12 @@ public byte decodeTextByte(ReadableByteBuf buf, int length, ColumnDefinitionPack
@Override
public Byte decodeBinary(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeBinaryByte(buffer, length, column);
}
- public byte decodeBinaryByte(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public byte decodeBinaryByte(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
long result;
@@ -267,13 +261,13 @@ public byte decodeBinaryByte(ReadableByteBuf buf, int length, ColumnDefinitionPa
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeAscii(Integer.toString((Byte) value));
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeByte((byte) value);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/ClobCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java
similarity index 84%
rename from src/main/java/org/mariadb/jdbc/codec/list/ClobCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java
index 16ba90790..3b086eb58 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/ClobCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ClobCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -12,11 +12,11 @@
import java.util.Calendar;
import java.util.EnumSet;
import org.mariadb.jdbc.MariaDbClob;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.util.constants.ServerStatus;
@@ -38,7 +38,7 @@ public String className() {
return Clob.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& (type.isAssignableFrom(Clob.class) || type.isAssignableFrom(NClob.class));
}
@@ -48,15 +48,13 @@ public boolean canEncode(Object value) {
}
@Override
- public Clob decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Clob decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return getClob(buf, length, column);
}
@SuppressWarnings("fallthrough")
- private Clob getClob(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
- throws SQLDataException {
+ private Clob getClob(ReadableByteBuf buf, int length, Column column) throws SQLDataException {
switch (column.getType()) {
case BLOB:
case TINYBLOB:
@@ -85,15 +83,14 @@ private Clob getClob(ReadableByteBuf buf, int length, ColumnDefinitionPacket col
}
@Override
- public Clob decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Clob decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return getClob(buf, length, column);
}
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException, SQLException {
Reader reader = ((Clob) value).getCharacterStream();
char[] buf = new char[4096];
@@ -111,7 +108,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException, SQLException {
// prefer use of encodeLongData, because length is unknown
Reader reader = ((Clob) value).getCharacterStream();
@@ -137,7 +134,7 @@ public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long
}
@Override
- public void encodeLongData(PacketWriter encoder, Clob value, Long maxLength)
+ public void encodeLongData(Writer encoder, Clob value, Long maxLength)
throws IOException, SQLException {
Reader reader = value.getCharacterStream();
char[] buf = new char[4096];
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/DateCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java
similarity index 88%
rename from src/main/java/org/mariadb/jdbc/codec/list/DateCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java
index b7e455a67..582c1cc84 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/DateCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DateCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.Date;
@@ -11,11 +11,11 @@
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class DateCodec implements Codec {
@@ -41,7 +41,7 @@ public String className() {
return Date.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(Date.class);
}
@@ -51,8 +51,7 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public Date decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Date decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
@@ -107,7 +106,7 @@ public Date decodeText(
}
}
- private Date getDate(ColumnDefinitionPacket column, Calendar cal, String val, String[] stDatePart)
+ private Date getDate(Column column, Calendar cal, String val, String[] stDatePart)
throws SQLDataException {
try {
int year = Integer.parseInt(stDatePart[0]);
@@ -130,8 +129,7 @@ private Date getDate(ColumnDefinitionPacket column, Calendar cal, String val, St
@Override
@SuppressWarnings("fallthrough")
- public Date decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Date decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
@@ -199,7 +197,7 @@ public Date decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object val, Calendar providedCal, Long maxLen)
+ Writer encoder, Context context, Object val, Calendar providedCal, Long maxLen)
throws IOException {
Calendar cal = providedCal == null ? Calendar.getInstance() : providedCal;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -212,7 +210,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar providedCal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar providedCal, Long maxLength)
throws IOException {
Calendar cal = providedCal == null ? Calendar.getInstance() : providedCal;
cal.setTimeInMillis(((Date) value).getTime());
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/DoubleCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java
similarity index 87%
rename from src/main/java/org/mariadb/jdbc/codec/list/DoubleCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java
index a5941939a..a2c93a71c 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/DoubleCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DoubleCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
@@ -10,11 +10,11 @@
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class DoubleCodec implements Codec {
@@ -45,7 +45,7 @@ public String className() {
return Double.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& ((type.isPrimitive() && type == Double.TYPE) || type.isAssignableFrom(Double.class));
}
@@ -56,14 +56,13 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public Double decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Double decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeTextDouble(buf, length, column);
}
@SuppressWarnings("fallthrough")
- public double decodeTextDouble(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public double decodeTextDouble(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
switch (column.getType()) {
case TINYINT:
@@ -109,14 +108,13 @@ public double decodeTextDouble(ReadableByteBuf buf, int length, ColumnDefinition
@Override
@SuppressWarnings("fallthrough")
- public Double decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Double decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeBinaryDouble(buf, length, column);
}
@SuppressWarnings("fallthrough")
- public double decodeBinaryDouble(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public double decodeBinaryDouble(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
switch (column.getType()) {
case TINYINT:
@@ -196,14 +194,13 @@ public double decodeBinaryDouble(ReadableByteBuf buf, int length, ColumnDefiniti
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
encoder.writeAscii(value.toString());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeDouble((Double) value);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/DurationCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java
similarity index 87%
rename from src/main/java/org/mariadb/jdbc/codec/list/DurationCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java
index c5edf2085..970d49005 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/DurationCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/DurationCodec.java
@@ -2,18 +2,18 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.time.Duration;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class DurationCodec implements Codec {
@@ -37,7 +37,7 @@ public String className() {
return Duration.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(Duration.class);
}
@@ -47,8 +47,7 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public Duration decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Duration decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
int[] parts;
@@ -99,8 +98,7 @@ public Duration decodeText(
@Override
@SuppressWarnings("fallthrough")
- public Duration decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Duration decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
long days = 0;
@@ -179,8 +177,7 @@ public Duration decodeBinary(
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object val, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object val, Calendar cal, Long maxLen)
throws IOException {
long s = ((Duration) val).getSeconds();
long microSecond = ((Duration) val).getNano() / 1000;
@@ -195,7 +192,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object val, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object val, Calendar cal, Long maxLength)
throws IOException {
int nano = ((Duration) val).getNano();
if (nano > 0) {
@@ -208,7 +205,7 @@ public void encodeBinary(PacketWriter encoder, Object val, Calendar cal, Long ma
}
}
- private void encodeDuration(PacketWriter encoder, Duration value) throws IOException {
+ private void encodeDuration(Writer encoder, Duration value) throws IOException {
encoder.writeByte((byte) (value.isNegative() ? 1 : 0));
encoder.writeInt((int) value.toDays());
encoder.writeByte((byte) (value.toHours() - 24 * value.toDays()));
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/FloatCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java
similarity index 86%
rename from src/main/java/org/mariadb/jdbc/codec/list/FloatCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java
index ca6f703f6..8707683c9 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/FloatCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/FloatCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
@@ -10,11 +10,11 @@
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class FloatCodec implements Codec {
@@ -45,7 +45,7 @@ public String className() {
return Float.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& ((type.isPrimitive() && type == Float.TYPE) || type.isAssignableFrom(Float.class));
}
@@ -56,16 +56,13 @@ public boolean canEncode(Object value) {
@Override
public Float decodeText(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeTextFloat(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public float decodeTextFloat(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public float decodeTextFloat(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
switch (column.getType()) {
case TINYINT:
@@ -111,16 +108,13 @@ public float decodeTextFloat(ReadableByteBuf buf, int length, ColumnDefinitionPa
@Override
public Float decodeBinary(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeBinaryFloat(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public float decodeBinaryFloat(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public float decodeBinaryFloat(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
switch (column.getType()) {
case TINYINT:
@@ -199,14 +193,13 @@ public float decodeBinaryFloat(ReadableByteBuf buf, int length, ColumnDefinition
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
encoder.writeAscii(value.toString());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeFloat((Float) value);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/GeometryCollectionCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java
similarity index 89%
rename from src/main/java/org/mariadb/jdbc/codec/list/GeometryCollectionCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java
index 781894f7e..5dd5f72f9 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/GeometryCollectionCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/GeometryCollectionCodec.java
@@ -2,16 +2,16 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.type.*;
@@ -23,7 +23,7 @@ public String className() {
return GeometryCollection.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return column.getType() == DataType.GEOMETRY && type.isAssignableFrom(GeometryCollection.class);
}
@@ -32,16 +32,14 @@ public boolean canEncode(Object value) {
}
@Override
- public GeometryCollection decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public GeometryCollection decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeBinary(buf, length, column, cal);
}
@Override
public GeometryCollection decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
- throws SQLDataException {
+ ReadableByteBuf buf, int length, Column column, Calendar cal) throws SQLDataException {
if (column.getType() == DataType.GEOMETRY) {
buf.skip(4); // SRID
Geometry geo = Geometry.getGeometry(buf, length - 4, column);
@@ -58,13 +56,13 @@ public GeometryCollection decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeBytes(("ST_GeomCollFromText('" + value.toString() + "')").getBytes());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
GeometryCollection geometryCollection = (GeometryCollection) value;
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/IntCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java
similarity index 87%
rename from src/main/java/org/mariadb/jdbc/codec/list/IntCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java
index 44e829e59..2cce1acb5 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/IntCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/IntCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
@@ -11,11 +11,11 @@
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class IntCodec implements Codec {
@@ -48,7 +48,7 @@ public String className() {
return Integer.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& ((type.isPrimitive() && type == Integer.TYPE) || type.isAssignableFrom(Integer.class));
}
@@ -59,17 +59,13 @@ public boolean canEncode(Object value) {
@Override
public Integer decodeText(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeTextInt(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public int decodeTextInt(
- final ReadableByteBuf buf, final int length, final ColumnDefinitionPacket column)
+ public int decodeTextInt(final ReadableByteBuf buf, final int length, final Column column)
throws SQLDataException {
long result;
switch (column.getType()) {
@@ -141,16 +137,13 @@ public int decodeTextInt(
@Override
public Integer decodeBinary(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeBinaryInt(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public int decodeBinaryInt(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public int decodeBinaryInt(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
long result;
switch (column.getType()) {
@@ -249,14 +242,13 @@ public int decodeBinaryInt(ReadableByteBuf buf, int length, ColumnDefinitionPack
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
encoder.writeAscii(value.toString());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeInt((Integer) value);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/LineStringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java
similarity index 73%
rename from src/main/java/org/mariadb/jdbc/codec/list/LineStringCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java
index cc87597b5..9811b0fc3 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/LineStringCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LineStringCodec.java
@@ -2,16 +2,16 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.type.*;
@@ -23,7 +23,7 @@ public String className() {
return LineString.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return column.getType() == DataType.GEOMETRY && type.isAssignableFrom(LineString.class);
}
@@ -32,15 +32,13 @@ public boolean canEncode(Object value) {
}
@Override
- public LineString decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public LineString decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeBinary(buf, length, column, cal);
}
@Override
- public LineString decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public LineString decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
if (column.getType() == DataType.GEOMETRY) {
buf.skip(4); // SRID
@@ -57,13 +55,13 @@ public LineString decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeBytes(("ST_LineFromText('" + value.toString() + "')").getBytes());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
LineString line = (LineString) value;
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/LocalDateCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java
similarity index 90%
rename from src/main/java/org/mariadb/jdbc/codec/list/LocalDateCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java
index 6e1360387..cbc1bfbef 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/LocalDateCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
@@ -11,11 +11,11 @@
import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class LocalDateCodec implements Codec {
@@ -61,7 +61,7 @@ public String className() {
return LocalDate.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(LocalDate.class);
}
@@ -71,8 +71,7 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public LocalDate decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public LocalDate decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
int[] parts;
@@ -144,8 +143,7 @@ public LocalDate decodeText(
@Override
@SuppressWarnings("fallthrough")
- public LocalDate decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public LocalDate decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
int year;
@@ -226,8 +224,7 @@ public LocalDate decodeBinary(
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object val, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object val, Calendar cal, Long maxLen)
throws IOException {
encoder.writeByte('\'');
encoder.writeAscii(((LocalDate) val).format(DateTimeFormatter.ISO_LOCAL_DATE));
@@ -235,7 +232,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar providedCal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar providedCal, Long maxLength)
throws IOException {
LocalDate val = (LocalDate) value;
encoder.writeByte(7); // length
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/LocalDateTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java
similarity index 92%
rename from src/main/java/org/mariadb/jdbc/codec/list/LocalDateTimeCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java
index e20859b65..cb9aa751e 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/LocalDateTimeCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalDateTimeCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
@@ -13,11 +13,11 @@
import java.time.temporal.ChronoField;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class LocalDateTimeCodec implements Codec {
@@ -96,7 +96,7 @@ public String className() {
return LocalDateTime.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& type.isAssignableFrom(LocalDateTime.class);
}
@@ -107,8 +107,7 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public LocalDateTime decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public LocalDateTime decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
int[] parts;
switch (column.getType()) {
@@ -169,8 +168,7 @@ public LocalDateTime decodeText(
@Override
@SuppressWarnings("fallthrough")
- public LocalDateTime decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public LocalDateTime decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
int year = 1970;
int month = 1;
@@ -253,8 +251,7 @@ public LocalDateTime decodeBinary(
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
LocalDateTime val = (LocalDateTime) value;
encoder.writeByte('\'');
@@ -264,7 +261,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
LocalDateTime val = (LocalDateTime) value;
int nano = val.getNano();
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/LocalTimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java
similarity index 91%
rename from src/main/java/org/mariadb/jdbc/codec/list/LocalTimeCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java
index 2998a7825..96028694b 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/LocalTimeCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LocalTimeCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
@@ -14,11 +14,11 @@
import java.util.Calendar;
import java.util.EnumSet;
import java.util.TimeZone;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class LocalTimeCodec implements Codec {
@@ -38,7 +38,7 @@ public class LocalTimeCodec implements Codec {
DataType.MEDIUMBLOB,
DataType.LONGBLOB);
- public static int[] parseTime(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public static int[] parseTime(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
int initialPos = buf.pos();
int[] parts = new int[5];
@@ -90,7 +90,7 @@ public String className() {
return LocalTime.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(LocalTime.class);
}
@@ -100,8 +100,7 @@ public boolean canEncode(Object value) {
@Override
@SuppressWarnings("fallthrough")
- public LocalTime decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public LocalTime decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
int[] parts;
@@ -162,8 +161,7 @@ public LocalTime decodeText(
@Override
@SuppressWarnings("fallthrough")
- public LocalTime decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public LocalTime decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
int hour = 0;
@@ -245,8 +243,7 @@ public LocalTime decodeBinary(
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
LocalTime val = (LocalTime) value;
StringBuilder dateString = new StringBuilder(15);
@@ -274,7 +271,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
LocalTime val = (LocalTime) value;
int nano = val.getNano();
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/LongCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java
similarity index 89%
rename from src/main/java/org/mariadb/jdbc/codec/list/LongCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java
index 46bd2b5ea..7a8603f6a 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/LongCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/LongCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
@@ -11,11 +11,11 @@
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class LongCodec implements Codec {
@@ -68,7 +68,7 @@ public String className() {
return Long.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& ((type.isPrimitive() && type == Integer.TYPE) || type.isAssignableFrom(Long.class));
}
@@ -79,16 +79,13 @@ public boolean canEncode(Object value) {
@Override
public Long decodeText(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeTextLong(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public long decodeTextLong(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public long decodeTextLong(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
long result;
switch (column.getType()) {
@@ -160,16 +157,13 @@ public long decodeTextLong(ReadableByteBuf buf, int length, ColumnDefinitionPack
@Override
public Long decodeBinary(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeBinaryLong(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public long decodeBinaryLong(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public long decodeBinaryLong(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
switch (column.getType()) {
@@ -260,14 +254,13 @@ public long decodeBinaryLong(ReadableByteBuf buf, int length, ColumnDefinitionPa
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
encoder.writeAscii(value.toString());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeLong((Long) value);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/MultiLinestringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java
similarity index 77%
rename from src/main/java/org/mariadb/jdbc/codec/list/MultiLinestringCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java
index 937993b5c..e9620b3b4 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/MultiLinestringCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiLinestringCodec.java
@@ -2,16 +2,16 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.type.Geometry;
import org.mariadb.jdbc.type.LineString;
@@ -26,7 +26,7 @@ public String className() {
return MultiLineString.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return column.getType() == DataType.GEOMETRY && type.isAssignableFrom(MultiLineString.class);
}
@@ -35,15 +35,13 @@ public boolean canEncode(Object value) {
}
@Override
- public MultiLineString decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public MultiLineString decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeBinary(buf, length, column, cal);
}
@Override
- public MultiLineString decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public MultiLineString decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
if (column.getType() == DataType.GEOMETRY) {
buf.skip(4); // SRID
@@ -60,13 +58,13 @@ public MultiLineString decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeBytes(("ST_MLineFromText('" + value.toString() + "')").getBytes());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
MultiLineString mp = (MultiLineString) value;
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/MultiPointCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java
similarity index 75%
rename from src/main/java/org/mariadb/jdbc/codec/list/MultiPointCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java
index c9e78477b..2ee3bd932 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/MultiPointCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPointCodec.java
@@ -2,16 +2,16 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.type.Geometry;
import org.mariadb.jdbc.type.MultiPoint;
@@ -25,7 +25,7 @@ public String className() {
return MultiPoint.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return column.getType() == DataType.GEOMETRY && type.isAssignableFrom(MultiPoint.class);
}
@@ -34,15 +34,13 @@ public boolean canEncode(Object value) {
}
@Override
- public MultiPoint decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public MultiPoint decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeBinary(buf, length, column, cal);
}
@Override
- public MultiPoint decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public MultiPoint decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
if (column.getType() == DataType.GEOMETRY) {
buf.skip(4); // SRID
@@ -59,13 +57,13 @@ public MultiPoint decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeBytes(("ST_MPointFromText('" + value.toString() + "')").getBytes());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
MultiPoint mp = (MultiPoint) value;
encoder.writeLength(13 + mp.getPoints().length * 21L);
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/MultiPolygonCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java
similarity index 78%
rename from src/main/java/org/mariadb/jdbc/codec/list/MultiPolygonCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java
index ff883c149..3777cae08 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/MultiPolygonCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/MultiPolygonCodec.java
@@ -2,16 +2,16 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.type.*;
@@ -23,7 +23,7 @@ public String className() {
return MultiPolygon.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return column.getType() == DataType.GEOMETRY && type.isAssignableFrom(MultiPolygon.class);
}
@@ -32,15 +32,13 @@ public boolean canEncode(Object value) {
}
@Override
- public MultiPolygon decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public MultiPolygon decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeBinary(buf, length, column, cal);
}
@Override
- public MultiPolygon decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public MultiPolygon decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
if (column.getType() == DataType.GEOMETRY) {
buf.skip(4); // SRID
@@ -57,13 +55,13 @@ public MultiPolygon decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeBytes(("ST_MPolyFromText('" + value.toString() + "')").getBytes());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
MultiPolygon mariadbMultiPolygon = (MultiPolygon) value;
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/PointCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java
similarity index 72%
rename from src/main/java/org/mariadb/jdbc/codec/list/PointCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java
index 0af4a0872..18d2e6e12 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/PointCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/PointCodec.java
@@ -2,16 +2,16 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.type.*;
@@ -23,7 +23,7 @@ public String className() {
return Point.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return column.getType() == DataType.GEOMETRY && type.isAssignableFrom(Point.class);
}
@@ -32,15 +32,13 @@ public boolean canEncode(Object value) {
}
@Override
- public Point decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Point decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeBinary(buf, length, column, cal);
}
@Override
- public Point decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Point decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
if (column.getType() == DataType.GEOMETRY) {
buf.skip(4); // SRID
@@ -56,13 +54,13 @@ public Point decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeBytes(("ST_PointFromText('" + value.toString() + "')").getBytes());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
Point pt = (Point) value;
encoder.writeLength(25);
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/PolygonCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java
similarity index 76%
rename from src/main/java/org/mariadb/jdbc/codec/list/PolygonCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java
index e0a0c8a2f..70360098d 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/PolygonCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/PolygonCodec.java
@@ -2,16 +2,16 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
import java.util.Calendar;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.type.Geometry;
import org.mariadb.jdbc.type.LineString;
@@ -26,7 +26,7 @@ public String className() {
return Polygon.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return column.getType() == DataType.GEOMETRY && type.isAssignableFrom(Polygon.class);
}
@@ -35,15 +35,13 @@ public boolean canEncode(Object value) {
}
@Override
- public Polygon decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Polygon decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeBinary(buf, length, column, cal);
}
@Override
- public Polygon decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Polygon decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
if (column.getType() == DataType.GEOMETRY) {
buf.skip(4); // SRID
@@ -60,13 +58,13 @@ public Polygon decodeBinary(
@Override
public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLength)
+ Writer encoder, Context context, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeBytes(("ST_PolyFromText('" + value.toString() + "')").getBytes());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
Polygon poly = (Polygon) value;
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/ReaderCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java
similarity index 84%
rename from src/main/java/org/mariadb/jdbc/codec/list/ReaderCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java
index ba56941bd..799e8a3b1 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/ReaderCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ReaderCodec.java
@@ -2,18 +2,18 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.util.constants.ServerStatus;
@@ -31,7 +31,7 @@ public class ReaderCodec implements Codec {
DataType.MEDIUMBLOB,
DataType.LONGBLOB);
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(Reader.class);
}
@@ -41,8 +41,7 @@ public String className() {
@Override
@SuppressWarnings("fallthrough")
- public Reader decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Reader decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
case BLOB:
@@ -70,8 +69,7 @@ public Reader decodeText(
}
@Override
- public Reader decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public Reader decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
return decodeText(buf, length, column, cal);
}
@@ -81,8 +79,7 @@ public boolean canEncode(Object value) {
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object val, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object val, Calendar cal, Long maxLen)
throws IOException {
Reader reader = (Reader) val;
encoder.writeByte('\'');
@@ -111,7 +108,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object val, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object val, Calendar cal, Long maxLength)
throws IOException {
// prefer use of encodeLongData, because length is unknown
byte[] clobBytes = new byte[4096];
@@ -138,8 +135,7 @@ public void encodeBinary(PacketWriter encoder, Object val, Calendar cal, Long ma
}
@Override
- public void encodeLongData(PacketWriter encoder, Reader reader, Long maxLength)
- throws IOException {
+ public void encodeLongData(Writer encoder, Reader reader, Long maxLength) throws IOException {
char[] buf = new char[4096];
int len;
long maxLen = maxLength != null ? maxLength : Long.MAX_VALUE;
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/ShortCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java
similarity index 87%
rename from src/main/java/org/mariadb/jdbc/codec/list/ShortCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java
index af3c23133..6c6692a29 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/ShortCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/ShortCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.math.BigDecimal;
@@ -10,11 +10,11 @@
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class ShortCodec implements Codec {
@@ -43,7 +43,7 @@ public class ShortCodec implements Codec {
DataType.MEDIUMBLOB,
DataType.LONGBLOB);
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType())
&& ((type.isPrimitive() && type == Short.TYPE) || type.isAssignableFrom(Short.class));
}
@@ -58,16 +58,13 @@ public String className() {
@Override
public Short decodeText(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeTextShort(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public short decodeTextShort(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public short decodeTextShort(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
long result;
switch (column.getType()) {
@@ -131,16 +128,13 @@ public short decodeTextShort(ReadableByteBuf buf, int length, ColumnDefinitionPa
@Override
public Short decodeBinary(
- final ReadableByteBuf buffer,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buffer, final int length, final Column column, final Calendar cal)
throws SQLDataException {
return decodeBinaryShort(buffer, length, column);
}
@SuppressWarnings("fallthrough")
- public short decodeBinaryShort(ReadableByteBuf buf, int length, ColumnDefinitionPacket column)
+ public short decodeBinaryShort(ReadableByteBuf buf, int length, Column column)
throws SQLDataException {
long result;
switch (column.getType()) {
@@ -225,14 +219,13 @@ public short decodeBinaryShort(ReadableByteBuf buf, int length, ColumnDefinition
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
encoder.writeAscii(value.toString());
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
encoder.writeShort((Short) value);
}
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/StreamCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java
similarity index 85%
rename from src/main/java/org/mariadb/jdbc/codec/list/StreamCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java
index 3ce431cb8..39e788b52 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/StreamCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/StreamCodec.java
@@ -2,17 +2,17 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.*;
import java.sql.SQLDataException;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.util.constants.ServerStatus;
@@ -34,13 +34,12 @@ public String className() {
return InputStream.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(InputStream.class);
}
@Override
- public InputStream decodeText(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public InputStream decodeText(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
case STRING:
@@ -61,8 +60,7 @@ public InputStream decodeText(
}
@Override
- public InputStream decodeBinary(
- ReadableByteBuf buf, int length, ColumnDefinitionPacket column, Calendar cal)
+ public InputStream decodeBinary(ReadableByteBuf buf, int length, Column column, Calendar cal)
throws SQLDataException {
switch (column.getType()) {
case STRING:
@@ -87,8 +85,7 @@ public boolean canEncode(Object value) {
}
@Override
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
encoder.writeBytes(ByteArrayCodec.BINARY_PREFIX);
byte[] array = new byte[4096];
@@ -113,7 +110,7 @@ public void encodeText(
}
@Override
- public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer encoder, Object value, Calendar cal, Long maxLength)
throws IOException {
// length is not known
byte[] blobBytes = new byte[4096];
@@ -151,8 +148,7 @@ public void encodeBinary(PacketWriter encoder, Object value, Calendar cal, Long
}
@Override
- public void encodeLongData(PacketWriter encoder, InputStream value, Long maxLength)
- throws IOException {
+ public void encodeLongData(Writer encoder, InputStream value, Long maxLength) throws IOException {
byte[] array = new byte[4096];
int len;
if (maxLength == null) {
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/StringCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java
similarity index 91%
rename from src/main/java/org/mariadb/jdbc/codec/list/StringCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java
index a1927bac0..95b813112 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/StringCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/StringCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -12,11 +12,11 @@
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
import org.mariadb.jdbc.util.constants.ServerStatus;
@@ -57,7 +57,7 @@ public String className() {
return String.class.getName();
}
- public boolean canDecode(ColumnDefinitionPacket column, Class> type) {
+ public boolean canDecode(Column column, Class> type) {
return COMPATIBLE_TYPES.contains(column.getType()) && type.isAssignableFrom(String.class);
}
@@ -66,10 +66,7 @@ public boolean canEncode(Object value) {
}
public String decodeText(
- final ReadableByteBuf buf,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buf, final int length, final Column column, final Calendar cal)
throws SQLDataException {
switch (column.getType()) {
case BIT:
@@ -107,10 +104,7 @@ public String decodeText(
}
public String decodeBinary(
- final ReadableByteBuf buf,
- final int length,
- final ColumnDefinitionPacket column,
- final Calendar cal)
+ final ReadableByteBuf buf, final int length, final Column column, final Calendar cal)
throws SQLDataException {
switch (column.getType()) {
case BIT:
@@ -275,8 +269,7 @@ public String decodeBinary(
}
}
- public void encodeText(
- PacketWriter encoder, Context context, Object value, Calendar cal, Long maxLen)
+ public void encodeText(Writer encoder, Context context, Object value, Calendar cal, Long maxLen)
throws IOException {
encoder.writeByte('\'');
encoder.writeStringEscaped(
@@ -285,7 +278,7 @@ public void encodeText(
encoder.writeByte('\'');
}
- public void encodeBinary(PacketWriter writer, Object value, Calendar cal, Long maxLength)
+ public void encodeBinary(Writer writer, Object value, Calendar cal, Long maxLength)
throws IOException {
byte[] b = value.toString().getBytes(StandardCharsets.UTF_8);
int len = maxLength != null ? Math.min(maxLength.intValue(), b.length) : b.length;
diff --git a/src/main/java/org/mariadb/jdbc/codec/list/TimeCodec.java b/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java
similarity index 90%
rename from src/main/java/org/mariadb/jdbc/codec/list/TimeCodec.java
rename to src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java
index e0cb8156d..1737fb456 100644
--- a/src/main/java/org/mariadb/jdbc/codec/list/TimeCodec.java
+++ b/src/main/java/org/mariadb/jdbc/plugin/codec/TimeCodec.java
@@ -2,7 +2,7 @@
// Copyright (c) 2012-2014 Monty Program Ab
// Copyright (c) 2015-2021 MariaDB Corporation Ab
-package org.mariadb.jdbc.codec.list;
+package org.mariadb.jdbc.plugin.codec;
import java.io.IOException;
import java.sql.SQLDataException;
@@ -13,11 +13,11 @@
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.EnumSet;
+import org.mariadb.jdbc.client.Column;
+import org.mariadb.jdbc.client.Context;
+import org.mariadb.jdbc.client.DataType;
import org.mariadb.jdbc.client.ReadableByteBuf;
-import org.mariadb.jdbc.client.context.Context;
-import org.mariadb.jdbc.client.socket.PacketWriter;
-import org.mariadb.jdbc.codec.DataType;
-import org.mariadb.jdbc.message.server.ColumnDefinitionPacket;
+import org.mariadb.jdbc.client.socket.Writer;
import org.mariadb.jdbc.plugin.Codec;
public class TimeCodec implements Codec