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.
17 package org.openecomp.sdc.vendorsoftwareproduct.dao.impl;
19 import com.datastax.driver.core.ResultSet;
20 import com.datastax.driver.core.UDTValue;
21 import com.datastax.driver.mapping.Mapper;
22 import com.datastax.driver.mapping.Result;
23 import com.datastax.driver.mapping.UDTMapper;
24 import com.datastax.driver.mapping.annotations.Accessor;
25 import com.datastax.driver.mapping.annotations.Query;
26 import java.util.Arrays;
27 import java.util.Collection;
28 import java.util.Collections;
29 import org.openecomp.core.dao.impl.CassandraBaseDao;
30 import org.openecomp.core.nosqldb.api.NoSqlDb;
31 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
32 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDependencyModelDao;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentDependencyModelEntity;
35 import org.openecomp.sdc.versioning.ActionVersioningManagerFactory;
36 import org.openecomp.sdc.versioning.dao.types.Version;
37 import org.openecomp.sdc.versioning.types.UniqueValueMetadata;
38 import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
40 public class ComponentDependencyModelDaoCassandraImpl extends
41 CassandraBaseDao<ComponentDependencyModelEntity> implements ComponentDependencyModelDao {
43 private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
44 private static final Mapper<ComponentDependencyModelEntity> mapper =
45 noSqlDb.getMappingManager().mapper(ComponentDependencyModelEntity.class);
46 private static final ComponentDependencyModelDaoCassandraImpl.ComponentDependencyModelAccessor
47 accessor = noSqlDb.getMappingManager().createAccessor(
48 ComponentDependencyModelDaoCassandraImpl.ComponentDependencyModelAccessor.class);
49 private static final UDTMapper<Version> versionMapper =
50 noSqlDb.getMappingManager().udtMapper(Version.class);
53 protected Mapper<ComponentDependencyModelEntity> getMapper() {
58 protected Object[] getKeys(ComponentDependencyModelEntity entity) {
59 return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
64 public Collection<ComponentDependencyModelEntity> list(ComponentDependencyModelEntity entity) {
66 .list(entity.getVspId(), versionMapper.toUDT(entity.getVersion())).all();
70 public void registerVersioning(String versionableEntityType) {
71 VersionableEntityMetadata metadata = new VersionableEntityMetadata(
72 mapper.getTableMetadata().getName(),
73 mapper.getTableMetadata().getPartitionKey().get(0).getName(),
74 mapper.getTableMetadata().getPartitionKey().get(1).getName());
76 metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata(
77 VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME,
78 Arrays.asList("vsp_id", "version", "component_id", "name"))));
80 ActionVersioningManagerFactory.getInstance().createInterface()
81 .register(versionableEntityType, metadata);
86 interface ComponentDependencyModelAccessor {
87 @Query("delete from vsp_component_dependency_model where vsp_id=? and version=?")
88 ResultSet deleteAll(String vspId, UDTValue version);
91 "select * from vsp_component_dependency_model where vsp_id=? and version=?")
92 Result<ComponentDependencyModelEntity> list(String vspId, UDTValue version);