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