2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.openecomp.core.tools.store;
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;
28 import java.nio.ByteBuffer;
31 public class ElementCassandraLoader {
33 private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
34 private static ElementAccessor accessor = noSqlDb.getMappingManager().createAccessor(ElementAccessor.class);
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());
50 public Result<ElementEntity> list() {
51 return accessor.getAll();
53 public Result<ElementEntity> getByPK(String space, String itemId, String versionId, String elementId,
55 return accessor.getByPK(space, itemId, versionId, elementId, revisionId);
58 interface ElementAccessor {
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);
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,