Some more backward compatibility to use getBytes if getBlob fails; gotta love JDBC

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@600224 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David E. Jones
2007-12-02 01:20:52 +00:00
parent 828a4a3203
commit 2a3f7fe13a
@@ -549,26 +549,40 @@ public class SqlJdbcUtil {
case 11:
Object obj = null;
byte[] fieldBytes = rs.getBytes(ind);
obj = deserializeField(fieldBytes, ind, curField);
byte[] originalBytes = rs.getBytes(ind);
obj = deserializeField(originalBytes, ind, curField);
if (obj != null) {
entity.dangerousSetNoCheckButFast(curField, obj);
} else {
entity.dangerousSetNoCheckButFast(curField, fieldBytes);
entity.dangerousSetNoCheckButFast(curField, originalBytes);
}
break;
case 12:
Blob theBlob = rs.getBlob(ind);
Object originalObject;
byte[] fieldBytes;
try {
Blob theBlob = rs.getBlob(ind);
fieldBytes = theBlob != null ? theBlob.getBytes(1, (int) theBlob.length()) : null;
originalObject = theBlob;
} catch (SQLException e) {
// for backward compatibility if getBlob didn't work try getBytes
fieldBytes = rs.getBytes(ind);
originalObject = fieldBytes;
}
if (theBlob != null) {
if (originalObject != null) {
// for backward compatibility, check to see if there is a serialized object and if so return that
Object blobObject = deserializeField(theBlob.getBytes(1, (int) theBlob.length()), ind, curField);
Object blobObject = deserializeField(fieldBytes, ind, curField);
if (blobObject != null) {
entity.dangerousSetNoCheckButFast(curField, blobObject);
} else {
// NOTE using SerialBlob here instead of the Blob from the database to make sure we can pass it around, serialize it, etc
entity.dangerousSetNoCheckButFast(curField, new SerialBlob(theBlob));
if (originalObject instanceof Blob) {
// NOTE using SerialBlob here instead of the Blob from the database to make sure we can pass it around, serialize it, etc
entity.dangerousSetNoCheckButFast(curField, new SerialBlob((Blob) originalObject));
} else {
entity.dangerousSetNoCheckButFast(curField, originalObject);
}
}
}