Remove & Simplfy redundancy code. (#4467)
Co-authored-by: 吴晟 Wu Sheng <wu.sheng@foxmail.com>
This commit is contained in:
parent
cbc692908f
commit
f0385ff7b0
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue