Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

HHH-7825 - org.hibernate.type.descriptor.java.DataHelper is incompati…

…ble with FireBird JDBC
  • Loading branch information...
commit caf2ee420c171ad23a4745a6777cf2694de72a5d 1 parent dd280b8
@sebersole sebersole authored
View
36 hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DataHelper.java
@@ -30,6 +30,7 @@
import java.io.StringReader;
import java.sql.Clob;
import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
import org.jboss.logging.Logger;
@@ -268,20 +269,17 @@ public static InputStream subStream(InputStream inputStream, long start, int len
/**
* Extract the contents of the given Clob as a string.
*
- * @param reader The reader for the content
+ * @param value The clob to to be extracted from
*
* @return The content as string
*/
public static String extractString(final Clob value) {
try {
- Reader characterStream = value.getCharacterStream();
- long length = value.length();
- if ( length > Integer.MAX_VALUE ) {
- return extractString( characterStream, Integer.MAX_VALUE );
- }
- else {
- return extractString( characterStream, (int) length );
- }
+ final Reader characterStream = value.getCharacterStream();
+ final long length = determineLengthForBufferSizing( value );
+ return length > Integer.MAX_VALUE
+ ? extractString( characterStream, Integer.MAX_VALUE )
+ : extractString( characterStream, (int) length );
}
catch ( SQLException e ) {
throw new HibernateException( "Unable to access lob stream", e );
@@ -289,13 +287,31 @@ public static String extractString(final Clob value) {
}
/**
+ * Determine a buffer size for reading the underlying character stream.
+ *
+ * @param value The Clob value
+ *
+ * @return The appropriate buffer size ({@link java.sql.Clob#length()} by default.
+ *
+ * @throws SQLException
+ */
+ private static long determineLengthForBufferSizing(Clob value) throws SQLException {
+ try {
+ return value.length();
+ }
+ catch ( SQLFeatureNotSupportedException e ) {
+ return BUFFER_SIZE;
+ }
+ }
+
+ /**
* Make sure we allocate a buffer sized not bigger than 2048,
* not higher than what is actually needed, and at least one.
*
* @param lengthHint the expected size of the full value
* @return the buffer size
*/
- private static final int getSuggestedBufferSize(final int lengthHint) {
+ private static int getSuggestedBufferSize(final int lengthHint) {
return Math.max( 1, Math.min( lengthHint , BUFFER_SIZE ) );
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.