Skip to content

Commit 97e04b3

Browse files
committed
fix #3287
1 parent 6a2676a commit 97e04b3

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

src/main/java/org/apache/ibatis/type/NClobTypeHandler.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717

1818
import java.io.StringReader;
1919
import java.sql.CallableStatement;
20-
import java.sql.Clob;
20+
import java.sql.NClob;
2121
import java.sql.PreparedStatement;
2222
import java.sql.ResultSet;
2323
import java.sql.SQLException;
@@ -31,29 +31,29 @@ public class NClobTypeHandler extends BaseTypeHandler<String> {
3131
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
3232
throws SQLException {
3333
StringReader reader = new StringReader(parameter);
34-
ps.setCharacterStream(i, reader, parameter.length());
34+
ps.setNCharacterStream(i, reader, parameter.length());
3535
}
3636

3737
@Override
3838
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
39-
Clob clob = rs.getClob(columnName);
40-
return toString(clob);
39+
NClob nclob = rs.getNClob(columnName);
40+
return toString(nclob);
4141
}
4242

4343
@Override
4444
public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
45-
Clob clob = rs.getClob(columnIndex);
46-
return toString(clob);
45+
NClob nclob = rs.getNClob(columnIndex);
46+
return toString(nclob);
4747
}
4848

4949
@Override
5050
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
51-
Clob clob = cs.getClob(columnIndex);
52-
return toString(clob);
51+
NClob nclob = cs.getNClob(columnIndex);
52+
return toString(nclob);
5353
}
5454

55-
private String toString(Clob clob) throws SQLException {
56-
return clob == null ? null : clob.getSubString(1, (int) clob.length());
55+
private String toString(NClob nclob) throws SQLException {
56+
return nclob == null ? null : nclob.getSubString(1, (int) nclob.length());
5757
}
5858

5959
}

src/test/java/org/apache/ibatis/type/NClobTypeHandlerTest.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
2121
import static org.mockito.Mockito.when;
2222

2323
import java.io.Reader;
24-
import java.sql.Clob;
24+
import java.sql.NClob;
2525

2626
import org.junit.jupiter.api.Test;
2727
import org.mockito.ArgumentMatchers;
@@ -32,60 +32,60 @@ class NClobTypeHandlerTest extends BaseTypeHandlerTest {
3232
private static final TypeHandler<String> TYPE_HANDLER = new NClobTypeHandler();
3333

3434
@Mock
35-
protected Clob clob;
35+
protected NClob nclob;
3636

3737
@Override
3838
@Test
3939
public void shouldSetParameter() throws Exception {
4040
TYPE_HANDLER.setParameter(ps, 1, "Hello", null);
41-
verify(ps).setCharacterStream(ArgumentMatchers.eq(1), ArgumentMatchers.any(Reader.class), ArgumentMatchers.eq(5));
41+
verify(ps).setNCharacterStream(ArgumentMatchers.eq(1), ArgumentMatchers.any(Reader.class), ArgumentMatchers.eq(5L));
4242
}
4343

4444
@Override
4545
@Test
4646
public void shouldGetResultFromResultSetByName() throws Exception {
47-
when(rs.getClob("column")).thenReturn(clob);
48-
when(clob.length()).thenReturn(3L);
49-
when(clob.getSubString(1, 3)).thenReturn("Hello");
47+
when(rs.getNClob("column")).thenReturn(nclob);
48+
when(nclob.length()).thenReturn(3L);
49+
when(nclob.getSubString(1, 3)).thenReturn("Hello");
5050
assertEquals("Hello", TYPE_HANDLER.getResult(rs, "column"));
5151
}
5252

5353
@Override
5454
@Test
5555
public void shouldGetResultNullFromResultSetByName() throws Exception {
56-
when(rs.getClob("column")).thenReturn(null);
56+
when(rs.getNClob("column")).thenReturn(null);
5757
assertNull(TYPE_HANDLER.getResult(rs, "column"));
5858
}
5959

6060
@Override
6161
@Test
6262
public void shouldGetResultFromResultSetByPosition() throws Exception {
63-
when(rs.getClob(1)).thenReturn(clob);
64-
when(clob.length()).thenReturn(3L);
65-
when(clob.getSubString(1, 3)).thenReturn("Hello");
63+
when(rs.getNClob(1)).thenReturn(nclob);
64+
when(nclob.length()).thenReturn(3L);
65+
when(nclob.getSubString(1, 3)).thenReturn("Hello");
6666
assertEquals("Hello", TYPE_HANDLER.getResult(rs, 1));
6767
}
6868

6969
@Override
7070
@Test
7171
public void shouldGetResultNullFromResultSetByPosition() throws Exception {
72-
when(rs.getClob(1)).thenReturn(null);
72+
when(rs.getNClob(1)).thenReturn(null);
7373
assertNull(TYPE_HANDLER.getResult(rs, 1));
7474
}
7575

7676
@Override
7777
@Test
7878
public void shouldGetResultFromCallableStatement() throws Exception {
79-
when(cs.getClob(1)).thenReturn(clob);
80-
when(clob.length()).thenReturn(3L);
81-
when(clob.getSubString(1, 3)).thenReturn("Hello");
79+
when(cs.getNClob(1)).thenReturn(nclob);
80+
when(nclob.length()).thenReturn(3L);
81+
when(nclob.getSubString(1, 3)).thenReturn("Hello");
8282
assertEquals("Hello", TYPE_HANDLER.getResult(cs, 1));
8383
}
8484

8585
@Override
8686
@Test
8787
public void shouldGetResultNullFromCallableStatement() throws Exception {
88-
when(cs.getClob(1)).thenReturn(null);
88+
when(cs.getNClob(1)).thenReturn(null);
8989
assertNull(TYPE_HANDLER.getResult(cs, 1));
9090
}
9191

0 commit comments

Comments
 (0)