Skip to content

Commit 8abced3

Browse files
author
diego Dupin
committed
[misc] small code improvement
1 parent 6bcae38 commit 8abced3

File tree

15 files changed

+144
-73
lines changed

15 files changed

+144
-73
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected String preSqlCmd() {
5757
if (queryTimeout != 0 && canUseServerTimeout) {
5858
return "SET STATEMENT max_statement_time=" + queryTimeout + " FOR ";
5959
}
60-
return "";
60+
return null;
6161
}
6262

6363
private void executeInternal() throws SQLException {

src/main/java/org/mariadb/jdbc/client/ReadableByteBuf.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package org.mariadb.jdbc.client;
66

77
import org.mariadb.jdbc.MariaDbBlob;
8-
import org.mariadb.jdbc.client.util.MutableInt;
98

109
public interface ReadableByteBuf {
1110

@@ -21,12 +20,10 @@ public interface ReadableByteBuf {
2120

2221
void skip();
2322

24-
ReadableByteBuf skip(int length);
23+
void skip(int length);
2524

2625
MariaDbBlob readBlob(int length);
2726

28-
MutableInt getSequence();
29-
3027
byte getByte();
3128

3229
byte getByte(int index);

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
import java.nio.charset.StandardCharsets;
88
import org.mariadb.jdbc.MariaDbBlob;
99
import org.mariadb.jdbc.client.ReadableByteBuf;
10-
import org.mariadb.jdbc.client.util.MutableInt;
1110

1211
public final class StandardReadableByteBuf implements ReadableByteBuf {
13-
private final MutableInt sequence;
12+
1413
private int limit;
1514
private byte[] buf;
1615
private int pos;
1716

18-
public StandardReadableByteBuf(MutableInt sequence, byte[] buf, int limit) {
19-
this.sequence = sequence;
17+
public StandardReadableByteBuf(byte[] buf, int limit) {
2018
this.pos = 0;
2119
this.buf = buf;
2220
this.limit = limit;
@@ -48,20 +46,15 @@ public void skip() {
4846
pos++;
4947
}
5048

51-
public StandardReadableByteBuf skip(int length) {
49+
public void skip(int length) {
5250
pos += length;
53-
return this;
5451
}
5552

5653
public MariaDbBlob readBlob(int length) {
5754
pos += length;
5855
return MariaDbBlob.safeMariaDbBlob(buf, pos - length, length);
5956
}
6057

61-
public MutableInt getSequence() {
62-
return sequence;
63-
}
64-
6558
public byte getByte() {
6659
return buf[pos];
6760
}
@@ -94,12 +87,8 @@ public int readLengthNotNull() {
9487
* @return current pos
9588
*/
9689
public int skipIdentifier() {
97-
int type = (buf[pos++] & 0xff);
98-
if (type == 252) {
99-
pos += readUnsignedShort();
100-
return pos;
101-
}
102-
pos += type;
90+
int type = buf[pos++] & 0xff;
91+
pos += (type == 252) ? readUnsignedShort() : type;
10392
return pos;
10493
}
10594

@@ -211,7 +200,7 @@ public StandardReadableByteBuf readLengthBuffer() {
211200
int len = readLengthNotNull();
212201
byte[] tmp = new byte[len];
213202
readBytes(tmp);
214-
return new StandardReadableByteBuf(sequence, tmp, len);
203+
return new StandardReadableByteBuf(tmp, len);
215204
}
216205

217206
public String readString(int length) {

src/main/java/org/mariadb/jdbc/client/result/Result.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ protected boolean readNext() throws SQLException, IOException {
102102
case (byte) 0xFF:
103103
loaded = true;
104104
ErrorPacket errorPacket =
105-
new ErrorPacket(new StandardReadableByteBuf(null, buf, buf.length), context);
105+
new ErrorPacket(new StandardReadableByteBuf(buf, buf.length), context);
106106
throw exceptionFactory.create(
107107
errorPacket.getMessage(), errorPacket.getSqlState(), errorPacket.getErrorCode());
108108

109109
case (byte) 0xFE:
110110
if ((context.isEofDeprecated() && buf.length < 16777215)
111111
|| (!context.isEofDeprecated() && buf.length < 8)) {
112-
ReadableByteBuf readBuf = new StandardReadableByteBuf(null, buf, buf.length);
112+
ReadableByteBuf readBuf = new StandardReadableByteBuf(buf, buf.length);
113113
readBuf.skip(); // skip header
114114
int serverStatus;
115115
int warnings;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public ReadableByteBuf readPacket(boolean reUsable, boolean traceEnable) throws
176176
} while (packetLength == MAX_PACKET_SIZE);
177177
}
178178

179-
return new StandardReadableByteBuf(sequence, rawBytes, lastPacketLength);
179+
return new StandardReadableByteBuf(rawBytes, lastPacketLength);
180180
}
181181

182182
public MutableInt getSequence() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ public void writeEmptyPacket() throws IOException {
663663
*/
664664
public void flush() throws IOException {
665665
writeSocket(true);
666-
out.flush();
666+
667667
// if buf is big, and last query doesn't use at least half of it, resize buf to default
668668
// value
669669
if (buf.length > SMALL_BUFFER_SIZE && cmdLength * 2 < buf.length) {

src/main/java/org/mariadb/jdbc/codec/RowDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public abstract class RowDecoder {
1717
protected static final int NULL_LENGTH = -1;
1818
private final Configuration conf;
19-
protected final ReadableByteBuf readBuf = new StandardReadableByteBuf(null, null, 0);
19+
protected final ReadableByteBuf readBuf = new StandardReadableByteBuf(null, 0);
2020
protected final Column[] columns;
2121

2222
protected int length;

src/main/java/org/mariadb/jdbc/message/client/QueryWithParametersPacket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void saveParameters() {
4545
public int encode(Writer encoder, Context context) throws IOException, SQLException {
4646
encoder.initPacket();
4747
encoder.writeByte(0x03);
48-
if (!preSqlCmd.isEmpty()) encoder.writeAscii(preSqlCmd);
48+
if (preSqlCmd != null) encoder.writeAscii(preSqlCmd);
4949
if (parser.getParamCount() == 0) {
5050
encoder.writeBytes(parser.getQueryParts().get(0));
5151
} else {

src/main/java/org/mariadb/jdbc/message/server/ColumnDefinitionPacket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static ColumnDefinitionPacket create(String name, DataType type) {
125125
}
126126

127127
return new ColumnDefinitionPacket(
128-
new StandardReadableByteBuf(null, arr, arr.length), len, type, stringPos);
128+
new StandardReadableByteBuf(arr, arr.length), len, type, stringPos);
129129
}
130130

131131
public String getSchema() {

src/main/java/org/mariadb/jdbc/plugin/authentication/addon/SendGssApiAuthPacket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void initialize(String authenticationData, byte[] seed, Configuration con
6464
*/
6565
public ReadableByteBuf process(Writer out, Reader in, Context context)
6666
throws IOException, SQLException {
67-
ReadableByteBuf buf = new StandardReadableByteBuf(in.getSequence(), seed, seed.length);
67+
ReadableByteBuf buf = new StandardReadableByteBuf(seed, seed.length);
6868

6969
final String serverSpn = buf.readStringNullEnd();
7070
// using provided connection string SPN if set, or if not, using to server information

0 commit comments

Comments
 (0)