2 * Copyright (c) 2010-2022 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.openhab.core.persistence.HistoricItem;
30 import org.openhab.core.types.State;
31 import org.openhab.core.types.UnDefType;
34 * This is the DAO object used for storing and retrieving to and from database.
36 * @author Manfred Bergmann - Initial contribution
41 @Table(name = "HISTORIC_ITEM")
42 public class JpaPersistentItem implements HistoricItem {
45 @GeneratedValue(strategy = GenerationType.AUTO)
48 private String name = "";
49 private String realName = "";
50 @Temporal(TemporalType.TIMESTAMP)
51 private Date timestamp = new Date();
52 @Column(length = 32672) // 32k, max varchar for apache derby
53 private String value = "";
59 public void setId(Long id) {
64 public String getName() {
68 public void setName(String name) {
72 public String getRealName() {
76 public void setRealName(String realName) {
77 this.realName = realName;
81 public ZonedDateTime getTimestamp() {
82 return ZonedDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault());
85 public void setTimestamp(Date timestamp) {
86 this.timestamp = timestamp;
89 public String getValue() {
93 public void setValue(String value) {
98 public State getState() {
99 return UnDefType.NULL;
103 public String toString() {
104 return DateFormat.getDateTimeInstance().format(getTimestamp()) + ": " + getName() + " -> " + value;