d1557489c34bce0312b5bd9a9bfe7f99ec84562a
[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 javax.persistence.Column;
26 import javax.persistence.Entity;
27 import javax.persistence.FetchType;
28 import javax.persistence.GeneratedValue;
29 import javax.persistence.GenerationType;
30 import javax.persistence.Id;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.ManyToOne;
33 import javax.persistence.OneToOne;
34 import javax.validation.constraints.NotNull;
35 import lombok.AllArgsConstructor;
36 import lombok.Builder;
37 import lombok.Getter;
38 import lombok.NoArgsConstructor;
39 import lombok.Setter;
40 import org.hibernate.annotations.Type;
41 import org.hibernate.annotations.TypeDef;
42 import org.hibernate.annotations.TypeDefs;
43
44 /**
45  * Entity to store a fragment.
46  */
47 @Getter
48 @Setter
49 @AllArgsConstructor
50 @NoArgsConstructor
51 @Builder
52 @Entity
53 @TypeDefs({@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)})
54 public class FragmentEntity implements Serializable {
55
56     private static final long serialVersionUID = 7737669789097119667L;
57
58     @Id
59     @GeneratedValue(strategy = GenerationType.IDENTITY)
60     private Long id;
61
62     @NotNull
63     @Column(columnDefinition = "text")
64     private String xpath;
65
66     @Type(type = "jsonb")
67     @Column(columnDefinition = "jsonb")
68     private String attributes;
69
70     @NotNull
71     @ManyToOne(fetch = FetchType.LAZY)
72     @JoinColumn(name = "dataspace_id")
73     private DataspaceEntity dataspace;
74
75     @OneToOne(fetch = FetchType.LAZY)
76     @JoinColumn(name = "anchor_id")
77     private AnchorEntity anchor;
78
79     @OneToOne(fetch = FetchType.LAZY)
80     @JoinColumn(name = "parent_id")
81     private FragmentEntity parentFragment;
82 }