diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcBaseDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcBaseDAO.java index 3025eef1b7b..b778ad48d06 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcBaseDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcBaseDAO.java @@ -342,10 +342,14 @@ public class JdbcBaseDAO { String sql = histItemFilterQueryProvider(filter, numberDecimalcount, table, name, timeZone); logger.debug("JDBC::doGetHistItemFilterQuery sql={}", sql); List 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> 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. toList()); } @@ -489,7 +493,7 @@ public class JdbcBaseDAO { /***************** * H E L P E R S * *****************/ - protected State getState(Item item, @Nullable Unit> unit, Object v) { + protected State objectAsState(Item item, @Nullable Unit> unit, Object v) { logger.debug( "JDBC::ItemResultHandler::handleResult getState value = '{}', unit = '{}', getClass = '{}', clazz = '{}'", v, unit, v.getClass(), v.getClass().getSimpleName()); diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcDerbyDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcDerbyDAO.java index c2e07d2bec9..ebfaa1c1382 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcDerbyDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/db/JdbcDerbyDAO.java @@ -169,7 +169,7 @@ public class JdbcDerbyDAO extends JdbcBaseDAO { Unit> 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. toList()); }