Merge "Data fragment update by xpath #2 - persistence layer"
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / entities / FragmentEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation. All rights reserved.
4  *  Modifications Copyright (C) 2021 Pantheon.tech
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.cps.spi.entities;
23
24 import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
25 import java.io.Serializable;
26 import java.util.Set;
27 import javax.persistence.CascadeType;
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.FetchType;
31 import javax.persistence.GeneratedValue;
32 import javax.persistence.GenerationType;
33 import javax.persistence.Id;
34 import javax.persistence.JoinColumn;
35 import javax.persistence.ManyToOne;
36 import javax.persistence.OneToMany;
37 import javax.persistence.OneToOne;
38 import javax.persistence.Table;
39 import javax.validation.constraints.NotNull;
40 import lombok.AllArgsConstructor;
41 import lombok.Builder;
42 import lombok.Data;
43 import lombok.Getter;
44 import lombok.NoArgsConstructor;
45 import lombok.Setter;
46 import org.hibernate.annotations.Type;
47 import org.hibernate.annotations.TypeDef;
48 import org.hibernate.annotations.TypeDefs;
49
50 /**
51  * Entity to store a fragment.
52  */
53 @Data
54 @Getter
55 @Setter
56 @AllArgsConstructor
57 @NoArgsConstructor
58 @Builder
59 @Entity
60 @Table(name = "fragment")
61 @TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)})
62 public class FragmentEntity implements Serializable {
63
64     private static final long serialVersionUID = 7737669789097119667L;
65
66     @Id
67     @GeneratedValue(strategy = GenerationType.IDENTITY)
68     private Long id;
69
70     @NotNull
71     @Column(columnDefinition = "text")
72     private String xpath;
73
74     @Type(type = "jsonb")
75     @Column(columnDefinition = "jsonb")
76     private String attributes;
77
78     @NotNull
79     @ManyToOne(fetch = FetchType.LAZY)
80     @JoinColumn(name = "dataspace_id")
81     private DataspaceEntity dataspace;
82
83     @OneToOne(fetch = FetchType.LAZY)
84     @JoinColumn(name = "anchor_id")
85     private AnchorEntity anchor;
86
87     @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
88     @JoinColumn(name = "parent_id")
89     private Set<FragmentEntity> childFragments;
90 }