From 6f0276ab2f5c8f6c8c65c919470dc62623503274 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Mon, 16 Nov 2015 11:39:52 +0530 Subject: [PATCH] Modified Application Mapping DAO classes --- .../mgt/core/dao/ApplicationMappingDAO.java | 2 +- .../dao/impl/ApplicationMappingDAOImpl.java | 18 +++++++++--------- .../main/resources/dbscripts/cdm/oracle.sql | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationMappingDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationMappingDAO.java index 372ea626ec6..e246c1c92b1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationMappingDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/ApplicationMappingDAO.java @@ -26,7 +26,7 @@ public interface ApplicationMappingDAO { int addApplicationMapping(int deviceId, int applicationId, int tenantId) throws DeviceManagementDAOException; - List addApplicationMappings(int deviceId, List applicationIds, int tenantId) + void addApplicationMappings(int deviceId, List applicationIds, int tenantId) throws DeviceManagementDAOException; void removeApplicationMapping(int deviceId, List appIdList, int tenantId) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java index 8e566117519..b9dff843a31 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationMappingDAOImpl.java @@ -49,7 +49,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { conn = this.getConnection(); String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " + "TENANT_ID) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + stmt = conn.prepareStatement(sql, new String[] {"id"}); stmt.setInt(1, deviceId); stmt.setInt(2, applicationId); stmt.setInt(3, tenantId); @@ -68,7 +68,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { } @Override - public List addApplicationMappings(int deviceId, List applicationIds, + public void addApplicationMappings(int deviceId, List applicationIds, int tenantId) throws DeviceManagementDAOException { Connection conn; PreparedStatement stmt = null; @@ -78,7 +78,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { conn = this.getConnection(); String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " + "TENANT_ID) VALUES (?, ?, ?)"; - stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + stmt = conn.prepareStatement(sql); for (int applicationId : applicationIds) { stmt.setInt(1, deviceId); @@ -88,11 +88,11 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { } stmt.executeBatch(); - rs = stmt.getGeneratedKeys(); - while (rs.next()) { - mappingIds.add(rs.getInt(1)); - } - return mappingIds; +// rs = stmt.getGeneratedKeys(); +// while (rs.next()) { +// mappingIds.add(rs.getInt(1)); +// } +// return mappingIds; } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while adding device application mappings", e); } finally { @@ -109,7 +109,7 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { conn = this.getConnection(); String sql = "DELETE DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " + "APPLICATION_ID = ? AND TENANT_ID = ?"; - stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + stmt = conn.prepareStatement(sql); for (Integer appId : appIdList) { stmt.setInt(1, deviceId); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 98735101ca0..2b33f64118e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -162,7 +162,7 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE ( OPERATION_RESPONSE BLOB DEFAULT NULL, CONSTRAINT PK_DM_DEVICE_OP_RESPONSE PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_OP_RES_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES - DM_DEVICE (ID), + DM_ENROLMENT (ID), CONSTRAINT FK_DM_DEVICE_OP_RES_OPERATION FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION (ID) )