Upgrade to Cassandra 3
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / DAOArtifactData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.resources.data;
22
23 import com.datastax.driver.mapping.annotations.Column;
24 import com.datastax.driver.mapping.annotations.PartitionKey;
25 import com.datastax.driver.mapping.annotations.Table;
26 import com.datastax.driver.mapping.annotations.Transient;
27
28 import java.nio.ByteBuffer;
29
30 @Table(keyspace = "sdcartifact", name = "resources")
31 public class DAOArtifactData {
32         public static final String RRESOURCE_ID_FIELD = "resourceId";
33
34         public static final String SERVICE_NAME_FIELD = "serviceName";
35         public static final String SERVICE_VERSION_FIELD = "serviceVersion";
36         public static final String ARTIFACT_NAME_FIELD = "artifactName";
37
38         public static String delim = ":";
39
40         @PartitionKey
41         @Column(name = "id")
42         private String id;
43
44         /*
45          * Base64 encoded Artifact file data
46          */
47
48         @Column
49         private ByteBuffer data;
50
51         // private byte[] data;
52
53         public DAOArtifactData() {
54
55         }
56
57         public DAOArtifactData(String id) {
58
59                 this.id = id;
60         }
61
62         public DAOArtifactData(String artifactId, byte[] data) {
63                 super();
64                 this.id = artifactId;
65                 if (data != null) {
66                         this.data = ByteBuffer.wrap(data.clone());
67                         // this.data = data.clone();
68                 }
69
70         }
71
72         @Transient
73         public byte[] getDataAsArray() {
74                 // return data;
75                 if (data != null) {
76                         return data.array();
77                 }
78                 return null;
79         }
80
81         public void setDataAsArray(byte[] data) {
82                 if (data != null) {
83                         // this.data = data.clone();
84                         this.data = ByteBuffer.wrap(data.clone());
85                 }
86         }
87
88         public ByteBuffer getData() {
89                 // return data;
90                 return data;
91         }
92
93         public void setData(ByteBuffer data) {
94                 if (data != null) {
95                         // this.data = data.clone();
96                         this.data = data.duplicate();
97                 }
98         }
99
100         public String getId() {
101                 return id;
102         }
103
104         public void setId(String id) {
105                 this.id = id;
106         }
107
108 }