Only log about records with duplicate pump id.

This commit is contained in:
Johannes Mockenhaupt 2018-08-06 20:42:56 +02:00
parent 409acd0721
commit ca003fbdd7
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -381,16 +381,14 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
QueryBuilder<Treatment, Long> queryBuilder = getDao().queryBuilder();
Where where = queryBuilder.where();
where.eq("pumpId", pumpId);
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
List<Treatment> result = getDao().query(preparedQuery);
switch (result.size()) {
case 0:
return null;
case 1:
return result.get(0);
default:
throw new RuntimeException("Multiple records with the same pump id found: " + result.toString());
}
queryBuilder.orderBy("date", true);
List<Treatment> result = getDao().query(queryBuilder.prepare());
if (result.isEmpty())
return null;
if (result.size() > 1)
log.warn("Multiple records with the same pump id found (returning first one): " + result.toString());
return result.get(0);
} catch (SQLException e) {
throw new RuntimeException(e);
}