From 85b1d4c7d1b9342180d5d10e43ec8b9edd8cec8c Mon Sep 17 00:00:00 2001 From: manoj Date: Thu, 2 Apr 2015 19:25:45 +0530 Subject: [PATCH] Add payload type to profile operation table --- .../mgt/dao/impl/ProfileOperationDAOImpl.java | 13 +++++++++++-- .../src/main/resources/dbscripts/cdm/h2.sql | 10 ++++++++++ 2 files changed, 21 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/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 72877487913..be8b880c812 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 @@ -128,15 +128,19 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { @Override public Operation getNextOperation(DeviceIdentifier deviceId) throws OperationManagementDAOException { + PreparedStatement stmt = null; ResultSet rs = null; ByteArrayInputStream bais; ObjectInputStream ois; + int operationId = 0; + String operationType = ""; + try { Connection connection = OperationManagementDAOFactory.getConnection(); stmt = connection.prepareStatement( "SELECT o.ID AS OPERATION_ID, o.CREATED_TIMESTAMP AS CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP AS " + - "RECEIVED_TIMESTAMP, po.PAYLOAD AS PAYLOAD FROM DM_OPERATION o " + + "RECEIVED_TIMESTAMP, po.PAYLOAD AS PAYLOAD,o.TYPE AS TYPE FROM DM_OPERATION o " + "INNER JOIN DM_PROFILE_OPERATION po ON o.ID = po.OPERATION_ID AND o.ID IN (" + "SELECT dom.OPERATION_ID FROM (SELECT d.ID FROM DM_DEVICE d INNER JOIN " + "DM_DEVICE_TYPE dm ON d.DEVICE_TYPE_ID = dm.ID AND dm.NAME = ? AND " + @@ -149,10 +153,15 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl { byte[] payload = new byte[0]; if (rs.next()) { payload = rs.getBytes("PAYLOAD"); + operationId = rs.getInt("OPERATION_ID"); + operationType = rs.getString("TYPE"); } bais = new ByteArrayInputStream(payload); ois = new ObjectInputStream(bais); - return (ProfileOperation) ois.readObject(); + ProfileOperation profileOperation = (ProfileOperation) ois.readObject(); + profileOperation.setId(operationId); + profileOperation.setType(Operation.Type.valueOf(operationType)); + return profileOperation; } catch (SQLException e) { throw new OperationManagementDAOException("Error occurred while adding operation metadata", e); } catch (ClassNotFoundException e) { diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 561e4a635cf..8e9d65270f1 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -27,6 +27,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( CREATED_TIMESTAMP TIMESTAMP NOT NULL, RECEIVED_TIMESTAMP TIMESTAMP NULL, STATUS VARCHAR(50) NULL, + PAYLOAD CLOB NULL, PRIMARY KEY (ID) ); @@ -45,6 +46,15 @@ CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION ( DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); +CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION ( + OPERATION_ID INTEGER NOT NULL, + ENABLED INTEGER NOT NULL DEFAULT 0, + PAYLOAD BLOB DEFAULT NULL, + PRIMARY KEY (OPERATION_ID), + CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES + DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); + CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL,