Remove & Simplfy redundancy code. (#4467)

Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
This commit is contained in:
Weiyi Liu 2020-03-09 11:36:48 +08:00 committed by GitHub
parent cbc692908f
commit f0385ff7b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 25 deletions

View File

@ -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);

View File

@ -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);