fix a bug in ClobProxy
Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
2d9f58ae4b
commit
d4b2d0fb9f
|
@ -97,17 +97,15 @@ public class ClobProxy implements InvocationHandler {
|
|||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
final String methodName = method.getName();
|
||||
final int argCount = method.getParameterCount();
|
||||
|
||||
if ( "length".equals( methodName ) && argCount == 0 ) {
|
||||
switch ( methodName ) {
|
||||
case "length":
|
||||
if ( argCount == 0 ) {
|
||||
return getLength();
|
||||
}
|
||||
if ( "getUnderlyingStream".equals( methodName ) ) {
|
||||
return getUnderlyingStream(); // Reset stream if needed.
|
||||
}
|
||||
if ( "getAsciiStream".equals( methodName ) && argCount == 0 ) {
|
||||
return getAsciiStream();
|
||||
}
|
||||
if ( "getCharacterStream".equals( methodName ) ) {
|
||||
break;
|
||||
case "getUnderlyingStream":
|
||||
return getUnderlyingStream(); // Reset stream if needed
|
||||
case "getCharacterStream":
|
||||
if ( argCount == 0 ) {
|
||||
return getCharacterStream();
|
||||
}
|
||||
|
@ -116,24 +114,30 @@ public class ClobProxy implements InvocationHandler {
|
|||
if ( start < 1 ) {
|
||||
throw new SQLException( "Start position 1-based; must be 1 or more." );
|
||||
}
|
||||
if ( start > getLength() ) {
|
||||
if ( start > getLength() + 1 ) {
|
||||
throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" );
|
||||
}
|
||||
final int length = (Integer) args[1];
|
||||
if ( length < 0 ) {
|
||||
// java docs specifically say for getCharacterStream(long,int) that the start+length must not exceed the
|
||||
// total length, however that is at odds with the getSubString(long,int) behavior.
|
||||
throw new SQLException( "Length must be great-than-or-equal to zero." );
|
||||
// javadoc for getCharacterStream(long,int) specify 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" );
|
||||
}
|
||||
return DataHelper.subStream( getCharacterStream(), start-1, length );
|
||||
}
|
||||
break;
|
||||
case "getAsciiStream":
|
||||
if ( argCount == 0 ) {
|
||||
return getAsciiStream();
|
||||
}
|
||||
if ( "getSubString".equals( methodName ) && argCount == 2 ) {
|
||||
break;
|
||||
case "getSubString":
|
||||
if ( argCount == 2 ) {
|
||||
final long start = (Long) args[0];
|
||||
if ( start < 1 ) {
|
||||
throw new SQLException( "Start position 1-based; must be 1 or more." );
|
||||
}
|
||||
if ( start > getLength() ) {
|
||||
if ( start > getLength() + 1 ) {
|
||||
throw new SQLException( "Start position [" + start + "] cannot exceed overall CLOB length [" + getLength() + "]" );
|
||||
}
|
||||
final int length = (Integer) args[1];
|
||||
|
@ -142,20 +146,29 @@ public class ClobProxy implements InvocationHandler {
|
|||
}
|
||||
return getSubString( start-1, length );
|
||||
}
|
||||
if ( "free".equals( methodName ) && argCount == 0 ) {
|
||||
break;
|
||||
case "free":
|
||||
if ( argCount == 0 ) {
|
||||
characterStream.release();
|
||||
return null;
|
||||
}
|
||||
if ( "toString".equals( methodName ) && argCount == 0 ) {
|
||||
break;
|
||||
case "toString":
|
||||
if ( argCount == 0 ) {
|
||||
return this.toString();
|
||||
}
|
||||
if ( "equals".equals( methodName ) && argCount == 1 ) {
|
||||
break;
|
||||
case "equals":
|
||||
if ( argCount == 1 ) {
|
||||
return proxy == args[0];
|
||||
}
|
||||
if ( "hashCode".equals( methodName ) && argCount == 0 ) {
|
||||
break;
|
||||
case "hashCode":
|
||||
if ( argCount == 0 ) {
|
||||
return this.hashCode();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
throw new UnsupportedOperationException( "Clob may not be manipulated from creating session" );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue