From 27279426f08b1466c4a2a427e6c3a798d04bd7ca Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 15 Jul 2015 11:02:54 +0530 Subject: [PATCH 1/3] code clean up --- .../mgt/core/service/DeviceManagementProviderServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 5ccb5c6410..dba0685429 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -704,7 +704,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } - public int getTenantId() { + private int getTenantId() { ThreadLocal tenantId = new ThreadLocal(); int tenant = 0; From 25a8f60d7400a6cce2664a5db3d22792669bf569 Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 15 Jul 2015 12:11:00 +0530 Subject: [PATCH 2/3] Retuen int for operations --- .../device/mgt/common/operation/mgt/OperationManager.java | 2 +- .../device/mgt/core/operation/mgt/OperationManagerImpl.java | 4 ++-- .../mgt/core/service/DeviceManagementProviderServiceImpl.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index c14f0e0e21..e953e2f1bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -36,7 +36,7 @@ public interface OperationManager { * @throws OperationManagementException If some unusual behaviour is observed while adding the * operation */ - public boolean addOperation(Operation operation, List devices) throws OperationManagementException; + public int addOperation(Operation operation, List devices) throws OperationManagementException; /** * Method to retrieve the list of all operations to a device. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index da551394e3..99116a4728 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -74,7 +74,7 @@ public class OperationManagerImpl implements OperationManager { } @Override - public boolean addOperation(Operation operation, + public int addOperation(Operation operation, List deviceIds) throws OperationManagementException { if (log.isDebugEnabled()) { @@ -105,7 +105,7 @@ public class OperationManagerImpl implements OperationManager { } } OperationManagementDAOFactory.commitTransaction(); - return true; + return operationId; } catch (OperationManagementDAOException e) { try { OperationManagementDAOFactory.rollbackTransaction(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index dba0685429..f5826d9cdf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -495,7 +495,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public boolean addOperation(Operation operation, List devices) throws + public int addOperation(Operation operation, List devices) throws OperationManagementException { return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices); } From a6cee6bae30915480debaad741eab3be2fe809d5 Mon Sep 17 00:00:00 2001 From: manoj Date: Wed, 15 Jul 2015 12:44:55 +0530 Subject: [PATCH 3/3] change update operation response to object --- .../mgt/dao/impl/OperationDAOImpl.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 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/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java index b2508080e0..d20b201293 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/OperationDAOImpl.java @@ -26,6 +26,9 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOE import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; import java.sql.*; import java.util.ArrayList; import java.util.Date; @@ -112,18 +115,43 @@ public class OperationDAOImpl implements OperationDAO { throws OperationManagementDAOException { PreparedStatement stmt = null; + ByteArrayOutputStream bao = null; + ObjectOutputStream oos = null; + try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement("INSERT INTO DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID,DEVICE_ID," + "OPERATION_RESPONSE) VALUES(?, ?, ?)"); + + bao = new ByteArrayOutputStream(); + oos = new ObjectOutputStream(bao); + oos.writeObject(operationResponse); + stmt.setInt(1, operationId); stmt.setInt(2, deviceId); - stmt.setObject(3, operationResponse); + stmt.setBytes(3, bao.toByteArray()); stmt.executeUpdate(); + } catch (SQLException e) { throw new OperationManagementDAOException("Error occurred while inserting operation response", e); - } finally { + }catch (IOException e) { + throw new OperationManagementDAOException("Error occurred while serializing policy operation object", e); + }finally { + if (bao != null) { + try { + bao.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ByteArrayOutputStream", e); + } + } + if (oos != null) { + try { + oos.close(); + } catch (IOException e) { + log.warn("Error occurred while closing ObjectOutputStream", e); + } + } OperationManagementDAOUtil.cleanupResources(stmt); } }