Fix Derby/H2/HSQLDB/SQLite queries for storing timestamps (#13817)
Fixes #13816 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
383b5137e4
commit
e979be4911
|
@ -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<HistoricItem> doGetHistItemFilterQuery(Item item, FilterCriteria filter, int numberDecimalcount,
|
||||
String table, String name, ZoneId timeZone) throws JdbcSQLException {
|
||||
|
|
|
@ -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 *
|
||||
****************************/
|
||||
|
|
|
@ -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 *
|
||||
****************************/
|
||||
|
|
|
@ -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 *
|
||||
****************************/
|
||||
|
|
Loading…
Reference in New Issue