16
16
17
17
import com .github .housepower .jdbc .connect .NativeContext ;
18
18
import com .github .housepower .jdbc .data .IDataType ;
19
+ import com .github .housepower .jdbc .misc .BytesCharSeq ;
19
20
import com .github .housepower .jdbc .misc .SQLLexer ;
20
21
import com .github .housepower .jdbc .serde .BinaryDeserializer ;
21
22
import com .github .housepower .jdbc .serde .BinarySerializer ;
25
26
import java .sql .SQLException ;
26
27
import java .sql .Types ;
27
28
28
- public class DataTypeString implements IDataType {
29
+ public class DataTypeString implements IDataType < CharSequence > {
29
30
30
31
public static DataTypeCreator CREATOR = (lexer , serverContext ) -> new DataTypeString (serverContext );
31
32
@@ -46,12 +47,13 @@ public int sqlTypeId() {
46
47
}
47
48
48
49
@ Override
49
- public Object defaultValue () {
50
+ public String defaultValue () {
50
51
return "" ;
51
52
}
52
53
54
+ // TODO FIX Later
53
55
@ Override
54
- public Class javaTypeClass () {
56
+ public Class < String > javaTypeClass () {
55
57
return String .class ;
56
58
}
57
59
@@ -71,12 +73,12 @@ public int getScale() {
71
73
}
72
74
73
75
@ Override
74
- public void serializeBinary (Object data , BinarySerializer serializer ) throws SQLException , IOException {
75
- if (data instanceof CharSequence ) {
76
- serializer .writeStringBinary (data .toString (), charset );
77
- } else {
78
- serializer .writeBytesBinary ((byte []) data );
76
+ public void serializeBinary (CharSequence data , BinarySerializer serializer ) throws SQLException , IOException {
77
+ if (data instanceof BytesCharSeq ) {
78
+ serializer .writeBytesBinary (((BytesCharSeq ) data ).bytes ());
79
+ return ;
79
80
}
81
+ serializer .writeStringBinary (data .toString (), charset );
80
82
}
81
83
82
84
/**
@@ -90,7 +92,7 @@ public String deserializeBinary(BinaryDeserializer deserializer) throws SQLExcep
90
92
}
91
93
92
94
@ Override
93
- public Object [] deserializeBinaryBulk (int rowCnt , BinaryDeserializer deserializer ) throws SQLException , IOException {
95
+ public String [] deserializeBinaryBulk (int rowCnt , BinaryDeserializer deserializer ) throws SQLException , IOException {
94
96
String [] data = new String [rowCnt ];
95
97
for (int row = 0 ; row < rowCnt ; row ++) {
96
98
byte [] bs = deserializer .readBytesBinary ();
@@ -115,7 +117,7 @@ public String[] getAliases() {
115
117
}
116
118
117
119
@ Override
118
- public Object deserializeTextQuoted (SQLLexer lexer ) throws SQLException {
120
+ public CharSequence deserializeTextQuoted (SQLLexer lexer ) throws SQLException {
119
121
return lexer .stringView ();
120
122
}
121
123
}
0 commit comments