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