From 749f2b782ed17526ff8e3869717e23e160e45eb4 Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 8 Apr 2015 17:30:06 +0530 Subject: [PATCH] Change blob read method --- .../mgt/dao/impl/ProfileOperationDAOImpl.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index 8e81370982..8a4355e36f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -133,7 +133,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { PreparedStatement stmt = null; ResultSet rs = null; ByteArrayInputStream bais; - ObjectInputStream ois; + ObjectOutputStream objectOutputStream; try { Connection connection = OperationManagementDAOFactory.openConnection(); @@ -149,13 +149,21 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { stmt.setString(2, deviceId.getId()); rs = stmt.executeQuery(); - byte[] operationObjbyteArr = new byte[0]; + byte[] operationObjbyteArr; + Blob operationBlob; + ByteArrayInputStream in; + ObjectInputStream is; + if (rs.next()) { - operationObjbyteArr = rs.getBytes("OPERATIONDETAILS"); + operationBlob = rs.getBlob("OPERATIONDETAILS"); + operationObjbyteArr = operationBlob.getBytes(1, (int) operationBlob.length()); + in = new ByteArrayInputStream(operationObjbyteArr); + is = new ObjectInputStream(in); + return (ProfileOperation) is.readObject(); + }else{ + return null; } - bais = new ByteArrayInputStream(operationObjbyteArr); - ois = new ObjectInputStream(bais); - return (ProfileOperation) ois.readObject(); + } catch (SQLException e) { log.error("SQL error occurred while retrieving profile operation", e); throw new OperationManagementDAOException("Error occurred while adding operation metadata", e);