Skip to content

Commit 560041b

Browse files
authored
Simplify data type codec maintenance (#987)
Moving all encoding, decoding, and metadata parsing logic to the same class. Also, put common buffer modification methods to utility Signed-off-by: Thomas Segismont <[email protected]>
1 parent 8eca81b commit 560041b

23 files changed

+983
-1216
lines changed

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/BinaryDataType.java

Lines changed: 0 additions & 31 deletions
This file was deleted.

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/CloseStatementCommandCodec.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
import io.vertx.mssqlclient.impl.protocol.MessageType;
1818
import io.vertx.mssqlclient.impl.protocol.TdsMessage;
1919
import io.vertx.mssqlclient.impl.protocol.client.rpc.ProcId;
20-
import io.vertx.mssqlclient.impl.protocol.datatype.MSSQLDataTypeId;
2120
import io.vertx.mssqlclient.impl.protocol.token.DataPacketStreamTokenType;
2221
import io.vertx.sqlclient.impl.command.CloseStatementCommand;
2322
import io.vertx.sqlclient.impl.command.CommandResponse;
2423

24+
import static io.vertx.mssqlclient.impl.codec.DataType.INTN;
25+
2526
class CloseStatementCommandCodec extends MSSQLCommandCodec<Void, CloseStatementCommand> {
2627

2728
CloseStatementCommandCodec(CloseStatementCommand cmd) {
@@ -93,7 +94,7 @@ private void sendUnprepareRequest() {
9394
// Option flags
9495
packet.writeShortLE(0x0000);
9596

96-
encodeIntNParameter(packet, ((MSSQLPreparedStatement) cmd.statement()).handle);
97+
INTN.encodeParam(packet, null, false, ((MSSQLPreparedStatement) cmd.statement()).handle);
9798

9899
int packetLen = packet.writerIndex() - packetLenIdx + 2;
99100
packet.setShort(packetLenIdx, packetLen);
@@ -107,13 +108,4 @@ protected void encodeTransactionDescriptor(ByteBuf payload, long transactionDesc
107108
payload.writeLongLE(transactionDescriptor);
108109
payload.writeIntLE(outstandingRequestCount);
109110
}
110-
111-
private void encodeIntNParameter(ByteBuf payload, Object value) {
112-
payload.writeByte(0x00);
113-
payload.writeByte(0x00);
114-
payload.writeByte(MSSQLDataTypeId.INTNTYPE_ID);
115-
payload.writeByte(4);
116-
payload.writeByte(4);
117-
payload.writeIntLE((Integer) value);
118-
}
119111
}
Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2011-2021 Contributors to the Eclipse Foundation
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License 2.0 which is available at
@@ -11,53 +11,33 @@
1111

1212
package io.vertx.mssqlclient.impl.codec;
1313

14-
import io.vertx.mssqlclient.impl.protocol.datatype.MSSQLDataType;
1514
import io.vertx.sqlclient.desc.ColumnDescriptor;
1615

1716
import java.sql.JDBCType;
1817

1918
public final class ColumnData implements ColumnDescriptor {
20-
/*
21-
Protocol reference: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/58880b9f-381c-43b2-bf8b-0727a98c4f4c
22-
*/
23-
private final long usertype;
24-
private final int flags;
25-
private final MSSQLDataType dataType;
26-
private final String colName;
2719

28-
// CryptoMetaData support?
29-
String tableName;
20+
private final String name;
21+
private final DataType dataType;
22+
private final DataType.Metadata metadata;
3023

31-
public ColumnData(long usertype, int flags, MSSQLDataType dataType, String colName) {
32-
this.usertype = usertype;
33-
this.flags = flags;
24+
public ColumnData(String name, DataType dataType, DataType.Metadata metadata) {
3425
this.dataType = dataType;
35-
this.colName = colName;
26+
this.name = name;
27+
this.metadata = metadata;
3628
}
3729

38-
public long usertype() {
39-
return usertype;
40-
}
41-
42-
public int flags() {
43-
return flags;
44-
}
45-
46-
public MSSQLDataType dataType() {
30+
public DataType dataType() {
4731
return dataType;
4832
}
4933

50-
public String colName() {
51-
return colName;
52-
}
53-
54-
public String tableName() {
55-
return tableName;
34+
public DataType.Metadata metadata() {
35+
return metadata;
5636
}
5737

5838
@Override
5939
public String name() {
60-
return colName;
40+
return name;
6141
}
6242

6343
@Override
@@ -67,22 +47,6 @@ public boolean isArray() {
6747

6848
@Override
6949
public JDBCType jdbcType() {
70-
return dataType.jdbcType();
71-
}
72-
73-
public static final class Flags {
74-
public static final int NULLABLE = 0x0001;
75-
public static final int CASESEN = 0x0002;
76-
public static final int UPDATEABLE = 0x0004;
77-
public static final int IDENTITY = 0x0010;
78-
public static final int COMPUTED = 0x0020;
79-
// 2-BIT RESERVED for ODBC
80-
public static final int FIXED_LEN_CLR_TYPE = 0x0100;
81-
// 1-BIT RESERVED
82-
public static final int SPARSE_COLUMN_SET = 0x0400;
83-
public static final int ENCRYPTED = 0x0800;
84-
public static final int HIDDEN = 0x2000;
85-
public static final int KEY = 0x4000;
86-
public static final int NULLABLE_UNKNOWN = 0x8000;
50+
return dataType.jdbcType(metadata);
8751
}
8852
}

0 commit comments

Comments
 (0)