Menu

#1 Blobs not read from database

open
None
6
2007-02-13
2006-12-19
No

A field stored as a Blob in the database is not read by the application, as it assumes that all data is stored as Strings. IMHO the bug is here:

com.kneobase.driver.rdbms.Row
public Object getValue(String columnName)
--snip--
if (resultSet.getString(columnName) != null) {
return resultSet.getString(columnName);
}
--snip--

but it needs to take account of the possibility of Blobs:

--snip--
if (resultSet.getString(columnName) != null) {
return resultSet.getString(columnName);
} else if (resultSet.getBlob(columnName) != null) {
return resultSet.getBlob(columnName);
}
--snip--

The calling method also assumes a String, e.g.:

com.kneobase.driver.rdbms.RowAdapter
public InputStream getBodyInputStream(String columnName)
--snip--
String value = (String)(getRow().getValue(columnName));
--snip--

needs to be changed to something like this:

--snip--
String value = (String)(getRow().getValue(columnName));
if (value == null) {
java.sql.Blob value =
(java.sql.Blob)(getRow().getValue(columnName));
inputStream = value.getBinaryStream();
}
--snip--

I've tested this and it works fine now.

Finally the LinkBuilder will need to write the Blob to a fs location where it will be accessible via the link from the search results. I added setters and getters to SQLSourceCriteria, for a new field containing the path to the fs location, and configured fs-contents.xml with the new field. Then I added a method for writing the Blob's InputStream to a file:

--snip--
public void writeToFile(String path, Blob mrBlobby) {
try {
InputStream in = mrBlobby.getBinaryStream();
OutputStream out = new FileOutputStream(path);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e) {
//handle
}
}
--snip--

I put this in RowAdapter but there must be a better place for it.

--
Alastair Calderwood
acalderwood@zynap.com

Discussion

  • Mariano Barcia

    Mariano Barcia - 2007-02-01
    • priority: 5 --> 6
    • assigned_to: nobody --> desantisernesto
    • status: open --> open-accepted
     
  • Ernesto De Santis

    • status: open-accepted --> open
     
  • Ernesto De Santis

    Logged In: YES
    user_id=1072864
    Originator: NO

    Thanks for your code.

    I think change your code a little:

    if (resultSet.getString(columnName) != null) {
    return resultSet.getString(columnName);
    } else if (resultSet.getBlob(columnName) != null) {
    return resultSet.getBlob(columnName);
    }

    I think it isn't very well, if we want support more types in the future. A more flexible option could be config the type in the xml, String by default sure.

    Ernesto.

     

Log in to post a comment.