From 250c48a25886e1727b30696f5db0fc3767090ad6 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Mon, 19 Jan 2015 14:32:10 +0530 Subject: [PATCH] Fixed an issue of DeviceType and DeviceIdentifier. Implemented the getDeviceType method --- .../device/mgt/core/dao/DeviceTypeDAO.java | 3 +-- .../mgt/core/dao/impl/DeviceTypeDAOImpl.java | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java index 29c08d9ca2d..b6cc823418d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceTypeDAO.java @@ -17,7 +17,6 @@ */ package org.wso2.carbon.device.mgt.core.dao; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.util.List; @@ -33,7 +32,7 @@ public interface DeviceTypeDAO { List getDeviceTypes() throws DeviceManagementDAOException; - DeviceIdentifier getDeviceType() throws DeviceManagementDAOException; + DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException; Integer getDeviceTypeIdByDeviceTypeName(String type) throws DeviceManagementDAOException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java index 049ed042444..cbcbdd5447b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceTypeDAOImpl.java @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -90,9 +89,28 @@ public class DeviceTypeDAOImpl implements DeviceTypeDAO { } @Override - public DeviceIdentifier getDeviceType() throws DeviceManagementDAOException { - //TODO: - return null; + public DeviceType getDeviceType(Integer id) throws DeviceManagementDAOException { + Connection conn = this.getConnection(); + PreparedStatement stmt = null; + DeviceType deviceType = null; + try { + stmt = conn.prepareStatement("SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID=?"); + stmt.setInt(1, id); + ResultSet results = stmt.executeQuery(); + + while (results.next()) { + deviceType = new DeviceType(); + deviceType.setId(results.getLong("DEVICE_TYPE_ID")); + deviceType.setName(results.getString("DEVICE_TYPE")); + } + } catch (SQLException e) { + String msg = "Error occurred while fetching the registered device type"; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } finally { + DeviceManagementDAOUtil.cleanupResources(conn, stmt, null); + } + return deviceType; } @Override