未验证 提交 f0385ff7 编写于 作者: W Weiyi Liu 提交者: GitHub

Remove & Simplfy redundancy code. (#4467)

Co-authored-by: wu-sheng's avatar吴晟 Wu Sheng <wu.sheng@foxmail.com>
上级 cbc69290
......@@ -101,19 +101,13 @@ public class H2AggregationQueryDAO implements IAggregationQueryDAO {
sql.append(" group by ").append(Metrics.ENTITY_ID);
sql.append(") order by value ").append(order.equals(Order.ASC) ? "asc" : "desc").append(" limit ").append(topN);
List<TopNEntity> topNEntities = new ArrayList<>();
try (Connection connection = h2Client.getConnection()) {
try (ResultSet resultSet = h2Client.executeQuery(connection, sql.toString(), conditions.toArray(new Object[0]))) {
try {
while (resultSet.next()) {
TopNEntity topNEntity = new TopNEntity();
topNEntity.setId(resultSet.getString(Metrics.ENTITY_ID));
topNEntity.setValue(resultSet.getLong("value"));
topNEntities.add(topNEntity);
}
} catch (SQLException e) {
throw new IOException(e);
}
try (Connection connection = h2Client.getConnection();
ResultSet resultSet = h2Client.executeQuery(connection, sql.toString(), conditions.toArray(new Object[0]))) {
while (resultSet.next()) {
TopNEntity topNEntity = new TopNEntity();
topNEntity.setId(resultSet.getString(Metrics.ENTITY_ID));
topNEntity.setValue(resultSet.getLong("value"));
topNEntities.add(topNEntity);
}
} catch (SQLException e) {
throw new IOException(e);
......
......@@ -60,18 +60,13 @@ public class MySQLAggregationQueryDAO extends H2AggregationQueryDAO {
sql.append(" order by value ").append(order.equals(Order.ASC) ? "asc" : "desc").append(" limit ").append(topN);
List<TopNEntity> topNEntities = new ArrayList<>();
try (Connection connection = getH2Client().getConnection()) {
try (ResultSet resultSet = getH2Client().executeQuery(connection, sql.toString(), conditions.toArray(new Object[0]))) {
try {
while (resultSet.next()) {
TopNEntity topNEntity = new TopNEntity();
topNEntity.setId(resultSet.getString(Metrics.ENTITY_ID));
topNEntity.setValue(resultSet.getLong("value"));
topNEntities.add(topNEntity);
}
} catch (SQLException e) {
throw new IOException(e);
}
try (Connection connection = getH2Client().getConnection();
ResultSet resultSet = getH2Client().executeQuery(connection, sql.toString(), conditions.toArray(new Object[0]))) {
while (resultSet.next()) {
TopNEntity topNEntity = new TopNEntity();
topNEntity.setId(resultSet.getString(Metrics.ENTITY_ID));
topNEntity.setValue(resultSet.getLong("value"));
topNEntities.add(topNEntity);
}
} catch (SQLException e) {
throw new IOException(e);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册