diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsTokenServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsTokenServiceImpl.java index ab81df77c7..e76ec4ebdd 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsTokenServiceImpl.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/WindowsTokenServiceImpl.java @@ -23,7 +23,7 @@ public class WindowsTokenServiceImpl implements WindowsTokenService { WindowsDAOFactory.beginTransaction(); windowsEnrollmentTokenDAO.addCacheToken(entry); WindowsDAOFactory.commitTransaction(); - } finally { + } finally { WindowsDAOFactory.closeConnection(); } } @@ -51,7 +51,8 @@ public class WindowsTokenServiceImpl implements WindowsTokenService { return cacheEntry; } - @Override public MobileCacheEntry getCacheTokenFromDeviceId(String deviceId) + @Override + public MobileCacheEntry getCacheTokenFromDeviceId(String deviceId) throws MobileDeviceManagementDAOException { MobileCacheEntry cacheEntry = null; try { diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dao/WindowsDAOFactory.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dao/WindowsDAOFactory.java index 760a8a5fd8..dab36a4b04 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dao/WindowsDAOFactory.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows/src/main/java/org/wso2/carbon/device/mgt/mobile/windows/impl/dao/WindowsDAOFactory.java @@ -20,8 +20,6 @@ package org.wso2.carbon.device.mgt.mobile.windows.impl.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.mobile.windows.exception.WindowsDeviceMgtPluginException; import org.wso2.carbon.device.mgt.mobile.windows.impl.dao.impl.WindowsDeviceDAOImpl; import org.wso2.carbon.device.mgt.mobile.windows.impl.dao.impl.WindowsFeatureDAOImpl; @@ -77,6 +75,15 @@ public class WindowsDAOFactory extends AbstractMobileDeviceManagementDAOFactory if (currentConnection.get() == null) { Connection conn; try { + if (dataSource == null) { + try { + String dataSourceName = "jdbc/MobileWindowsDM_DS"; + Context ctx = new InitialContext(); + dataSource = (DataSource) ctx.lookup(dataSourceName); + } catch (NamingException e) { + throw new MobileDeviceManagementDAOException("Error occurred while initializing datasource", e); + } + } conn = dataSource.getConnection(); currentConnection.set(conn); } catch (SQLException e) {