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.util.Date;
25 import java.util.Objects;
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.GeneratedValue;
30 import javax.persistence.GenerationType;
31 import javax.persistence.Id;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.PrePersist;
35 import javax.persistence.PreUpdate;
36 import javax.persistence.Table;
37 import javax.persistence.Temporal;
38 import javax.persistence.TemporalType;
42 @Table(name="PolicyVersion")
44 @NamedQuery(name="PolicyVersion.findAll", query="SELECT p FROM PolicyVersion p"),
45 @NamedQuery(name="PolicyVersion.deleteAll", query="DELETE FROM PolicyVersion WHERE 1=1"),
46 @NamedQuery(name="PolicyVersion.findByPolicyName", query="Select p from PolicyVersion p where p.policyName=:pname"),
47 @NamedQuery(name="PolicyVersion.findAllCount", query="SELECT COUNT(p) FROM PolicyVersion p")
49 public class PolicyVersion implements Serializable {
50 private static final long serialVersionUID = 1L;
53 @GeneratedValue(strategy = GenerationType.AUTO)
58 @Column(name="POLICY_NAME", nullable=false, length=255)
59 private String policyName;
61 @Column(name="ACTIVE_VERSION")
62 private int activeVersion;
64 @Column(name="HIGHEST_VERSION")
65 private int higherVersion;
67 @Temporal(TemporalType.TIMESTAMP)
68 @Column(name="created_date", nullable=false)
69 private Date createdDate;
72 public int getActiveVersion() {
76 public void setActiveVersion(int activeVersion) {
77 this.activeVersion = activeVersion;
80 public int getHigherVersion() {
84 public void setHigherVersion(int higherVersion) {
85 this.higherVersion = higherVersion;
88 @Column(name="CREATED_BY", nullable=false, length=45)
89 private String createdBy;
91 @Temporal(TemporalType.TIMESTAMP)
92 @Column(name="modified_date", nullable=false)
93 private Date modifiedDate;
96 @Column(name="modified_by", nullable=false, length=45)
97 private String modifiedBy;
99 public PolicyVersion(String domain, String loginUserId) {
101 this.createdBy = loginUserId;
102 this.modifiedBy = loginUserId;
105 public PolicyVersion(String domain) {
106 this.policyName = domain;
109 public PolicyVersion(){
114 public void prePersist() {
115 Date date = new Date();
116 this.createdDate = date;
117 this.modifiedDate = date;
121 public void preUpdate() {
122 this.modifiedDate = new Date();
129 public void setId(int id) {
133 public String getPolicyName() {
137 public void setPolicyName(String policyName) {
138 this.policyName = policyName;
141 public Date getCreatedDate() {
145 public void setCreatedDate(Date createdDate) {
146 this.createdDate = createdDate;
149 public String getCreatedBy() {
153 public void setCreatedBy(String createdBy) {
154 this.createdBy = createdBy;
157 public Date getModifiedDate() {
161 public void setModifiedDate(Date modifiedDate) {
162 this.modifiedDate = modifiedDate;
165 public String getModifiedBy() {
169 public void setModifiedBy(String modifiedBy) {
170 this.modifiedBy = modifiedBy;
174 public int hashCode() {
175 return Objects.hash(id, policyName, activeVersion, higherVersion, createdDate,
176 createdBy, modifiedDate, modifiedBy);
180 public boolean equals(Object obj) {
187 if(!(obj instanceof PolicyVersion)){
191 PolicyVersion p = (PolicyVersion) obj;
194 policyName.equals(p.policyName) &&
195 activeVersion == p.activeVersion &&
196 higherVersion == p.higherVersion &&
197 createdDate.equals(p.createdDate) &&
198 createdBy.equals(p.createdBy) &&
199 modifiedDate.equals(p.modifiedDate) &&
200 modifiedBy.equals(p.modifiedBy);