From 16f6a62dca64b1bd7c845b60bf99279f0706f285 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Sun, 23 Oct 2016 17:37:27 +0530 Subject: [PATCH] refactored DAO handler --- .../deployer/template/DeviceTypeManager.java | 18 +++++++++--------- .../dao/DeviceTypePluginDAOManager.java | 9 +++++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java index c31147bb5b..c52aff0a9d 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java @@ -222,13 +222,13 @@ public class DeviceTypeManager implements DeviceManager { if (isEnrolled) { this.modifyEnrollment(device); } else { - deviceTypePluginDAOManager.beginTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); status = deviceTypePluginDAOManager.getDeviceDAO().addDevice(device); - deviceTypePluginDAOManager.commitTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); } } catch (DeviceTypeMgtPluginException e) { try { - deviceTypePluginDAOManager.rollbackTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); } catch (DeviceTypeMgtPluginException ex) { String msg = "Error occurred while roll back the device enrol transaction :" + device.toString(); @@ -250,12 +250,12 @@ public class DeviceTypeManager implements DeviceManager { if (log.isDebugEnabled()) { log.debug("Modifying the Android device enrollment data"); } - deviceTypePluginDAOManager.beginTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(device); - deviceTypePluginDAOManager.commitTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); } catch (DeviceTypeMgtPluginException e) { try { - deviceTypePluginDAOManager.rollbackTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); } catch (DeviceTypeMgtPluginException mobileDAOEx) { String msg = "Error occurred while roll back the update device transaction :" + device.toString(); @@ -373,12 +373,12 @@ public class DeviceTypeManager implements DeviceManager { log.debug( "updating the details of " + deviceType + " device : " + device.getDeviceIdentifier()); } - deviceTypePluginDAOManager.beginTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(existingDevice); - deviceTypePluginDAOManager.commitTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); } catch (DeviceTypeMgtPluginException e) { try { - deviceTypePluginDAOManager.rollbackTransaction(); + deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); } catch (DeviceTypeMgtPluginException e1) { log.warn("Error occurred while roll back the update device info transaction : '" + device.toString() + "'", e1); diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java index d7c7b249c8..10a9b018b3 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/dao/DeviceTypePluginDAOManager.java @@ -22,17 +22,18 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.dao; public class DeviceTypePluginDAOManager { private DeviceTypePluginDAO deviceTypePluginDAO; + private DeviceTypeDAOHandler deviceTypeDAOHandler; public DeviceTypePluginDAOManager(String datasourceName, DeviceDAODefinition deviceDAODefinition) { - DeviceTypeDAOHandler deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName); + deviceTypeDAOHandler = new DeviceTypeDAOHandler(datasourceName); deviceTypePluginDAO = new DeviceTypePluginDAO(deviceDAODefinition, deviceTypeDAOHandler); } - - public DeviceTypePluginDAO getDeviceDAO() { return deviceTypePluginDAO; } - + public DeviceTypeDAOHandler getDeviceTypeDAOHandler() { + return deviceTypeDAOHandler; + } } \ No newline at end of file