2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.rest.jpa;
23 import java.io.Serializable;
24 import java.sql.Timestamp;
25 import java.util.Date;
26 import java.util.Objects;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.GeneratedValue;
31 import javax.persistence.GenerationType;
32 import javax.persistence.Id;
33 import javax.persistence.NamedQueries;
34 import javax.persistence.NamedQuery;
35 import javax.persistence.PrePersist;
36 import javax.persistence.PreUpdate;
37 import javax.persistence.Table;
38 import javax.persistence.Temporal;
39 import javax.persistence.TemporalType;
43 @Table(name="PolicyVersion")
45 @NamedQuery(name="PolicyVersion.findAll", query="SELECT p FROM PolicyVersion p"),
46 @NamedQuery(name="PolicyVersion.deleteAll", query="DELETE FROM PolicyVersion WHERE 1=1"),
47 @NamedQuery(name="PolicyVersion.findByPolicyName", query="Select p from PolicyVersion p where p.policyName=:pname"),
48 @NamedQuery(name="PolicyVersion.findAllCount", query="SELECT COUNT(p) FROM PolicyVersion p")
50 public class PolicyVersion implements Serializable {
51 private static final long serialVersionUID = 1L;
54 @GeneratedValue(strategy = GenerationType.AUTO)
59 @Column(name="POLICY_NAME", nullable=false, length=255)
60 private String policyName;
62 @Column(name="ACTIVE_VERSION")
63 private int activeVersion;
65 @Column(name="HIGHEST_VERSION")
66 private int higherVersion;
68 @Temporal(TemporalType.TIMESTAMP)
69 @Column(name="created_date", nullable=false)
70 private Date createdDate;
73 public int getActiveVersion() {
77 public void setActiveVersion(int activeVersion) {
78 this.activeVersion = activeVersion;
81 public int getHigherVersion() {
85 public void setHigherVersion(int higherVersion) {
86 this.higherVersion = higherVersion;
89 @Column(name="CREATED_BY", nullable=false, length=45)
90 private String createdBy;
92 @Temporal(TemporalType.TIMESTAMP)
93 @Column(name="modified_date", nullable=false)
94 private Date modifiedDate;
97 @Column(name="modified_by", nullable=false, length=45)
98 private String modifiedBy;
100 public PolicyVersion(String domain, String loginUserId) {
102 this.createdBy = loginUserId;
103 this.modifiedBy = loginUserId;
106 public PolicyVersion(String domain) {
107 this.policyName = domain;
110 public PolicyVersion(){
115 public void prePersist() {
116 Date date = new Date();
117 this.createdDate = date;
118 this.modifiedDate = date;
122 public void preUpdate() {
123 this.modifiedDate = new Date();
130 public void setId(int id) {
134 public String getPolicyName() {
138 public void setPolicyName(String policyName) {
139 this.policyName = policyName;
142 public Date getCreatedDate() {
146 public void setCreatedDate(Timestamp createdDate) {
147 this.createdDate = createdDate;
150 public String getCreatedBy() {
154 public void setCreatedBy(String createdBy) {
155 this.createdBy = createdBy;
158 public Date getModifiedDate() {
162 public void setModifiedDate(Date modifiedDate) {
163 this.modifiedDate = modifiedDate;
166 public String getModifiedBy() {
170 public void setModifiedBy(String modifiedBy) {
171 this.modifiedBy = modifiedBy;
175 public int hashCode() {
176 return Objects.hash(id, policyName, activeVersion, higherVersion, createdDate,
177 createdBy, modifiedDate, modifiedBy);
181 public boolean equals(Object obj) {
188 if(!(obj instanceof PolicyVersion)){
192 PolicyVersion p = (PolicyVersion) obj;
195 policyName.equals(p.policyName) &&
196 activeVersion == p.activeVersion &&
197 higherVersion == p.higherVersion &&
198 createdDate.equals(p.createdDate) &&
199 createdBy.equals(p.createdBy) &&
200 modifiedDate.equals(p.modifiedDate) &&
201 modifiedBy.equals(p.modifiedBy);