]> git.basschouten.com Git - openhab-addons.git/blob
95f8ec77c1bafe4a0a306898ac9d86c75f7209b1
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.openhab.core.persistence.HistoricItem;
30 import org.openhab.core.types.State;
31 import org.openhab.core.types.UnDefType;
32
33 /**
34  * This is the DAO object used for storing and retrieving to and from database.
35  *
36  * @author Manfred Bergmann - Initial contribution
37  *
38  */
39
40 @Entity
41 @Table(name = "HISTORIC_ITEM")
42 public class JpaPersistentItem implements HistoricItem {
43
44     @Id
45     @GeneratedValue(strategy = GenerationType.AUTO)
46     private Long id;
47
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 = "";
54
55     public Long getId() {
56         return id;
57     }
58
59     public void setId(Long id) {
60         this.id = id;
61     }
62
63     @Override
64     public String getName() {
65         return name;
66     }
67
68     public void setName(String name) {
69         this.name = name;
70     }
71
72     public String getRealName() {
73         return realName;
74     }
75
76     public void setRealName(String realName) {
77         this.realName = realName;
78     }
79
80     @Override
81     public ZonedDateTime getTimestamp() {
82         return ZonedDateTime.ofInstant(timestamp.toInstant(), ZoneId.systemDefault());
83     }
84
85     public void setTimestamp(Date timestamp) {
86         this.timestamp = timestamp;
87     }
88
89     public String getValue() {
90         return value;
91     }
92
93     public void setValue(String value) {
94         this.value = value;
95     }
96
97     @Override
98     public State getState() {
99         return UnDefType.NULL;
100     }
101
102     @Override
103     public String toString() {
104         return DateFormat.getDateTimeInstance().format(getTimestamp()) + ": " + getName() + " -> " + value;
105     }
106 }