Skip to content

Commit caf2ee4

Browse files
committed
HHH-7825 - org.hibernate.type.descriptor.java.DataHelper is incompatible with FireBird JDBC
1 parent dd280b8 commit caf2ee4

File tree

1 file changed

+26
-10
lines changed
  • hibernate-core/src/main/java/org/hibernate/type/descriptor/java

1 file changed

+26
-10
lines changed

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.StringReader;
3131
import java.sql.Clob;
3232
import java.sql.SQLException;
33+
import java.sql.SQLFeatureNotSupportedException;
3334

3435
import org.jboss.logging.Logger;
3536

@@ -268,34 +269,49 @@ public static InputStream subStream(InputStream inputStream, long start, int len
268269
/**
269270
* Extract the contents of the given Clob as a string.
270271
*
271-
* @param reader The reader for the content
272+
* @param value The clob to to be extracted from
272273
*
273274
* @return The content as string
274275
*/
275276
public static String extractString(final Clob value) {
276277
try {
277-
Reader characterStream = value.getCharacterStream();
278-
long length = value.length();
279-
if ( length > Integer.MAX_VALUE ) {
280-
return extractString( characterStream, Integer.MAX_VALUE );
281-
}
282-
else {
283-
return extractString( characterStream, (int) length );
284-
}
278+
final Reader characterStream = value.getCharacterStream();
279+
final long length = determineLengthForBufferSizing( value );
280+
return length > Integer.MAX_VALUE
281+
? extractString( characterStream, Integer.MAX_VALUE )
282+
: extractString( characterStream, (int) length );
285283
}
286284
catch ( SQLException e ) {
287285
throw new HibernateException( "Unable to access lob stream", e );
288286
}
289287
}
290288

289+
/**
290+
* Determine a buffer size for reading the underlying character stream.
291+
*
292+
* @param value The Clob value
293+
*
294+
* @return The appropriate buffer size ({@link java.sql.Clob#length()} by default.
295+
*
296+
* @throws SQLException
297+
*/
298+
private static long determineLengthForBufferSizing(Clob value) throws SQLException {
299+
try {
300+
return value.length();
301+
}
302+
catch ( SQLFeatureNotSupportedException e ) {
303+
return BUFFER_SIZE;
304+
}
305+
}
306+
291307
/**
292308
* Make sure we allocate a buffer sized not bigger than 2048,
293309
* not higher than what is actually needed, and at least one.
294310
*
295311
* @param lengthHint the expected size of the full value
296312
* @return the buffer size
297313
*/
298-
private static final int getSuggestedBufferSize(final int lengthHint) {
314+
private static int getSuggestedBufferSize(final int lengthHint) {
299315
return Math.max( 1, Math.min( lengthHint , BUFFER_SIZE ) );
300316
}
301317
}

0 commit comments

Comments
 (0)