From 97e04b3fd9f9f7c05a41be8091e20dae7be2a8ee Mon Sep 17 00:00:00 2001 From: ZLATAN628 <107628611+ZLATAN628@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:12:13 +0800 Subject: [PATCH] fix #3287 --- .../apache/ibatis/type/NClobTypeHandler.java | 22 ++++++------- .../ibatis/type/NClobTypeHandlerTest.java | 32 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/apache/ibatis/type/NClobTypeHandler.java b/src/main/java/org/apache/ibatis/type/NClobTypeHandler.java index ffa4ce7ab4b..0341747f221 100644 --- a/src/main/java/org/apache/ibatis/type/NClobTypeHandler.java +++ b/src/main/java/org/apache/ibatis/type/NClobTypeHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 the original author or authors. + * Copyright 2009-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ import java.io.StringReader; import java.sql.CallableStatement; -import java.sql.Clob; +import java.sql.NClob; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -31,29 +31,29 @@ public class NClobTypeHandler extends BaseTypeHandler { public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException { StringReader reader = new StringReader(parameter); - ps.setCharacterStream(i, reader, parameter.length()); + ps.setNCharacterStream(i, reader, parameter.length()); } @Override public String getNullableResult(ResultSet rs, String columnName) throws SQLException { - Clob clob = rs.getClob(columnName); - return toString(clob); + NClob nclob = rs.getNClob(columnName); + return toString(nclob); } @Override public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException { - Clob clob = rs.getClob(columnIndex); - return toString(clob); + NClob nclob = rs.getNClob(columnIndex); + return toString(nclob); } @Override public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { - Clob clob = cs.getClob(columnIndex); - return toString(clob); + NClob nclob = cs.getNClob(columnIndex); + return toString(nclob); } - private String toString(Clob clob) throws SQLException { - return clob == null ? null : clob.getSubString(1, (int) clob.length()); + private String toString(NClob nclob) throws SQLException { + return nclob == null ? null : nclob.getSubString(1, (int) nclob.length()); } } diff --git a/src/test/java/org/apache/ibatis/type/NClobTypeHandlerTest.java b/src/test/java/org/apache/ibatis/type/NClobTypeHandlerTest.java index 75bd4b725dd..075d08a5f07 100644 --- a/src/test/java/org/apache/ibatis/type/NClobTypeHandlerTest.java +++ b/src/test/java/org/apache/ibatis/type/NClobTypeHandlerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2023 the original author or authors. + * Copyright 2009-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import static org.mockito.Mockito.when; import java.io.Reader; -import java.sql.Clob; +import java.sql.NClob; import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; @@ -32,60 +32,60 @@ class NClobTypeHandlerTest extends BaseTypeHandlerTest { private static final TypeHandler TYPE_HANDLER = new NClobTypeHandler(); @Mock - protected Clob clob; + protected NClob nclob; @Override @Test public void shouldSetParameter() throws Exception { TYPE_HANDLER.setParameter(ps, 1, "Hello", null); - verify(ps).setCharacterStream(ArgumentMatchers.eq(1), ArgumentMatchers.any(Reader.class), ArgumentMatchers.eq(5)); + verify(ps).setNCharacterStream(ArgumentMatchers.eq(1), ArgumentMatchers.any(Reader.class), ArgumentMatchers.eq(5L)); } @Override @Test public void shouldGetResultFromResultSetByName() throws Exception { - when(rs.getClob("column")).thenReturn(clob); - when(clob.length()).thenReturn(3L); - when(clob.getSubString(1, 3)).thenReturn("Hello"); + when(rs.getNClob("column")).thenReturn(nclob); + when(nclob.length()).thenReturn(3L); + when(nclob.getSubString(1, 3)).thenReturn("Hello"); assertEquals("Hello", TYPE_HANDLER.getResult(rs, "column")); } @Override @Test public void shouldGetResultNullFromResultSetByName() throws Exception { - when(rs.getClob("column")).thenReturn(null); + when(rs.getNClob("column")).thenReturn(null); assertNull(TYPE_HANDLER.getResult(rs, "column")); } @Override @Test public void shouldGetResultFromResultSetByPosition() throws Exception { - when(rs.getClob(1)).thenReturn(clob); - when(clob.length()).thenReturn(3L); - when(clob.getSubString(1, 3)).thenReturn("Hello"); + when(rs.getNClob(1)).thenReturn(nclob); + when(nclob.length()).thenReturn(3L); + when(nclob.getSubString(1, 3)).thenReturn("Hello"); assertEquals("Hello", TYPE_HANDLER.getResult(rs, 1)); } @Override @Test public void shouldGetResultNullFromResultSetByPosition() throws Exception { - when(rs.getClob(1)).thenReturn(null); + when(rs.getNClob(1)).thenReturn(null); assertNull(TYPE_HANDLER.getResult(rs, 1)); } @Override @Test public void shouldGetResultFromCallableStatement() throws Exception { - when(cs.getClob(1)).thenReturn(clob); - when(clob.length()).thenReturn(3L); - when(clob.getSubString(1, 3)).thenReturn("Hello"); + when(cs.getNClob(1)).thenReturn(nclob); + when(nclob.length()).thenReturn(3L); + when(nclob.getSubString(1, 3)).thenReturn("Hello"); assertEquals("Hello", TYPE_HANDLER.getResult(cs, 1)); } @Override @Test public void shouldGetResultNullFromCallableStatement() throws Exception { - when(cs.getClob(1)).thenReturn(null); + when(cs.getNClob(1)).thenReturn(null); assertNull(TYPE_HANDLER.getResult(cs, 1)); }