Skip to content

Commit 4dcfdb5

Browse files
committed
add missing @OverRide annotations, light refactoring
Signed-off-by: Gavin King <[email protected]>
1 parent f9e544e commit 4dcfdb5

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

hibernate-core/src/main/java/org/hibernate/engine/jdbc/proxy/BlobProxy.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ private InputStream getStream() throws SQLException {
6767
return getUnderlyingStream().getInputStream();
6868
}
6969

70+
@Override
7071
public BinaryStream getUnderlyingStream() throws SQLException {
7172
resetIfNeeded();
7273
return binaryStream;
@@ -172,15 +173,14 @@ public InputStream getBinaryStream(final long start, final long length) throws S
172173
throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + length() + "]" );
173174
}
174175
if ( length > Integer.MAX_VALUE ) {
175-
throw new SQLException( "Can't deal with Blobs larger than Integer.MAX_VALUE" );
176+
throw new SQLException( "Can't deal with Blobs larger than 'Integer.MAX_VALUE'" );
176177
}
177-
final int intLength = (int)length;
178-
if ( intLength < 0 ) {
179-
// java docs specifically say for getBinaryStream(long,int) that the start+length must not exceed the
180-
// total length, however that is at odds with the getBytes(long,int) behavior.
178+
if ( length < 0 ) {
179+
// javadoc for getBinaryStream(long,int) specifies that the start+length must not exceed the
180+
// total length (this is at odds with the behavior of getBytes(long,int))
181181
throw new SQLException( "Length must be great-than-or-equal to zero." );
182182
}
183-
return DataHelper.subStream( getStream(), start-1, intLength );
183+
return DataHelper.subStream( getStream(), start-1, (int)length );
184184
}
185185

186186
private static UnsupportedOperationException notSupported() {

hibernate-core/src/main/java/org/hibernate/engine/jdbc/proxy/ClobProxy.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,35 @@ public long position(String searchstr, long start) throws SQLException {
9292

9393
@Override
9494
public long position(Clob searchstr, long start) throws SQLException {
95-
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
95+
throw notSupported();
9696
}
9797

9898
@Override
9999
public int setString(long pos, String str) throws SQLException {
100-
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
100+
throw notSupported();
101101
}
102102

103103
@Override
104104
public int setString(long pos, String str, int offset, int len) throws SQLException {
105-
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
105+
throw notSupported();
106106
}
107107

108108
@Override
109109
public OutputStream setAsciiStream(long pos) {
110-
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
110+
throw notSupported();
111111
}
112112

113113
@Override
114114
public Writer setCharacterStream(long pos) {
115-
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
115+
throw notSupported();
116116
}
117117

118118
@Override
119119
public void truncate(long len) throws SQLException {
120-
throw new UnsupportedOperationException("Clob may not be manipulated from creating session");
120+
throw notSupported();
121121
}
122122

123+
@Override
123124
public String getSubString(long start, int length) throws SQLException {
124125
if ( start < 1 ) {
125126
throw new SQLException( "Start position 1-based; must be 1 or more." );
@@ -143,8 +144,11 @@ public Reader getCharacterStream(long start, long length) throws SQLException {
143144
if ( start > length() + 1 ) {
144145
throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + length() + "]" );
145146
}
147+
if ( length > Integer.MAX_VALUE ) {
148+
throw new SQLException( "Can't deal with Clobs larger than 'Integer.MAX_VALUE'" );
149+
}
146150
if ( length < 0 ) {
147-
// javadoc for getCharacterStream(long,int) specify that the start+length must not exceed the
151+
// javadoc for getCharacterStream(long,int) specifies that the start+length must not exceed the
148152
// total length (this is at odds with the behavior of getSubString(long,int))
149153
throw new SQLException( "Length must be greater than or equal to zero" );
150154
}
@@ -190,4 +194,8 @@ public static Clob generateProxy(String string) {
190194
public static Clob generateProxy(Reader reader, long length) {
191195
return new ClobProxy( reader, length );
192196
}
197+
198+
private static UnsupportedOperationException notSupported() {
199+
return new UnsupportedOperationException("Clob may not be manipulated from creating session");
200+
}
193201
}

0 commit comments

Comments
 (0)