1c7e185e181f176a98aadbb8a1bdec65256096b3
[sdc.git] /
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.core.tools.store;
22
23 import com.datastax.driver.mapping.Mapper;
24 import com.datastax.driver.mapping.Result;
25 import com.datastax.driver.mapping.annotations.Accessor;
26 import com.datastax.driver.mapping.annotations.Query;
27 import com.datastax.driver.mapping.annotations.QueryParameters;
28 import org.openecomp.core.nosqldb.api.NoSqlDb;
29 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
30 import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity;
31
32 import java.nio.ByteBuffer;
33 import java.util.Set;
34
35 public class ElementCassandraLoader {
36
37     private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
38     private static Mapper<ElementEntity> mapper = noSqlDb.getMappingManager().mapper(ElementEntity.class);
39     private static ElementAccessor accessor = noSqlDb.getMappingManager().createAccessor(ElementAccessor.class);
40     private String[] columns = {"space", "item_id", "version_id", "element_id", "data", "info", "namespace", "parent_id",
41             "relations", "searchable_data", "sub_element_ids"};
42
43
44     public void createEntity(ElementEntity elementEntity) {
45         accessor.insertElement(elementEntity.getSpace(),
46                 elementEntity.getItemId(),
47                 elementEntity.getVersionId(),
48                 elementEntity.getElement_id(),
49                 elementEntity.getData(),
50                 elementEntity.getInfo(),
51                 elementEntity.getNamespace(),
52                 elementEntity.getParentId(),
53                 elementEntity.getRelations(),
54                 elementEntity.getSearchableData(),
55                 elementEntity.getSubElementIds());
56     }
57
58     public Result<ElementEntity> list() {
59         return accessor.getAll();
60     }
61
62     @Accessor
63     interface ElementAccessor {
64
65         @Query("insert into  zusammen_dox.element (space,item_id,version_id,element_id,data,info,namespace,parent_id,relations,searchable_data,sub_element_ids) values (?,?,?,?,?,?,?,?,?,?,?)")
66         void insertElement(String space, String itemId, String versionId, String elementId, ByteBuffer data, String info, String namespaceStr,
67                            String parentId, String relations, ByteBuffer searchable, Set<String> subElementsIds);
68
69
70         @Query("select * from zusammen_dox.element ")
71         @QueryParameters(fetchSize = 100)
72         Result<ElementEntity> getAll();
73     }
74 }