Repository objects refactoring

SQL query is limited by 1, so there will be two cases - whether collection is empty or not. We should user convenient shortcut for checking emptiness of collection
This commit is contained in:
vraskulin 2016-12-19 11:30:32 +03:00
parent a5b2c9f8c0
commit e22951c68e
2 changed files with 4 additions and 4 deletions

View file

@ -71,7 +71,7 @@ public enum UserStatsRepository {
QueryBuilder<UserStats, Object> qb = dao.queryBuilder();
qb.limit(1L).where().eq("userName", userName);
List<UserStats> users = dao.query(qb.prepare());
if (users.size() == 1) {
if (!users.isEmpty()) {
return users.get(0);
}
} catch (SQLException ex) {
@ -95,7 +95,7 @@ public enum UserStatsRepository {
QueryBuilder<UserStats, Object> qb = dao.queryBuilder();
qb.orderBy("endTimeMs", false).limit(1L);
List<UserStats> users = dao.query(qb.prepare());
if (users.size() == 1) {
if (!users.isEmpty()) {
return users.get(0).getEndTimeMs();
}
} catch (SQLException ex) {

View file

@ -115,7 +115,7 @@ public enum ExpansionRepository {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.limit(1L).where().eq("code", new SelectArg(setCode));
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
if (expansions.size() > 0) {
if (!expansions.isEmpty()) {
set = expansions.get(0);
}
} catch (SQLException ex) {
@ -129,7 +129,7 @@ public enum ExpansionRepository {
QueryBuilder<ExpansionInfo, Object> qb = expansionDao.queryBuilder();
qb.limit(1L).where().eq("name", new SelectArg(setName));
List<ExpansionInfo> expansions = expansionDao.query(qb.prepare());
if (expansions.size() > 0) {
if (!expansions.isEmpty()) {
set = expansions.get(0);
}
} catch (SQLException ex) {