From 2a3f7fe13a91b06f7dedbcbd155cbb07d418912b Mon Sep 17 00:00:00 2001 From: "David E. Jones" Date: Sun, 2 Dec 2007 01:20:52 +0000 Subject: [PATCH] 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 --- .../org/ofbiz/entity/jdbc/SqlJdbcUtil.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java b/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java index aed9946a7d..60177b86cf 100644 --- a/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java +++ b/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java @@ -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); + } } }