|
|
@ -310,6 +310,71 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
|
|
|
|
return devices;
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Get the list of devices that matches with the given device name and (or) device type.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param deviceName Name of the device.
|
|
|
|
|
|
|
|
* @param tenantId Id of the current tenant
|
|
|
|
|
|
|
|
* @return device list
|
|
|
|
|
|
|
|
* @throws DeviceManagementDAOException
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<Device> getDevicesByNameAndType(String deviceName, String type, int tenantId, int offset, int limit)
|
|
|
|
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String filteringString = "";
|
|
|
|
|
|
|
|
if (deviceName != null && !deviceName.isEmpty()) {
|
|
|
|
|
|
|
|
filteringString = filteringString + " AND d.NAME LIKE ?";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (type != null && !type.isEmpty()) {
|
|
|
|
|
|
|
|
filteringString = filteringString + " AND t.NAME = ?";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String sql = "SELECT * FROM (SELECT ROWNUM offset, rs.* FROM (SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, " +
|
|
|
|
|
|
|
|
"d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, " +
|
|
|
|
|
|
|
|
"e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, " +
|
|
|
|
|
|
|
|
"(SELECT d.ID, d.NAME, d.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
|
|
|
|
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?" + filteringString +
|
|
|
|
|
|
|
|
") d1 WHERE d1.ID = e.DEVICE_ID) rs) WHERE offset >= ? AND ROWNUM <= ?";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (deviceName != null && !deviceName.isEmpty()) {
|
|
|
|
|
|
|
|
stmt.setString(++i, deviceName + "%");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (type != null && !type.isEmpty()) {
|
|
|
|
|
|
|
|
stmt.setString(++i, type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setInt(++i, offset);
|
|
|
|
|
|
|
|
stmt.setInt(++i, limit);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
Device device = DeviceManagementDAOUtil.loadDevice(rs);
|
|
|
|
|
|
|
|
devices.add(device);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices corresponding" +
|
|
|
|
|
|
|
|
"to the mentioned filtering criteria", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
return DeviceManagementDAOFactory.getConnection();
|
|
|
|
return DeviceManagementDAOFactory.getConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|