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 a0c40efe0..1b110de9a 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 @@ -13,6 +13,7 @@ package org.openhab.persistence.jdbc.internal.db; import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -193,6 +194,22 @@ public class JdbcDerbyDAO extends JdbcBaseDAO { } } + @Override + public void doStoreItemValue(Item item, State itemState, ItemVO vo, ZonedDateTime date) throws JdbcSQLException { + ItemVO storedVO = storeItemValueProvider(item, itemState, vo); + String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue, + new String[] { "#tableName#", "#dbType#", "#tablePrimaryValue#" }, + new String[] { storedVO.getTableName().toUpperCase(), storedVO.getDbType(), "?" }); + java.sql.Timestamp timestamp = new java.sql.Timestamp(date.toInstant().toEpochMilli()); + Object[] params = { timestamp, storedVO.getValue() }; + logger.debug("JDBC::doStoreItemValue sql={} timestamp={} value='{}'", sql, timestamp, storedVO.getValue()); + try { + Yank.execute(sql, params); + } catch (YankSQLException e) { + throw new JdbcSQLException(e); + } + } + @Override public List doGetHistItemFilterQuery(Item item, FilterCriteria filter, int numberDecimalcount, String table, String name, ZoneId timeZone) throws JdbcSQLException { diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcH2DAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcH2DAO.java index 2bbdcf7eb..8b2ef9ff8 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcH2DAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcH2DAO.java @@ -12,6 +12,8 @@ */ package org.openhab.persistence.jdbc.internal.db; +import java.time.ZonedDateTime; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.knowm.yank.Yank; import org.knowm.yank.exceptions.YankSQLException; @@ -93,6 +95,22 @@ public class JdbcH2DAO extends JdbcBaseDAO { } } + @Override + public void doStoreItemValue(Item item, State itemState, ItemVO vo, ZonedDateTime date) throws JdbcSQLException { + ItemVO storedVO = storeItemValueProvider(item, itemState, vo); + String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue, + new String[] { "#tableName#", "#dbType#", "#tablePrimaryValue#" }, + new String[] { storedVO.getTableName(), storedVO.getDbType(), "?" }); + java.sql.Timestamp timestamp = new java.sql.Timestamp(date.toInstant().toEpochMilli()); + Object[] params = { timestamp, storedVO.getValue() }; + logger.debug("JDBC::doStoreItemValue sql={} timestamp={} value='{}'", sql, timestamp, storedVO.getValue()); + try { + Yank.execute(sql, params); + } catch (YankSQLException e) { + throw new JdbcSQLException(e); + } + } + /**************************** * SQL generation Providers * ****************************/ diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcHsqldbDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcHsqldbDAO.java index 35160585b..9fa66d1e5 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcHsqldbDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcHsqldbDAO.java @@ -12,6 +12,8 @@ */ package org.openhab.persistence.jdbc.internal.db; +import java.time.ZonedDateTime; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.knowm.yank.Yank; @@ -139,6 +141,22 @@ public class JdbcHsqldbDAO extends JdbcBaseDAO { } } + @Override + public void doStoreItemValue(Item item, State itemState, ItemVO vo, ZonedDateTime date) throws JdbcSQLException { + ItemVO storedVO = storeItemValueProvider(item, itemState, vo); + String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue, + new String[] { "#tableName#", "#dbType#", "#tableName#", "#tablePrimaryValue#" }, + new String[] { storedVO.getTableName(), storedVO.getDbType(), storedVO.getTableName(), "?" }); + java.sql.Timestamp timestamp = new java.sql.Timestamp(date.toInstant().toEpochMilli()); + Object[] params = { timestamp, storedVO.getValue() }; + logger.debug("JDBC::doStoreItemValue sql={} timestamp={} value='{}'", sql, timestamp, storedVO.getValue()); + try { + Yank.execute(sql, params); + } catch (YankSQLException e) { + throw new JdbcSQLException(e); + } + } + /**************************** * SQL generation Providers * ****************************/ diff --git a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcSqliteDAO.java b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcSqliteDAO.java index fc2888e79..27d869882 100644 --- a/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcSqliteDAO.java +++ b/bundles/org.openhab.persistence.jdbc/src/main/java/org/openhab/persistence/jdbc/internal/db/JdbcSqliteDAO.java @@ -12,6 +12,8 @@ */ package org.openhab.persistence.jdbc.internal.db; +import java.time.ZonedDateTime; + import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.knowm.yank.Yank; @@ -121,6 +123,22 @@ public class JdbcSqliteDAO extends JdbcBaseDAO { } } + @Override + public void doStoreItemValue(Item item, State itemState, ItemVO vo, ZonedDateTime date) throws JdbcSQLException { + ItemVO storedVO = storeItemValueProvider(item, itemState, vo); + String sql = StringUtilsExt.replaceArrayMerge(sqlInsertItemValue, + new String[] { "#tableName#", "#dbType#", "#tablePrimaryValue#" }, + new String[] { storedVO.getTableName(), storedVO.getDbType(), "?" }); + java.sql.Timestamp timestamp = new java.sql.Timestamp(date.toInstant().toEpochMilli()); + Object[] params = { timestamp, storedVO.getValue() }; + logger.debug("JDBC::doStoreItemValue sql={} timestamp={} value='{}'", sql, timestamp, storedVO.getValue()); + try { + Yank.execute(sql, params); + } catch (YankSQLException e) { + throw new JdbcSQLException(e); + } + } + /**************************** * SQL generation Providers * ****************************/