2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.rest.jpa;
24 import java.io.Serializable;
25 import java.util.Date;
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;
40 import lombok.EqualsAndHashCode;
45 * The Class PolicyVersion.
49 @Table(name = "PolicyVersion")
53 name = "PolicyVersion.findAll", query = "SELECT p FROM PolicyVersion p"
56 name = "PolicyVersion.deleteAll", query = "DELETE FROM PolicyVersion WHERE 1=1"
59 name = "PolicyVersion.findByPolicyName", query = "Select p from PolicyVersion p where p.policyName=:pname"
62 name = "PolicyVersion.findAllCount", query = "SELECT COUNT(p) FROM PolicyVersion p"
70 public class PolicyVersion implements Serializable {
71 private static final long serialVersionUID = 1L;
74 @GeneratedValue(strategy = GenerationType.AUTO)
79 @Column(name = "POLICY_NAME", nullable = false, length = 255)
80 private String policyName;
82 @Column(name = "ACTIVE_VERSION")
83 private int activeVersion;
85 @Column(name = "HIGHEST_VERSION")
86 private int higherVersion;
88 @Temporal(TemporalType.TIMESTAMP)
89 @Column(name = "created_date", nullable = false)
90 private Date createdDate;
92 @Column(name = "CREATED_BY", nullable = false, length = 45)
93 private String createdBy;
95 @Temporal(TemporalType.TIMESTAMP)
96 @Column(name = "modified_date", nullable = false)
97 private Date modifiedDate;
99 @Column(name = "modified_by", nullable = false, length = 45)
100 private String modifiedBy;
103 * Instantiates a new policy version.
105 public PolicyVersion() {
106 this.modifiedDate = new Date();
107 this.createdDate = new Date();
111 * Instantiates a new policy version.
113 * @param domain the domain
114 * @param loginUserId the login user id
116 public PolicyVersion(String domain, String loginUserId) {
118 this.createdBy = loginUserId;
119 this.modifiedBy = loginUserId;
123 * Instantiates a new policy version.
125 * @param domain the domain
127 public PolicyVersion(String domain) {
128 this.policyName = domain;
135 public void prePersist() {
136 Date date = new Date();
137 this.createdDate = date;
138 this.modifiedDate = date;
145 public void preUpdate() {
146 this.modifiedDate = new Date();