2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.core.tools.store;
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;
32 import java.nio.ByteBuffer;
35 public class ElementCassandraLoader {
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"};
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());
58 public Result<ElementEntity> list() {
59 return accessor.getAll();
63 interface ElementAccessor {
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);
70 @Query("select * from zusammen_dox.element ")
71 @QueryParameters(fetchSize = 100)
72 Result<ElementEntity> getAll();