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.DeploymentFlavorDao;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity;
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;
41 public class DeploymentFlavorDaoCassandraImpl extends CassandraBaseDao<DeploymentFlavorEntity>
42 implements DeploymentFlavorDao {
43 private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
44 private static final Mapper<DeploymentFlavorEntity> mapper =
45 noSqlDb.getMappingManager().mapper(DeploymentFlavorEntity.class);
46 private static final DeploymentFlavorAccessor accessor =
47 noSqlDb.getMappingManager().createAccessor(DeploymentFlavorAccessor.class);
48 private static final UDTMapper<Version> versionMapper =
49 noSqlDb.getMappingManager().udtMapper(Version.class);
52 protected Mapper<DeploymentFlavorEntity> getMapper() {
57 protected Object[] getKeys(DeploymentFlavorEntity entity) {
58 return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
63 public Collection<DeploymentFlavorEntity> list(DeploymentFlavorEntity entity) {
64 return accessor.list(entity.getVspId(), versionMapper.toUDT(entity.getVersion())).all();
68 public void update(DeploymentFlavorEntity entity) {
69 accessor.updateCompositionData(entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
70 entity.getId(), entity.getCompositionData());
74 public void registerVersioning(String versionableEntityType) {
75 VersionableEntityMetadata metadata = new VersionableEntityMetadata(
76 mapper.getTableMetadata().getName(),
77 mapper.getTableMetadata().getPartitionKey().get(0).getName(),
78 mapper.getTableMetadata().getPartitionKey().get(1).getName());
81 metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata(
82 VendorSoftwareProductConstants.UniqueValues.DEPLOYMENT_FLAVOR_NAME,
83 Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(),
84 mapper.getTableMetadata().getPartitionKey().get(1).getName(), "name"))));
86 ActionVersioningManagerFactory.getInstance().createInterface()
87 .register(versionableEntityType, metadata);
91 public void deleteAll(String vspId, Version version) {
92 accessor.deleteAll(vspId, version);
96 interface DeploymentFlavorAccessor {
98 "select vsp_id, version, deployment_flavor_id, composition_data from vsp_deployment_flavor where vsp_id=?"
100 Result<DeploymentFlavorEntity> list(String vspId, UDTValue version);
103 "insert into vsp_deployment_flavor (vsp_id, version, deployment_flavor_id, composition_data) values (?,?,?,?)")
104 ResultSet updateCompositionData(String vspId, UDTValue version, String id,
105 String compositionData);
107 @Query("delete from vsp_deployment_flavor where vsp_id=? and version=?")
108 ResultSet deleteAll(String vspId, Version version);