d7f2ba63d682bc44bbab62dfc40f562158a7e2f6
[sdc.git] /
1 /*
2 * Copyright © 2016-2018 European Support Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 package org.openecomp.core.tools.store;
19
20 import com.datastax.driver.mapping.Result;
21 import com.datastax.driver.mapping.annotations.Accessor;
22 import com.datastax.driver.mapping.annotations.Query;
23 import com.datastax.driver.mapping.annotations.QueryParameters;
24 import org.openecomp.core.nosqldb.api.NoSqlDb;
25 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
26 import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity;
27
28 import java.nio.ByteBuffer;
29 import java.util.Set;
30
31 public class ElementCassandraLoader {
32
33     private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
34     private static ElementAccessor accessor = noSqlDb.getMappingManager().createAccessor(ElementAccessor.class);
35
36     public void createEntity(ElementEntity elementEntity) {
37         accessor.insertElement(elementEntity.getSpace(),
38                 elementEntity.getItemId(),
39                 elementEntity.getVersionId(),
40                 elementEntity.getElementId(),
41                 elementEntity.getData(),
42                 elementEntity.getInfo(),
43                 elementEntity.getNamespace(),
44                 elementEntity.getParentId(),
45                 elementEntity.getRelations(),
46                 elementEntity.getSearchableData(),
47                 elementEntity.getSubElementIds());
48     }
49
50     public Result<ElementEntity> list() {
51         return accessor.getAll();
52     }
53     public Result<ElementEntity> getByPK(String space, String itemId, String versionId, String elementId,
54                                          String revisionId) {
55         return accessor.getByPK(space, itemId, versionId, elementId, revisionId);
56     }
57     @Accessor
58     interface ElementAccessor {
59
60         @Query("insert into  zusammen_dox.element (space,item_id,version_id,element_id,data,info," +
61                 "namespace,parent_id,relations,searchable_data,sub_element_ids) values (?,?,?,?,?,?,?,?,?,?,?)")
62         void insertElement(String space, String itemId, String versionId, String elementId, ByteBuffer data,
63                            String info, String namespaceStr, String parentId, String relations, ByteBuffer searchable,
64                            Set<String> subElementsIds);
65
66
67         @Query("select * from zusammen_dox.element ")
68         @QueryParameters(fetchSize = 100)
69         Result<ElementEntity> getAll();
70         @Query("select * from zusammen_dox.element where space = ? and item_id = ? and version_id = ? and " +
71                 "element_id = ? and revision_id = ?")
72         Result<ElementEntity> getByPK(String space, String itemId, String versionId, String elementId,
73                                       String revisionId);
74     }
75 }