Sonar cleanup
[policy/drools-pdp.git] / feature-active-standby-management / src / main / java / org / onap / policy / drools / activestandby / DroolsPdpEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * feature-active-standby-management
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.activestandby;
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.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.Temporal;
32 import javax.persistence.TemporalType;
33
34 import org.onap.policy.drools.activestandby.DroolsPdpObject;
35
36 @Entity
37 //@Table(name="DroolsPdpEntity")
38
39 @NamedQueries({
40         @NamedQuery(name="DroolsPdpEntity.findAll", query="SELECT e FROM DroolsPdpEntity e "),
41         @NamedQuery(name="DroolsPdpEntity.deleteAll", query="DELETE FROM DroolsPdpEntity WHERE 1=1")
42 })
43 public class DroolsPdpEntity extends DroolsPdpObject implements Serializable{
44
45         private static final long serialVersionUID = 1L;
46         
47         @Id
48         @Column(name="pdpId", nullable=false)
49         private String pdpId="-1";
50         
51         @Column(name="designated", nullable=false)
52         private boolean designated=false;
53         
54         @Column(name="priority", nullable=false)
55         private int priority=0;
56         
57         @Temporal(TemporalType.TIMESTAMP)
58         @Column(name="updatedDate", nullable=false)
59         private Date updatedDate;
60         
61         @Temporal(TemporalType.TIMESTAMP)
62         @Column(name="designatedDate",nullable=false)
63         private Date designatedDate;
64         
65         @Column(name="site", nullable=true, length = 50)
66         private String site;
67         
68         
69         public DroolsPdpEntity(){
70                 updatedDate = new Date();
71                 //When this is translated to a TimeStamp in MySQL, it assumes the date is relative
72                 //to the local timezone.  So, a value of Date(0) is actually Dec 31 18:00:00 CST 1969
73                 //which is an invalid value for the MySql TimeStamp 
74                 designatedDate = new Date(864000000);
75         }
76
77         @Override
78         public String getPdpId() {
79                 return this.pdpId;
80         }
81         
82         public void setPdpId(String pdpId) {
83                 this.pdpId = pdpId;
84         }
85         
86         @Override
87         public boolean isDesignated() {
88                 return this.designated;
89         }
90
91         @Override
92         public int getPriority() {
93                 return this.priority;
94         }
95
96         public void setPriority(int priority) {
97                 this.priority = priority;
98         }
99
100         @Override
101         public Date getUpdatedDate() {
102                 return this.updatedDate;
103         }
104
105         @Override
106         public void setDesignated(boolean isDesignated) {               
107                 this.designated=isDesignated;           
108         }
109
110         @Override
111         public void setUpdatedDate(Date updatedDate) {
112                 this.updatedDate=updatedDate;
113         }
114
115         
116         @Override
117         public String getSiteName() {
118                 return site;
119         }
120
121         @Override
122         public void setSiteName(String siteName) {
123                 site = siteName;
124                 
125         }
126
127         @Override
128         public Date getDesignatedDate() {
129                 return designatedDate;
130         }
131
132         @Override
133         public void setDesignatedDate(Date designatedDate) {
134                 this.designatedDate = designatedDate;           
135         }
136         
137         @Override
138         public boolean equals(Object obj){
139
140                 if (obj instanceof DroolsPdp) {
141                         DroolsPdpEntity d = (DroolsPdpEntity) obj;
142                         return this.pdpId.equals(d.getPdpId());
143                 } else {
144                         return false;
145                 }
146
147         }
148         
149         @Override
150         public int hashCode() {
151         final int prime = 31;
152         int result = 1;
153         result = prime * result + (this.pdpId == null ? 0 : this.pdpId.hashCode());
154                 return result;
155         }
156
157 }