[jdbc] Fixed NPE when SQL query failed (#11954)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2022-01-04 10:37:04 +01:00 committed by GitHub
parent 845b57add9
commit ef46e126b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -342,10 +342,14 @@ public class JdbcBaseDAO {
String sql = histItemFilterQueryProvider(filter, numberDecimalcount, table, name, timeZone);
logger.debug("JDBC::doGetHistItemFilterQuery sql={}", sql);
List<Object[]> m = Yank.queryObjectArrays(sql, null);
if (m == null) {
logger.debug("JDBC::doGetHistItemFilterQuery Query failed. Returning an empty list.");
return List.of();
}
// we already retrieve the unit here once as it is a very costly operation
String itemName = item.getName();
Unit<? extends Quantity<?>> unit = item instanceof NumberItem ? ((NumberItem) item).getUnit() : null;
return m.stream().map(o -> new JdbcHistoricItem(itemName, getState(item, unit, o[1]), objectAsDate(o[0])))
return m.stream().map(o -> new JdbcHistoricItem(itemName, objectAsState(item, unit, o[1]), objectAsDate(o[0])))
.collect(Collectors.<HistoricItem> toList());
}
@ -489,7 +493,7 @@ public class JdbcBaseDAO {
/*****************
* H E L P E R S *
*****************/
protected State getState(Item item, @Nullable Unit<? extends Quantity<?>> unit, Object v) {
protected State objectAsState(Item item, @Nullable Unit<? extends Quantity<?>> unit, Object v) {
logger.debug(
"JDBC::ItemResultHandler::handleResult getState value = '{}', unit = '{}', getClass = '{}', clazz = '{}'",
v, unit, v.getClass(), v.getClass().getSimpleName());

View File

@ -169,7 +169,7 @@ public class JdbcDerbyDAO extends JdbcBaseDAO {
Unit<? extends Quantity<?>> unit = item instanceof NumberItem ? ((NumberItem) item).getUnit() : null;
return m.stream().map(o -> {
logger.debug("JDBC::doGetHistItemFilterQuery 0='{}' 1='{}'", o[0], o[1]);
return new JdbcHistoricItem(itemName, getState(item, unit, o[1]), objectAsDate(o[0]));
return new JdbcHistoricItem(itemName, objectAsState(item, unit, o[1]), objectAsDate(o[0]));
}).collect(Collectors.<HistoricItem> toList());
}