2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.persistence.jpa.internal.model;
15 import java.text.DateFormat;
16 import java.time.ZoneId;
17 import java.time.ZonedDateTime;
18 import java.util.Date;
20 import javax.persistence.Column;
21 import javax.persistence.Entity;
22 import javax.persistence.GeneratedValue;
23 import javax.persistence.GenerationType;
24 import javax.persistence.Id;
25 import javax.persistence.Table;
26 import javax.persistence.Temporal;
27 import javax.persistence.TemporalType;
29 import org.eclipse.jdt.annotation.NonNullByDefault;
30 import org.openhab.core.persistence.HistoricItem;
31 import org.openhab.core.types.State;
32 import org.openhab.core.types.UnDefType;
35 * This is the DAO object used for storing and retrieving to and from database.
37 * @author Manfred Bergmann - Initial contribution
42 @Table(name = "HISTORIC_ITEM")
44 public class JpaPersistentItem implements HistoricItem {
47 @GeneratedValue(strategy = GenerationType.AUTO)
48 private @NonNullByDefault({}) Long id;
50 private String name = "";
51 private String realName = "";
52 @Temporal(TemporalType.TIMESTAMP)
53 private Date timestamp = new Date();
54 @Column(length = 32672) // 32k, max varchar for apache derby
55 private String value = "";
61 public void setId(Long id) {
66 public String getName() {
70 public void setName(String name) {
74 public String getRealName() {
78 public void setRealName(String realName) {
79 this.realName = realName;
83 public ZonedDateTime getTimestamp() {
84 return ZonedDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault());
87 public void setTimestamp(Date timestamp) {
88 this.timestamp = timestamp;
91 public String getValue() {
95 public void setValue(String value) {
100 public State getState() {
101 return UnDefType.NULL;
105 public String toString() {
106 return DateFormat.getDateTimeInstance().format(getTimestamp()) + ": " + getName() + " -> " + value;