Fix date cast exception (#13382)
After upgrading mysql-connector to 8.0.30 this exception was thrown: class java.time.LocalDateTime cannot be cast to class java.sql.Timestamp Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
parent
333ffbcba2
commit
474be93710
|
@ -14,6 +14,7 @@ package org.openhab.persistence.jdbc.db;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
@ -564,11 +565,17 @@ public class JdbcBaseDAO {
|
|||
}
|
||||
|
||||
protected ZonedDateTime objectAsDate(Object v) {
|
||||
if (v instanceof java.lang.String) {
|
||||
if (v instanceof LocalDateTime) {
|
||||
return ZonedDateTime.of((LocalDateTime) v, ZoneId.systemDefault());
|
||||
} else if (v instanceof java.sql.Timestamp) {
|
||||
return ZonedDateTime.ofInstant(((java.sql.Timestamp) v).toInstant(), ZoneId.systemDefault());
|
||||
} else if (v instanceof Instant) {
|
||||
return ZonedDateTime.ofInstant((Instant) v, ZoneId.systemDefault());
|
||||
} else if (v instanceof java.lang.String) {
|
||||
return ZonedDateTime.ofInstant(java.sql.Timestamp.valueOf(v.toString()).toInstant(),
|
||||
ZoneId.systemDefault());
|
||||
}
|
||||
return ZonedDateTime.ofInstant(((java.sql.Timestamp) v).toInstant(), ZoneId.systemDefault());
|
||||
throw new UnsupportedOperationException("Date of type " + v.getClass().getName() + " is not supported");
|
||||
}
|
||||
|
||||
protected Long objectAsLong(Object v) {
|
||||
|
|
Loading…
Reference in New Issue