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 29c08d9ca2..b6cc823418 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 049ed04244..cbcbdd5447 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