mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[jdbc] Fixed NPE when SQL query failed (#11954)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
845b57add9
commit
ef46e126b4
@ -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());
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user