9ac68567c8568bed8103bc133b509bc3da874117
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * feature-session-persistence
4  * ================================================================================
5  * Copyright (C) 2017-2018, 2020-2021 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 import lombok.EqualsAndHashCode;
33 import lombok.Getter;
34 import lombok.NoArgsConstructor;
35 import lombok.Setter;
36
37 @Entity
38 @Getter
39 @Setter
40 @EqualsAndHashCode(onlyExplicitlyIncluded = true)
41 @NoArgsConstructor
42 public class DroolsSessionEntity implements Serializable, DroolsSession {
43
44     private static final long serialVersionUID = -5495057038819948709L;
45
46     @Id
47     @Column(name = "sessionName", nullable = false)
48     @EqualsAndHashCode.Include
49     private String sessionName = "-1";
50
51     @Column(name = "sessionId", nullable = false)
52     private long sessionId = -1L;
53
54     @Temporal(TemporalType.TIMESTAMP)
55     @Column(name = "createdDate", nullable = false)
56     private Date createdDate;
57
58     @Temporal(TemporalType.TIMESTAMP)
59     @Column(name = "updatedDate", nullable = false)
60     private Date updatedDate;
61
62     public DroolsSessionEntity(String sessionName, long sessionId) {
63         this.sessionName = sessionName;
64         this.sessionId = sessionId;
65     }
66
67     @PrePersist
68     public void prePersist() {
69         this.createdDate = new Date();
70         this.updatedDate = new Date();
71     }
72
73     @PreUpdate
74     public void preUpdate() {
75         this.updatedDate = new Date();
76     }
77
78     @Override
79     public String toString() {
80         return "{name=" + getSessionName() + ", id=" + getSessionId() + "}";
81     }
82 }