b3616c439de045cba9b76b0e8086103c8a176e04
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * feature-session-persistence
4  * ================================================================================
5  * Copyright (C) 2017 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
26 import javax.persistence.Column;
27 import javax.persistence.Entity;
28 import javax.persistence.Id;
29 import javax.persistence.PrePersist;
30 import javax.persistence.PreUpdate;
31 import javax.persistence.Temporal;
32 import javax.persistence.TemporalType;
33
34 @Entity
35 public class DroolsSessionEntity implements Serializable, DroolsSession {
36
37         private static final long serialVersionUID = -5495057038819948709L;
38
39         @Id
40         @Column(name = "sessionName", nullable = false)
41         private String sessionName = "-1";
42
43         @Column(name = "sessionId", nullable = false)
44         private long sessionId = -1L;
45
46         @Temporal(TemporalType.TIMESTAMP)
47         @Column(name = "createdDate", nullable = false)
48         private Date createdDate;
49
50         @Temporal(TemporalType.TIMESTAMP)
51         @Column(name = "updatedDate", nullable = false)
52         private Date updatedDate;
53
54         public DroolsSessionEntity() {
55
56         }
57
58         public DroolsSessionEntity(String sessionName, long sessionId) {
59                 this.sessionName = sessionName;
60                 this.sessionId = sessionId;
61
62         }
63
64         @PrePersist
65         public void prePersist() {
66                 this.createdDate = new Date();
67                 this.updatedDate = new Date();
68         }
69
70         @PreUpdate
71         public void preUpdate() {
72                 this.updatedDate = new Date();
73         }
74
75         @Override
76         public String getSessionName() {
77                 return sessionName;
78         }
79
80         @Override
81         public void setSessionName(String sessionName) {
82                 this.sessionName = sessionName;
83         }
84
85         @Override
86         public long getSessionId() {
87                 return sessionId;
88         }
89
90         @Override
91         public void setSessionId(long sessionId) {
92                 this.sessionId = sessionId;
93         }
94
95         @Override
96         public Date getCreatedDate() {
97                 return createdDate;
98         }
99
100         @Override
101         public void setCreatedDate(Date createdDate) {
102                 this.createdDate = createdDate;
103         }
104
105         @Override
106         public Date getUpdatedDate() {
107                 return updatedDate;
108         }
109
110         @Override
111         public void setUpdatedDate(Date updatedDate) {
112                 this.updatedDate = updatedDate;
113         }
114
115         @Override
116         public boolean equals(Object other) {
117                 if (other instanceof DroolsSession) {
118                         DroolsSession p = (DroolsSession) other;
119                         return this.getSessionName().equals(p.getSessionName());
120                 } else {
121                         return false;
122                 }
123         }
124
125         @Override
126         public int hashCode() {
127                 final int prime = 31;
128                 int result = 1;
129                 result = prime * result + getSessionName().hashCode();
130                 return result;
131         }
132
133         @Override
134         public String toString() {
135                 return "{name=" + getSessionName() + ", id=" + getSessionId() + "}";
136         }
137
138 }