Skip to content

Commit fe37496

Browse files
blafondDavideD
authored andcommitted
[#1500] Fixes Clob type issues
1 parent e9b4a6c commit fe37496

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/PreparedStatementAdaptor.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,25 @@ private static Buffer convertToBuffer(InputStream is) throws IOException {
346346

347347
@Override
348348
public void setCharacterStream(int parameterIndex, Reader reader, long length) {
349-
throw new UnsupportedOperationException();
349+
try {
350+
int charsLength = (int) length;
351+
char[] chars = new char[charsLength];
352+
int charsRead = 0;
353+
while ( true ) {
354+
int n = reader.read( chars, charsRead, charsLength - charsRead );
355+
if ( n == -1 ) {
356+
break;
357+
}
358+
charsRead += n;
359+
if ( charsRead == length ) {
360+
break;
361+
}
362+
}
363+
setString( parameterIndex, new String( chars, 0, charsRead ) );
364+
}
365+
catch (IOException e) {
366+
throw new RuntimeException( e );
367+
}
350368
}
351369

352370
@Override

hibernate-reactive-core/src/main/java/org/hibernate/reactive/adaptor/impl/ResultSetAdaptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,14 +703,14 @@ public Ref getRef(int columnIndex) {
703703

704704
@Override
705705
public Blob getBlob(int columnIndex) {
706-
Blob blob = blob( row -> row.getValue( columnIndex ), row -> row.getBuffer( columnIndex ) );
706+
Blob blob = blob( row -> row.getValue( columnIndex - 1 ), row -> row.getBuffer( columnIndex - 1 ) );
707707
wasNull = blob == null;
708708
return blob;
709709
}
710710

711711
@Override
712712
public Clob getClob(int columnIndex) {
713-
Clob clob = clob( row -> row.getString( columnIndex ) );
713+
Clob clob = clob( row -> row.getString( columnIndex - 1 ) );
714714
wasNull = clob == null;
715715
if ( wasNull ) {
716716
return null;

0 commit comments

Comments
 (0)