SOLR-1794: Dataimport of CLOB fields fails when getCharacterStream() is defined in a superclass

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1024256 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2010-10-19 14:59:56 +00:00
parent a40d8d6a5d
commit ade778b533
2 changed files with 10 additions and 26 deletions

View File

@ -527,6 +527,9 @@ Bug Fixes
* SOLR-2157 Suggester should return alpha-sorted results when onlyMorePopular=false (ab)
* SOLR-1794: Dataimport of CLOB fields fails when getCharacterStream() is
defined in a superclass. (Gunnar Gauslaa Bergem via rmuir)
Other Changes
----------------------

View File

@ -22,11 +22,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.SQLException;
import java.util.Properties;
/**
@ -83,16 +81,7 @@ public class FieldReaderDataSource extends DataSource<Reader> {
} else if (o instanceof Blob) {
Blob blob = (Blob) o;
try {
//Most of the JDBC drivers have getBinaryStream defined as public
// so let us just check it
Method m = blob.getClass().getDeclaredMethod("getBinaryStream");
if (Modifier.isPublic(m.getModifiers())) {
return getReader(m, blob);
} else {
// force invoke
m.setAccessible(true);
return getReader(m, blob);
}
return getReader(blob);
} catch (Exception e) {
LOG.info("Unable to get data from BLOB");
return null;
@ -106,27 +95,19 @@ public class FieldReaderDataSource extends DataSource<Reader> {
static Reader readCharStream(Clob clob) {
try {
Method m = clob.getClass().getDeclaredMethod("getCharacterStream");
if (Modifier.isPublic(m.getModifiers())) {
return (Reader) m.invoke(clob);
} else {
// force invoke
m.setAccessible(true);
return (Reader) m.invoke(clob);
}
return clob.getCharacterStream();
} catch (Exception e) {
wrapAndThrow(SEVERE, e,"Unable to get reader from clob");
return null;//unreachable
}
}
private Reader getReader(Method m, Blob blob)
throws IllegalAccessException, InvocationTargetException, UnsupportedEncodingException {
InputStream is = (InputStream) m.invoke(blob);
private Reader getReader(Blob blob)
throws SQLException, UnsupportedEncodingException {
if (encoding == null) {
return (new InputStreamReader(is));
return (new InputStreamReader(blob.getBinaryStream()));
} else {
return (new InputStreamReader(is, encoding));
return (new InputStreamReader(blob.getBinaryStream(), encoding));
}
}