|
|
@ -18,10 +18,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.mgt.core.dao.impl;
|
|
|
|
package org.wso2.carbon.device.mgt.core.dao.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device.Status;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.OwnerShip;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
|
|
@ -53,11 +54,11 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
stmt.setString(2, device.getName());
|
|
|
|
stmt.setString(2, device.getName());
|
|
|
|
stmt.setLong(3, new Date().getTime());
|
|
|
|
stmt.setLong(3, new Date().getTime());
|
|
|
|
stmt.setLong(4, new Date().getTime());
|
|
|
|
stmt.setLong(4, new Date().getTime());
|
|
|
|
stmt.setString(5, device.getOwnership());
|
|
|
|
stmt.setString(5, device.getEnrolmentInfo().getOwnership().toString());
|
|
|
|
stmt.setString(6, device.getStatus().toString());
|
|
|
|
stmt.setString(6, device.getEnrolmentInfo().getStatus().toString());
|
|
|
|
stmt.setInt(7, typeId);
|
|
|
|
stmt.setInt(7, typeId);
|
|
|
|
stmt.setString(8, device.getDeviceIdentifier());
|
|
|
|
stmt.setString(8, device.getDeviceIdentifier());
|
|
|
|
stmt.setString(9, device.getOwner());
|
|
|
|
stmt.setString(9, device.getEnrolmentInfo().getOwner());
|
|
|
|
stmt.setInt(10, tenantId);
|
|
|
|
stmt.setInt(10, tenantId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -76,8 +77,8 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "UPDATE DM_DEVICE SET STATUS=?, OWNER=? WHERE DEVICE_IDENTIFICATION = ?";
|
|
|
|
String sql = "UPDATE DM_DEVICE SET STATUS=?, OWNER=? WHERE DEVICE_IDENTIFICATION = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, device.getStatus().toString());
|
|
|
|
stmt.setString(1, device.getEnrolmentInfo().getStatus().toString());
|
|
|
|
stmt.setString(2, device.getOwner());
|
|
|
|
stmt.setString(2, device.getEnrolmentInfo().getOwner());
|
|
|
|
stmt.setString(3, device.getDeviceIdentifier());
|
|
|
|
stmt.setString(3, device.getDeviceIdentifier());
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -108,27 +109,15 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql =
|
|
|
|
String sql =
|
|
|
|
"SELECT d.ID, d.DESCRIPTION, d.NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, " +
|
|
|
|
"SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, " +
|
|
|
|
"d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE dt WHERE " +
|
|
|
|
"d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE dt WHERE " +
|
|
|
|
"dt.NAME = ? AND d.DEVICE_IDENTIFICATION = ?";
|
|
|
|
"dt.NAME = ? AND d.DEVICE_IDENTIFICATION = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, deviceId.getType());
|
|
|
|
stmt.setString(1, deviceId.getType());
|
|
|
|
stmt.setString(2, deviceId.getId());
|
|
|
|
stmt.setString(2, deviceId.getId());
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
device = new Device();
|
|
|
|
device = this.loadDevice(rs);
|
|
|
|
device.setId(rs.getInt("ID"));
|
|
|
|
|
|
|
|
device.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
|
|
|
|
device.setName(rs.getString("NAME"));
|
|
|
|
|
|
|
|
device.setDateOfEnrolment(rs.getLong("DATE_OF_ENROLLMENT"));
|
|
|
|
|
|
|
|
device.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
|
|
|
|
|
|
|
|
//TODO:- Ownership is not a enum in DeviceDAO
|
|
|
|
|
|
|
|
device.setOwnership(rs.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
device.setStatus(Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
device.setDeviceType(deviceId.getType());
|
|
|
|
|
|
|
|
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
device.setOwner(rs.getString("OWNER"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while listing devices for type " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while listing devices for type " +
|
|
|
@ -144,30 +133,19 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
List<Device> devicesList = null;
|
|
|
|
List<Device> devices = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, " +
|
|
|
|
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, " +
|
|
|
|
"d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
|
|
|
|
"d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
|
|
|
|
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID, t.NAME AS DEVICE_TYPE_NAME FROM DM_DEVICE d, DEVICE_TYPE t " +
|
|
|
|
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID, t.NAME AS DEVICE_TYPE_NAME FROM DM_DEVICE d, DEVICE_TYPE t " +
|
|
|
|
"WHERE d.DEVICE_TYPE_ID = t.ID ";
|
|
|
|
"WHERE d.DEVICE_TYPE_ID = t.ID ";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
devicesList = new ArrayList<Device>();
|
|
|
|
devices = new ArrayList<Device>();
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
Device device = new Device();
|
|
|
|
Device device = this.loadDevice(rs);
|
|
|
|
device.setId(rs.getInt("DEVICE_ID"));
|
|
|
|
devices.add(device);
|
|
|
|
device.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
|
|
|
|
device.setName(rs.getString("DEVICE_NAME"));
|
|
|
|
|
|
|
|
device.setDateOfEnrolment(rs.getLong("DATE_OF_ENROLLMENT"));
|
|
|
|
|
|
|
|
device.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
|
|
|
|
|
|
|
|
//TODO:- Ownership is not a enum in DeviceDAO
|
|
|
|
|
|
|
|
device.setOwnership("OWNERSHIP");
|
|
|
|
|
|
|
|
device.setStatus(Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
device.setDeviceType("DEVICE_TYPE_NAME");
|
|
|
|
|
|
|
|
device.setDeviceIdentifier("DEVICE_IDENTIFICATION");
|
|
|
|
|
|
|
|
device.setOwner("OWNER");
|
|
|
|
|
|
|
|
devicesList.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving information of all " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving information of all " +
|
|
|
@ -175,7 +153,7 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return devicesList;
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -206,8 +184,8 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
public List<Device> getDevices(String type, int tenantId) throws DeviceManagementDAOException {
|
|
|
|
public List<Device> getDevices(String type, int tenantId) throws DeviceManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
List<Device> devicesList = null;
|
|
|
|
List<Device> devices = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String selectDBQueryForType = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
|
|
|
|
String selectDBQueryForType = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
|
|
|
@ -215,62 +193,41 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
"WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ?";
|
|
|
|
"WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ?";
|
|
|
|
stmt = conn.prepareStatement(selectDBQueryForType);
|
|
|
|
stmt = conn.prepareStatement(selectDBQueryForType);
|
|
|
|
stmt.setString(1, type);
|
|
|
|
stmt.setString(1, type);
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
devicesList = new ArrayList<Device>();
|
|
|
|
devices = new ArrayList<Device>();
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
Device device = new Device();
|
|
|
|
Device device = this.loadDevice(rs);
|
|
|
|
device.setId(resultSet.getInt("DEVICE_ID"));
|
|
|
|
devices.add(device);
|
|
|
|
device.setDescription(resultSet.getString("DESCRIPTION"));
|
|
|
|
|
|
|
|
device.setName(resultSet.getString("DEVICE_NAME"));
|
|
|
|
|
|
|
|
device.setDateOfEnrolment(resultSet.getLong("DATE_OF_ENROLLMENT"));
|
|
|
|
|
|
|
|
device.setDateOfLastUpdate(resultSet.getLong("DATE_OF_LAST_UPDATE"));
|
|
|
|
|
|
|
|
//TODO:- Ownership is not a enum in DeviceDAO
|
|
|
|
|
|
|
|
device.setOwnership(resultSet.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
device.setStatus(Status.valueOf(resultSet.getString("STATUS")));
|
|
|
|
|
|
|
|
device.setDeviceType(type);
|
|
|
|
|
|
|
|
device.setDeviceIdentifier(resultSet.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
device.setOwner(resultSet.getString("OWNER"));
|
|
|
|
|
|
|
|
devicesList.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e);
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return devicesList;
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override public List<Device> getDeviceListOfUser(String username, int tenantId) throws DeviceManagementDAOException {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Device> getDeviceListOfUser(String username, int tenantId) throws DeviceManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
List<Device> deviceList = new ArrayList<Device>();
|
|
|
|
List<Device> devices = new ArrayList<Device>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement(
|
|
|
|
stmt = conn.prepareStatement(
|
|
|
|
"SELECT t.NAME AS DEVICE_TYPE_NAME, d.ID AS DEVICE_ID, d.DESCRIPTION, " +
|
|
|
|
"SELECT t.NAME AS DEVICE_TYPE, d.ID AS DEVICE_ID, d.DESCRIPTION, " +
|
|
|
|
"d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
|
|
|
|
"d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
|
|
|
|
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM " +
|
|
|
|
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM " +
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
|
|
|
"AND d.OWNER =? AND d.TENANT_ID =?");
|
|
|
|
"AND d.OWNER =? AND d.TENANT_ID =?");
|
|
|
|
stmt.setString(1, username);
|
|
|
|
stmt.setString(1, username);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
ResultSet resultSet = stmt.executeQuery();
|
|
|
|
ResultSet rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
Device device = new Device();
|
|
|
|
Device device = this.loadDevice(rs);
|
|
|
|
device.setId(resultSet.getInt("DEVICE_ID"));
|
|
|
|
devices.add(device);
|
|
|
|
device.setDescription(resultSet.getString("DESCRIPTION"));
|
|
|
|
|
|
|
|
device.setName(resultSet.getString("DEVICE_NAME"));
|
|
|
|
|
|
|
|
device.setDateOfEnrolment(resultSet.getLong("DATE_OF_ENROLLMENT"));
|
|
|
|
|
|
|
|
device.setDateOfLastUpdate(resultSet.getLong("DATE_OF_LAST_UPDATE"));
|
|
|
|
|
|
|
|
//TODO:- Ownership is not a enum in DeviceDAO
|
|
|
|
|
|
|
|
device.setOwnership(resultSet.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
device.setStatus(Status.valueOf(resultSet.getString("STATUS")));
|
|
|
|
|
|
|
|
device.setDeviceType("DEVICE_TYPE_NAME");
|
|
|
|
|
|
|
|
device.setDeviceIdentifier("DEVICE_IDENTIFICATION");
|
|
|
|
|
|
|
|
device.setOwner("OWNER");
|
|
|
|
|
|
|
|
deviceList.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
|
|
@ -278,7 +235,7 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deviceList;
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws DeviceManagementDAOException {
|
|
|
|
private Connection getConnection() throws DeviceManagementDAOException {
|
|
|
@ -287,6 +244,7 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get device count of all devices.
|
|
|
|
* Get device count of all devices.
|
|
|
|
|
|
|
|
*
|
|
|
|
* @return device count
|
|
|
|
* @return device count
|
|
|
|
* @throws DeviceManagementDAOException
|
|
|
|
* @throws DeviceManagementDAOException
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -329,29 +287,17 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement(
|
|
|
|
stmt = conn.prepareStatement(
|
|
|
|
"SELECT d.ID AS DEVICE_ID, d.NAME AS DEVICE_NAME, t.ID AS DEVICE_TYPE_ID, d.DESCRIPTION, " +
|
|
|
|
"SELECT d.ID AS DEVICE_ID, d.NAME AS DEVICE_NAME, t.ID AS DEVICE_TYPE_ID, d.DESCRIPTION, " +
|
|
|
|
"t.NAME AS DEVICE_TYPE, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"t.NAME AS DEVICE_TYPE, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
|
|
|
|
"d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
|
|
|
|
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM " +
|
|
|
|
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM " +
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
|
|
|
"AND d.NAME LIKE ? AND d.TENANT_ID = ?");
|
|
|
|
"AND d.NAME LIKE ? AND d.TENANT_ID = ?");
|
|
|
|
stmt.setString(1, deviceName + "%");
|
|
|
|
stmt.setString(1, deviceName + "%");
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
ResultSet rs = stmt.executeQuery();
|
|
|
|
ResultSet rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
Device device = new Device();
|
|
|
|
Device device = this.loadDevice(rs);
|
|
|
|
DeviceType deviceType = new DeviceType();
|
|
|
|
|
|
|
|
deviceType.setId(rs.getInt("ID"));
|
|
|
|
|
|
|
|
deviceType.setName(rs.getString("DEVICE_NAME"));
|
|
|
|
|
|
|
|
device.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
|
|
|
|
device.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
|
|
|
|
device.setDateOfEnrolment(rs.getLong("DATE_OF_ENROLLMENT"));
|
|
|
|
|
|
|
|
device.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
|
|
|
|
|
|
|
|
device.setOwnership(rs.getString("OWNERSHIP"));
|
|
|
|
|
|
|
|
device.setStatus(Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
device.setDeviceType(rs.getString("DEVICE_TYPE"));
|
|
|
|
|
|
|
|
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
device.setOwner(rs.getString("OWNER"));
|
|
|
|
|
|
|
|
deviceList.add(device);
|
|
|
|
deviceList.add(device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -363,4 +309,25 @@ public class DeviceDAOImpl implements DeviceDAO {
|
|
|
|
return deviceList;
|
|
|
|
return deviceList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Device loadDevice(ResultSet rs) throws SQLException {
|
|
|
|
|
|
|
|
Device device = new Device();
|
|
|
|
|
|
|
|
DeviceType deviceType = new DeviceType();
|
|
|
|
|
|
|
|
deviceType.setId(rs.getInt("ID"));
|
|
|
|
|
|
|
|
deviceType.setName(rs.getString("DEVICE_NAME"));
|
|
|
|
|
|
|
|
device.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
|
|
|
|
device.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
|
|
|
|
device.setType(rs.getString("DEVICE_TYPE"));
|
|
|
|
|
|
|
|
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
|
|
|
|
|
|
|
|
enrolmentInfo.setDateOfEnrolment(rs.getLong("DATE_OF_ENROLLMENT"));
|
|
|
|
|
|
|
|
enrolmentInfo.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
|
|
|
|
|
|
|
|
enrolmentInfo.setOwnership(OwnerShip.valueOf(rs.getString("OWNERSHIP")));
|
|
|
|
|
|
|
|
enrolmentInfo.setStatus(Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
enrolmentInfo.setOwner(rs.getString("OWNER"));
|
|
|
|
|
|
|
|
device.setEnrolmentInfo(enrolmentInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return device;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|