From 77c4c3485830cda733fff66fbf472f79d38df45c Mon Sep 17 00:00:00 2001 From: prabathabey Date: Wed, 23 Dec 2015 18:13:39 +0530 Subject: [PATCH] Fixing https://wso2.org/jira/browse/EMM-1133 --- .../core/dao/impl/ApplicationMappingDAOImpl.java | 10 ++++------ .../mgt/core/dao/impl/EnrollmentDAOImpl.java | 14 ++------------ 2 files changed, 6 insertions(+), 18 deletions(-) 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 45154a54a2..1200c86b93 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 @@ -78,6 +78,8 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { conn = this.getConnection(); String sql = "INSERT INTO DM_DEVICE_APPLICATION_MAPPING (DEVICE_ID, APPLICATION_ID, " + "TENANT_ID) VALUES (?, ?, ?)"; + + conn.setAutoCommit(false); stmt = conn.prepareStatement(sql); for (int applicationId : applicationIds) { @@ -87,12 +89,6 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { stmt.addBatch(); } stmt.executeBatch(); - -// 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,6 +105,8 @@ public class ApplicationMappingDAOImpl implements ApplicationMappingDAO { conn = this.getConnection(); String sql = "DELETE DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID = ? AND " + "APPLICATION_ID = ? AND TENANT_ID = ?"; + + conn.setAutoCommit(false); stmt = conn.prepareStatement(sql); for (Integer appId : appIdList) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java index f3a5a58511..1998907b9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/EnrollmentDAOImpl.java @@ -76,7 +76,7 @@ public class EnrollmentDAOImpl implements EnrollmentDAO { String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " + "DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?" + " AND ID = ?"; - stmt = conn.prepareStatement(sql, new String[] {"id"}); + stmt = conn.prepareStatement(sql); stmt.setString(1, enrolmentInfo.getOwnership().toString()); stmt.setString(2, enrolmentInfo.getStatus().toString()); stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment())); @@ -86,11 +86,6 @@ public class EnrollmentDAOImpl implements EnrollmentDAO { stmt.setInt(7, tenantId); stmt.setInt(8, enrolmentInfo.getId()); stmt.executeUpdate(); - - rs = stmt.getGeneratedKeys(); - if (rs.next()) { - status = 1; - } return status; } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e); @@ -109,18 +104,13 @@ public class EnrollmentDAOImpl implements EnrollmentDAO { conn = this.getConnection(); String sql = "UPDATE DM_ENROLMENT SET OWNERSHIP = ?, STATUS = ?, " + "DATE_OF_ENROLMENT = ?, DATE_OF_LAST_UPDATE = ? WHERE ID = ?"; - stmt = conn.prepareStatement(sql, new String[] {"id"}); + stmt = conn.prepareStatement(sql); stmt.setString(1, enrolmentInfo.getOwnership().toString()); stmt.setString(2, enrolmentInfo.getStatus().toString()); stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment())); stmt.setTimestamp(4, new Timestamp(new Date().getTime())); stmt.setInt(5, enrolmentInfo.getId()); stmt.executeUpdate(); - - rs = stmt.getGeneratedKeys(); - if (rs.next()) { - status = 1; - } return status; } catch (SQLException e) { throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e);