18 package org.hibernate.engine.jdbc;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.Reader;
23 import java.io.StringReader;
24 import java.lang.reflect.InvocationHandler;
25 import java.lang.reflect.Method;
26 import java.lang.reflect.Proxy;
28 import java.sql.SQLException;
29 import org.hibernate.type.descriptor.java.DataHelper;
40 private static final Class[] PROXY_INTERFACES =
new Class[] { Clob.class, ClobImplementer.class };
42 private String string;
43 private Reader reader;
45 private boolean needsReset =
false;
56 reader =
new StringReader(
string);
57 length =
string.length();
78 return new ReaderInputStream( reader );
87 if (
string ==
null ) {
88 throw new UnsupportedOperationException(
"Clob was not created from string; cannot substring" );
91 int endIndex = Math.min( ((
int)start)+length,
string.length() );
92 return string.substring( (
int)start, endIndex );
101 @SuppressWarnings({
"UnnecessaryBoxing" })
103 public Object
invoke(Object proxy, Method method, Object[] args)
throws Throwable {
104 final String methodName = method.getName();
105 final int argCount = method.getParameterTypes().length;
107 if (
"length".equals( methodName ) && argCount == 0 ) {
110 if (
"getAsciiStream".equals( methodName ) && argCount == 0 ) {
113 if (
"getCharacterStream".equals( methodName ) ) {
114 if ( argCount == 0 ) {
117 else if ( argCount == 2 ) {
118 long start = (Long) args[0];
120 throw new SQLException(
"Start position 1-based; must be 1 or more." );
123 throw new SQLException(
"Start position [" + start +
"] cannot exceed overall CLOB length [" +
getLength() +
"]" );
125 int length = (Integer) args[1];
129 throw new SQLException(
"Length must be great-than-or-equal to zero." );
134 if (
"getSubString".equals( methodName ) && argCount == 2 ) {
135 long start = (Long) args[0];
137 throw new SQLException(
"Start position 1-based; must be 1 or more." );
141 throw new SQLException(
"Start position [" + start +
"] cannot exceed overall CLOB length [" +
getLength() +
"]" );
143 int length = (Integer) args[1];
145 throw new SQLException(
"Length must be great-than-or-equal to zero." );
149 if (
"free".equals( methodName ) && argCount == 0 ) {
153 if (
"toString".equals( methodName ) && argCount == 0 ) {
154 return this.toString();
156 if (
"equals".equals( methodName ) && argCount == 1 ) {
157 return Boolean.valueOf( proxy == args[0] );
159 if (
"hashCode".equals( methodName ) && argCount == 0 ) {
160 return new Integer( this.hashCode() );
163 throw new UnsupportedOperationException(
"Clob may not be manipulated from creating session" );
172 catch ( IOException ioe ) {
173 throw new SQLException(
"could not reset reader" );
214 ClassLoader cl = Thread.currentThread().getContextClassLoader();
216 cl = ClobImplementer.class.getClassLoader();
static Clob generateProxy(String string)
InputStream getAsciiStream()
ClobProxy_360(String string)
static Clob generateProxy(Reader reader, long length)
Object invoke(Object proxy, Method method, Object[] args)
static ClassLoader getProxyClassLoader()
ClobProxy_360(Reader reader, long length)
String getSubString(long start, int length)
Reader getCharacterStream()