1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one or more
3
+ * contributor license agreements. See the NOTICE file distributed with
4
+ * this work for additional information regarding copyright ownership.
5
+ * The ASF licenses this file to You under the Apache License, Version 2.0
6
+ * (the "License"); you may not use this file except in compliance with
7
+ * the License. You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
1
18
package org .apache .shardingsphere .database .protocol .postgresql .packet .command .query .extended .bind .protocol ;
2
19
3
20
import org .apache .shardingsphere .database .protocol .postgresql .payload .PostgreSQLPacketPayload ;
10
27
import java .util .Map ;
11
28
12
29
public class PostgreSQLArrayBinaryProtocolValue implements PostgreSQLBinaryProtocolValue {
13
-
30
+
14
31
private static final Map <Integer , String > oidTypeName = new HashMap <>();
15
-
32
+
16
33
static {
17
34
oidTypeName .put (Oid .BOOL , "bool[]" );
18
35
oidTypeName .put (Oid .BYTEA , "bytea[]" );
19
- // oidTypeName.put(Oid.CHAR_ARRAY, "char[]");
20
- // oidTypeName.put(Oid.NAME_ARRAY, "name[]");
36
+ // oidTypeName.put(Oid.CHAR_ARRAY, "char[]");
37
+ // oidTypeName.put(Oid.NAME_ARRAY, "name[]");
21
38
oidTypeName .put (Oid .INT2 , "int2[]" );
22
39
oidTypeName .put (Oid .INT4 , "int4[]" );
23
40
oidTypeName .put (Oid .INT8 , "int8[]" );
@@ -27,23 +44,23 @@ public class PostgreSQLArrayBinaryProtocolValue implements PostgreSQLBinaryProto
27
44
oidTypeName .put (Oid .VARCHAR , "varchar[]" );
28
45
oidTypeName .put (Oid .DATE , "date[]" );
29
46
oidTypeName .put (Oid .TIMESTAMP , "timestamp[]" );
30
- // oidTypeName.put(Oid.TIMESTAMPTZ_ARRAY, "timestamptz[]");
47
+ // oidTypeName.put(Oid.TIMESTAMPTZ_ARRAY, "timestamptz[]");
31
48
oidTypeName .put (Oid .TIME , "time[]" );
32
- // oidTypeName.put(Oid.TIMETZ_ARRAY, "timetz[]");
49
+ // oidTypeName.put(Oid.TIMETZ_ARRAY, "timetz[]");
33
50
oidTypeName .put (Oid .NUMERIC , "numeric[]" );
34
- // oidTypeName.put(Oid.UUID_ARRAY, "uuid[]");
51
+ // oidTypeName.put(Oid.UUID_ARRAY, "uuid[]");
35
52
}
36
-
37
- private PostgreSQLArrayBinaryProtocolValue (){
38
-
53
+
54
+ private PostgreSQLArrayBinaryProtocolValue () {
55
+
39
56
}
40
57
public static final PostgreSQLArrayBinaryProtocolValue instance = new PostgreSQLArrayBinaryProtocolValue ();
41
-
58
+
42
59
@ Override
43
60
public int getColumnLength (PostgreSQLPacketPayload payload , Object value ) {
44
61
return -1 ;
45
62
}
46
-
63
+
47
64
@ Override
48
65
public Object read (PostgreSQLPacketPayload payload , int parameterValueLength ) {
49
66
byte [] bytes = new byte [parameterValueLength ];
@@ -55,16 +72,11 @@ public Object read(PostgreSQLPacketPayload payload, int parameterValueLength) {
55
72
pgBinaryObj .setType (typeName );
56
73
return pgBinaryObj ;
57
74
}
58
-
75
+
59
76
@ Override
60
77
public void write (PostgreSQLPacketPayload payload , Object value ) {
61
- try {
62
- byte [] result = ShardingSpherePgArrayUtils .getBinaryBytes (value ,payload .getCharset ());
63
- payload .writeInt4 (result .length );
64
- payload .writeBytes (result );
65
- }catch (Exception e ) {
66
- e .printStackTrace ();
67
- }
68
-
78
+ byte [] result = ShardingSpherePgArrayUtils .getBinaryBytes (value , payload .getCharset ());
79
+ payload .writeInt4 (result .length );
80
+ payload .writeBytes (result );
69
81
}
70
82
}
0 commit comments