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 com.google.common.collect.Sets;
29 import org.openecomp.core.nosqldb.api.NoSqlDb;
30 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
31 import org.openecomp.core.tools.store.zusammen.datatypes.ElementEntity;
32 import org.openecomp.core.tools.store.zusammen.datatypes.VersionEntity;
34 import java.util.Date;
37 public class VersionCassandraLoader {
39 private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
40 private static Mapper<VersionEntity> mapper = noSqlDb.getMappingManager().mapper(VersionEntity.class);
41 private static VersionAccessor accessor = noSqlDb.getMappingManager().createAccessor(VersionAccessor.class);
43 public void insertElementToVersion(ElementEntity elementEntity) {
44 accessor.addElements(Sets.newHashSet(elementEntity.getElement_id()), elementEntity.getSpace(), elementEntity.getItemId(), elementEntity.getVersionId());
47 public void insertVersion(VersionEntity versionEntity) {
48 accessor.insertVersion( versionEntity.getSpace(),
49 versionEntity.getItemId(),
50 versionEntity.getVersionId(),
51 versionEntity.getBaseVersionId(),
52 versionEntity.getCreationTime(),
53 versionEntity.getInfo(),
54 versionEntity.getModificationTime(),
55 versionEntity.getRelations());
59 public Result<VersionEntity> list() {
60 return accessor.getAll();
64 interface VersionAccessor {
66 @Query("UPDATE zusammen_dox.version_elements SET element_ids=element_ids+? " +
67 "WHERE space=? AND item_id=? AND version_id=?")
68 void addElements(Set<String> elementIds, String space, String itemId, String versionId);
70 @Query("insert into zusammen_dox.version (space,item_id,version_id,base_version_id,creation_time,info,modification_time,relations) values (?,?,?,?,?,?,?,?)")
71 void insertVersion(String space, String itemId, String versionId, String baseVersionId, Date createTime, String info, Date modificationTime, String relations);
74 @Query("select * from zusammen_dox.version ")
75 @QueryParameters(fetchSize = 400)
76 Result<VersionEntity> getAll();