From 7ab04b20a16de9dd2b847b22597aa8403175b69f Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 15 Aug 2023 13:24:29 +0200 Subject: [PATCH] [jdbc] Fix null annotation warnings (#15426) Signed-off-by: Jacob Laursen --- .../persistence/jdbc/internal/db/JdbcBaseDAO.java | 12 ++++++------ .../persistence/jdbc/internal/db/JdbcDerbyDAO.java | 12 ++++++------ .../jdbc/internal/db/JdbcPostgresqlDAO.java | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java index 16b1af647..a0fefaba2 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcBaseDAO.java @@ -542,15 +542,15 @@ public class JdbcBaseDAO { protected String resolveTimeFilter(FilterCriteria filter, ZoneId timeZone) { String filterString = ""; - if (filter.getBeginDate() != null) { + ZonedDateTime beginDate = filter.getBeginDate(); + if (beginDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME>='" + JDBC_DATE_FORMAT.format(filter.getBeginDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME>='" + JDBC_DATE_FORMAT.format(beginDate.withZoneSameInstant(timeZone)) + "'"; } - if (filter.getEndDate() != null) { + ZonedDateTime endDate = filter.getEndDate(); + if (endDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME<='" + JDBC_DATE_FORMAT.format(filter.getEndDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME<='" + JDBC_DATE_FORMAT.format(endDate.withZoneSameInstant(timeZone)) + "'"; } return filterString; } diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcDerbyDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcDerbyDAO.java index 527e673ed..10045d1ed 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcDerbyDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcDerbyDAO.java @@ -242,15 +242,15 @@ public class JdbcDerbyDAO extends JdbcBaseDAO { StringUtilsExt.filterToString(filter), numberDecimalcount, table, simpleName); String filterString = ""; - if (filter.getBeginDate() != null) { + ZonedDateTime beginDate = filter.getBeginDate(); + if (beginDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME>='" + JDBC_DATE_FORMAT.format(filter.getBeginDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME>='" + JDBC_DATE_FORMAT.format(beginDate.withZoneSameInstant(timeZone)) + "'"; } - if (filter.getEndDate() != null) { + ZonedDateTime endDate = filter.getEndDate(); + if (endDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME<='" + JDBC_DATE_FORMAT.format(filter.getEndDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME<='" + JDBC_DATE_FORMAT.format(endDate.withZoneSameInstant(timeZone)) + "'"; } filterString += (filter.getOrdering() == Ordering.ASCENDING) ? " ORDER BY time ASC" : " ORDER BY time DESC"; if (filter.getPageSize() != 0x7fffffff) { diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java index 3043354b0..8add63026 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcPostgresqlDAO.java @@ -260,15 +260,15 @@ public class JdbcPostgresqlDAO extends JdbcBaseDAO { filter.toString(), numberDecimalcount, table, simpleName); String filterString = ""; - if (filter.getBeginDate() != null) { + ZonedDateTime beginDate = filter.getBeginDate(); + if (beginDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME>='" + JDBC_DATE_FORMAT.format(filter.getBeginDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME>='" + JDBC_DATE_FORMAT.format(beginDate.withZoneSameInstant(timeZone)) + "'"; } - if (filter.getEndDate() != null) { + ZonedDateTime endDate = filter.getEndDate(); + if (endDate != null) { filterString += filterString.isEmpty() ? " WHERE" : " AND"; - filterString += " TIME<='" + JDBC_DATE_FORMAT.format(filter.getEndDate().withZoneSameInstant(timeZone)) - + "'"; + filterString += " TIME<='" + JDBC_DATE_FORMAT.format(endDate.withZoneSameInstant(timeZone)) + "'"; } filterString += (filter.getOrdering() == Ordering.ASCENDING) ? " ORDER BY time ASC" : " ORDER BY time DESC"; if (filter.getPageSize() != 0x7fffffff) {