in backend/src/main/java/org/apache/iotdb/admin/service/impl/IotDBServiceImpl.java [513:564]
public CountDTO getDevicesByGroup(
Connection connection, String groupName, Integer pageSize, Integer pageNum, String keyword)
throws BaseException {
SessionPool sessionPool = getSessionPool(connection);
String sql = "show devices " + groupName;
SessionDataSetWrapper sessionDataSetWrapper = null;
try {
sessionDataSetWrapper = sessionPool.executeQueryStatement(sql);
int batchSize = sessionDataSetWrapper.getBatchSize();
List<String> values = new ArrayList<>();
int count = 0;
if (batchSize > 0) {
while (sessionDataSetWrapper.hasNext()) {
RowRecord rowRecord = sessionDataSetWrapper.next();
List<org.apache.iotdb.tsfile.read.common.Field> fields = rowRecord.getFields();
if (keyword != null || "".equals(keyword)) {
String deviceName = fields.get(0).toString();
if (deviceName.contains(keyword)) {
count++;
} else {
continue;
}
if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) {
values.add(fields.get(0).toString());
}
} else {
count++;
if (count >= pageSize * (pageNum - 1) + 1 && count <= pageSize * pageNum) {
values.add(fields.get(0).toString());
}
}
}
}
CountDTO countDTO = new CountDTO();
countDTO.setObjects(values);
countDTO.setTotalCount(count);
Integer totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
countDTO.setTotalPage(totalPage);
return countDTO;
} catch (IoTDBConnectionException e) {
logger.error(e.getMessage());
throw new BaseException(
ErrorCode.GET_SQL_ONE_COLUMN_FAIL, ErrorCode.GET_SQL_ONE_COLUMN_FAIL_MSG);
} catch (StatementExecutionException e) {
logger.error(e.getMessage());
throw new BaseException(
ErrorCode.GET_SQL_ONE_COLUMN_FAIL, ErrorCode.GET_SQL_ONE_COLUMN_FAIL_MSG);
} finally {
closeResultSet(sessionDataSetWrapper);
closeSessionPool(sessionPool);
}
}