From 11d416cb824ba122eae8d8711335d032b6d3949a Mon Sep 17 00:00:00 2001 From: prabathabey Date: Thu, 26 Mar 2015 19:48:59 +0530 Subject: [PATCH] Fixing MobileDAOFactory initialization issues --- ...obileDeviceManagementServiceComponent.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java index d48753384..a00dd92c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/internal/MobileDeviceManagementServiceComponent.java @@ -25,7 +25,6 @@ import org.osgi.framework.ServiceRegistration; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.spi.DeviceManager; -import org.wso2.carbon.device.mgt.mobile.DataSourceListener; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceConfigurationManager; import org.wso2.carbon.device.mgt.mobile.config.MobileDeviceManagementConfig; import org.wso2.carbon.device.mgt.mobile.config.datasource.MobileDataSourceConfig; @@ -65,14 +64,6 @@ public class MobileDeviceManagementServiceComponent { try { BundleContext bundleContext = ctx.getBundleContext(); - /* Initialize the datasource configuration */ - MobileDeviceConfigurationManager.getInstance().initConfig(); - MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() - .getMobileDeviceManagementConfig(); - MobileDataSourceConfig dsConfig = - config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); - - MobileDeviceManagementDAOFactory.setDatSourceConfig(dsConfig); String setupOption = System.getProperty("setup"); if (setupOption != null) { if (log.isDebugEnabled()) { @@ -131,12 +122,25 @@ public class MobileDeviceManagementServiceComponent { /* This is to avoid mobile device management component getting initialized before the underlying datasources are registered */ try { - MobileDeviceManagementDAOFactory.init(); + initConfigs(); } catch (DeviceManagementException e) { log.error("Error occurred while initializing mobile device management repository datasource", e); } } + private void initConfigs() throws DeviceManagementException { + /* Initialize the datasource configuration */ + MobileDeviceConfigurationManager.getInstance().initConfig(); + + MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance() + .getMobileDeviceManagementConfig(); + MobileDataSourceConfig dsConfig = + config.getMobileDeviceMgtRepository().getMobileDataSourceConfig(); + + MobileDeviceManagementDAOFactory.setDatSourceConfig(dsConfig); + MobileDeviceManagementDAOFactory.init(); + } + protected void unsetDataSourceService(DataSourceService dataSourceService) { //do nothing }