24
24
import io .r2dbc .spi .Blob ;
25
25
import io .r2dbc .spi .Clob ;
26
26
import io .r2dbc .spi .Connection ;
27
+ import io .r2dbc .spi .Parameters ;
27
28
import io .r2dbc .spi .Row ;
28
29
import io .r2dbc .spi .Statement ;
29
30
import oracle .sql .json .OracleJsonFactory ;
50
51
import java .util .stream .Collectors ;
51
52
import java .util .stream .Stream ;
52
53
54
+ import static io .r2dbc .spi .R2dbcType .NCHAR ;
55
+ import static io .r2dbc .spi .R2dbcType .NCLOB ;
56
+ import static io .r2dbc .spi .R2dbcType .NVARCHAR ;
53
57
import static java .util .Arrays .asList ;
54
58
import static oracle .r2dbc .test .DatabaseConfig .connectTimeout ;
55
59
import static oracle .r2dbc .test .DatabaseConfig .databaseVersion ;
@@ -95,6 +99,16 @@ public class TypeMappingTest {
95
99
* <a href="https://r2dbc.io/spec/0.8.3.RELEASE/spec/html/#datatypes.mapping">
96
100
* Table 4 of Section 12 of the R2DBC 0.8.3 Specification.
97
101
* </a>
102
+ * </p><p>
103
+ * This test method makes use of {@link io.r2dbc.spi.R2dbcType#NCHAR} and
104
+ * {@link io.r2dbc.spi.R2dbcType#NVARCHAR} when binding Strings that contain
105
+ * non-ascii characters. By default, a String bind is mapped to the VARCHAR
106
+ * SQL type. This default mapping has the driver encode the value using the
107
+ * database character set. The database character set may not support
108
+ * non-ascii characters. Binding Strings with the NCHAR/NVARCHAR type
109
+ * configures the driver to encode the string using the national character set
110
+ * of the database. The national character set is either UTF16 or UTF8, and so
111
+ * it must support non-ascii characters.
98
112
* </p>
99
113
*/
100
114
@ Test
@@ -112,11 +126,18 @@ public void testCharacterTypeMappings() {
112
126
113
127
// Expect NCHAR and String to map
114
128
verifyTypeMapping (connection ,
115
- String .format ("%100s" , "你好, Oracle" ), "NCHAR(100)" );
129
+ Parameters .in (NCHAR , String .format ("%100s" , "你好, Oracle" )),
130
+ "NCHAR(100)" ,
131
+ (expected , actual ) ->
132
+ assertEquals (expected .getValue (), actual ));
116
133
117
134
// Expect NVARCHAR and String to map. The Oracle type named "NVARCHAR2" is
118
135
// equivalent to the standard type named "NVARCHAR"
119
- verifyTypeMapping (connection , "नमस्कार, Oracle" , "NVARCHAR2(100)" );
136
+ verifyTypeMapping (connection ,
137
+ Parameters .in (NVARCHAR , "नमस्कार, Oracle" ),
138
+ "NVARCHAR2(100)" ,
139
+ (expected , actual ) ->
140
+ assertEquals (expected .getValue (), actual ));
120
141
121
142
// Expect CLOB and String to map
122
143
verifyTypeMapping (connection , "Hola, Oracle" , "CLOB" );
@@ -130,7 +151,11 @@ public void testCharacterTypeMappings() {
130
151
131
152
// Expect NCLOB and String to map for bind values, but not for row values.
132
153
// For row values, expect Oracle CLOB to be mapped to io.r2dbc.spi.Clob
133
- verifyTypeMapping (connection , "こんにちは, Oracle" , "NCLOB" );
154
+ verifyTypeMapping (connection ,
155
+ Parameters .in (NVARCHAR , "こんにちは, Oracle" ),
156
+ "NCLOB" ,
157
+ (expected , actual ) ->
158
+ assertEquals (expected .getValue (), actual ));
134
159
135
160
// Expect NCLOB and io.r2dbc.spi.Clob to map
136
161
verifyTypeMapping (connection ,
0 commit comments