ec9e5b76b848dfe961eff04a7f18a86027feb594
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * feature-session-persistence
4  * ================================================================================
5  * Copyright (C) 2017-2018, 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.drools.persistence;
22
23 import java.io.Serializable;
24 import java.util.Date;
25 import javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.Id;
28 import javax.persistence.PrePersist;
29 import javax.persistence.PreUpdate;
30 import javax.persistence.Temporal;
31 import javax.persistence.TemporalType;
32
33 @Entity
34 public class DroolsSessionEntity implements Serializable, DroolsSession {
35
36     private static final long serialVersionUID = -5495057038819948709L;
37
38     @Id
39     @Column(name = "sessionName", nullable = false)
40     private String sessionName = "-1";
41
42     @Column(name = "sessionId", nullable = false)
43     private long sessionId = -1L;
44
45     @Temporal(TemporalType.TIMESTAMP)
46     @Column(name = "createdDate", nullable = false)
47     private Date createdDate;
48
49     @Temporal(TemporalType.TIMESTAMP)
50     @Column(name = "updatedDate", nullable = false)
51     private Date updatedDate;
52
53     public DroolsSessionEntity() {
54     }
55
56     public DroolsSessionEntity(String sessionName, long sessionId) {
57         this.sessionName = sessionName;
58         this.sessionId = sessionId;
59     }
60
61     @PrePersist
62     public void prePersist() {
63         this.createdDate = new Date();
64         this.updatedDate = new Date();
65     }
66
67     @PreUpdate
68     public void preUpdate() {
69         this.updatedDate = new Date();
70     }
71
72     @Override
73     public String getSessionName() {
74         return sessionName;
75     }
76
77     @Override
78     public void setSessionName(String sessionName) {
79         this.sessionName = sessionName;
80     }
81
82     @Override
83     public long getSessionId() {
84         return sessionId;
85     }
86
87     @Override
88     public void setSessionId(long sessionId) {
89         this.sessionId = sessionId;
90     }
91
92     @Override
93     public Date getCreatedDate() {
94         return createdDate;
95     }
96
97     @Override
98     public void setCreatedDate(Date createdDate) {
99         this.createdDate = createdDate;
100     }
101
102     @Override
103     public Date getUpdatedDate() {
104         return updatedDate;
105     }
106
107     @Override
108     public void setUpdatedDate(Date updatedDate) {
109         this.updatedDate = updatedDate;
110     }
111
112     @Override
113     public boolean equals(Object other) {
114         if (other instanceof DroolsSession) {
115             DroolsSession session = (DroolsSession) other;
116             return this.getSessionName().equals(session.getSessionName());
117         } else {
118             return false;
119         }
120     }
121
122     @Override
123     public int hashCode() {
124         final int prime = 31;
125         int result = 1;
126         result = prime * result + getSessionName().hashCode();
127         return result;
128     }
129
130     @Override
131     public String toString() {
132         return "{name=" + getSessionName() + ", id=" + getSessionId() + "}";
133     }
134 }