svn commit: r600224 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r600224 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java

jonesde
Author: jonesde
Date: Sat Dec  1 17:20:52 2007
New Revision: 600224

URL: http://svn.apache.org/viewvc?rev=600224&view=rev
Log:
Some more backward compatibility to use getBytes if getBlob fails; gotta love JDBC

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java?rev=600224&r1=600223&r2=600224&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/jdbc/SqlJdbcUtil.java Sat Dec  1 17:20:52 2007
@@ -549,26 +549,40 @@
                 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);
+                     }
                     }
                     }