add missing @Override annotations, light refactoring

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-11-04 15:35:42 +01:00
parent f9e544e394
commit 4dcfdb57e5
2 changed files with 21 additions and 13 deletions

View File

@ -67,6 +67,7 @@ public final class BlobProxy implements Blob, BlobImplementer {
return getUnderlyingStream().getInputStream();
}
@Override
public BinaryStream getUnderlyingStream() throws SQLException {
resetIfNeeded();
return binaryStream;
@ -172,15 +173,14 @@ public final class BlobProxy implements Blob, BlobImplementer {
throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + length() + "]" );
}
if ( length > Integer.MAX_VALUE ) {
throw new SQLException( "Can't deal with Blobs larger than Integer.MAX_VALUE" );
throw new SQLException( "Can't deal with Blobs larger than 'Integer.MAX_VALUE'" );
}
final int intLength = (int)length;
if ( intLength < 0 ) {
// java docs specifically say for getBinaryStream(long,int) that the start+length must not exceed the
// total length, however that is at odds with the getBytes(long,int) behavior.
if ( length < 0 ) {
// javadoc for getBinaryStream(long,int) specifies that the start+length must not exceed the
// total length (this is at odds with the behavior of getBytes(long,int))
throw new SQLException( "Length must be great-than-or-equal to zero." );
}
return DataHelper.subStream( getStream(), start-1, intLength );
return DataHelper.subStream( getStream(), start-1, (int)length );
}
private static UnsupportedOperationException notSupported() {

View File

@ -92,34 +92,35 @@ public class ClobProxy implements Clob, ClobImplementer {
@Override
public long position(Clob searchstr, long start) throws SQLException {
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
throw notSupported();
}
@Override
public int setString(long pos, String str) throws SQLException {
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
throw notSupported();
}
@Override
public int setString(long pos, String str, int offset, int len) throws SQLException {
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
throw notSupported();
}
@Override
public OutputStream setAsciiStream(long pos) {
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
throw notSupported();
}
@Override
public Writer setCharacterStream(long pos) {
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
throw notSupported();
}
@Override
public void truncate(long len) throws SQLException {
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
throw notSupported();
}
@Override
public String getSubString(long start, int length) throws SQLException {
if ( start < 1 ) {
throw new SQLException( "Start position 1-based; must be 1 or more." );
@ -143,8 +144,11 @@ public class ClobProxy implements Clob, ClobImplementer {
if ( start > length() + 1 ) {
throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + length() + "]" );
}
if ( length > Integer.MAX_VALUE ) {
throw new SQLException( "Can't deal with Clobs larger than 'Integer.MAX_VALUE'" );
}
if ( length < 0 ) {
// javadoc for getCharacterStream(long,int) specify that the start+length must not exceed the
// javadoc for getCharacterStream(long,int) specifies that the start+length must not exceed the
// total length (this is at odds with the behavior of getSubString(long,int))
throw new SQLException( "Length must be greater than or equal to zero" );
}
@ -190,4 +194,8 @@ public class ClobProxy implements Clob, ClobImplementer {
public static Clob generateProxy(Reader reader, long length) {
return new ClobProxy( reader, length );
}
private static UnsupportedOperationException notSupported() {
return new UnsupportedOperationException("Clob may not be manipulated from creating session");
}
}