Skip to content

Commit 50fc5f2

Browse files
Fix pr comments
1 parent 2fe7852 commit 50fc5f2

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/main/java/main/model/db/dao/DAO.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,8 @@ public T getEntityById(Integer id) throws AqualityException {
9696

9797
List<Pair<String, String>> parameters = entity.getIdSearchParameters(id);
9898
List<T> all = dtoMapper.mapObjects(CallStoredProcedure(select, parameters).toString());
99-
if(!all.isEmpty()) {
100-
return all.get(0);
101-
}
102-
else{
103-
throw new AqualityException("No Entities was found by id");
104-
}
99+
100+
return getSingleResult(all, id);
105101
}
106102

107103
/**
@@ -112,12 +108,8 @@ public T getEntityById(Integer id) throws AqualityException {
112108
public T getEntityById(T entity) throws AqualityException {
113109
List<Pair<String, String>> parameters = entity.getIdAndProjectIdSearchParameters();
114110
List<T> all = dtoMapper.mapObjects(CallStoredProcedure(select, parameters).toString());
115-
if(!all.isEmpty()) {
116-
return all.get(0);
117-
}
118-
else{
119-
throw new AqualityException("No Entities was found by id");
120-
}
111+
112+
return getSingleResult(all, entity.getIdOrOverrideId());
121113
}
122114

123115
/**
@@ -225,6 +217,15 @@ protected JSONArray CallStoredProcedure(String sql, List<Pair<String, String>> p
225217
return json;
226218
}
227219

220+
private T getSingleResult(List<T> allResults, Integer id) throws AqualityException {
221+
if(!allResults.isEmpty()) {
222+
return allResults.get(0);
223+
}
224+
else{
225+
throw new AqualityException("No Entities was found by '%s' id", id);
226+
}
227+
}
228+
228229
private void getConnection() throws AqualityException {
229230
InitialContext initialContext;
230231
try {

0 commit comments

Comments
 (0)