]> git.basschouten.com Git - openhab-addons.git/blob
139a7d9eca4d0beaa33c09ffaeb521783f306c0c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.persistence.jpa.internal.model;
14
15 import java.text.DateFormat;
16 import java.time.ZoneId;
17 import java.time.ZonedDateTime;
18 import java.util.Date;
19
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;
28
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;
33
34 /**
35  * This is the DAO object used for storing and retrieving to and from database.
36  *
37  * @author Manfred Bergmann - Initial contribution
38  *
39  */
40
41 @Entity
42 @Table(name = "HISTORIC_ITEM")
43 @NonNullByDefault
44 public class JpaPersistentItem implements HistoricItem {
45
46     @Id
47     @GeneratedValue(strategy = GenerationType.AUTO)
48     private @NonNullByDefault({}) Long id;
49
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 = "";
56
57     public Long getId() {
58         return id;
59     }
60
61     public void setId(Long id) {
62         this.id = id;
63     }
64
65     @Override
66     public String getName() {
67         return name;
68     }
69
70     public void setName(String name) {
71         this.name = name;
72     }
73
74     public String getRealName() {
75         return realName;
76     }
77
78     public void setRealName(String realName) {
79         this.realName = realName;
80     }
81
82     @Override
83     public ZonedDateTime getTimestamp() {
84         return ZonedDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault());
85     }
86
87     public void setTimestamp(Date timestamp) {
88         this.timestamp = timestamp;
89     }
90
91     public String getValue() {
92         return value;
93     }
94
95     public void setValue(String value) {
96         this.value = value;
97     }
98
99     @Override
100     public State getState() {
101         return UnDefType.NULL;
102     }
103
104     @Override
105     public String toString() {
106         return DateFormat.getDateTimeInstance().format(getTimestamp()) + ": " + getName() + " -> " + value;
107     }
108 }