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.sdc.vendorsoftwareproduct.dao.impl;
23 import com.datastax.driver.core.ResultSet;
24 import com.datastax.driver.core.UDTValue;
25 import com.datastax.driver.mapping.Mapper;
26 import com.datastax.driver.mapping.Result;
27 import com.datastax.driver.mapping.UDTMapper;
28 import com.datastax.driver.mapping.annotations.Accessor;
29 import com.datastax.driver.mapping.annotations.Query;
30 import org.openecomp.core.dao.impl.CassandraBaseDao;
31 import org.openecomp.core.nosqldb.api.NoSqlDb;
32 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
33 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.NetworkDao;
35 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NetworkEntity;
36 import org.openecomp.sdc.versioning.VersioningManagerFactory;
37 import org.openecomp.sdc.versioning.dao.types.Version;
38 import org.openecomp.sdc.versioning.types.UniqueValueMetadata;
39 import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
41 import java.util.Arrays;
42 import java.util.Collection;
43 import java.util.Collections;
45 public class NetworkDaoCassandraImpl extends CassandraBaseDao<NetworkEntity> implements NetworkDao {
47 private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
48 private static final Mapper<NetworkEntity> mapper =
49 noSqlDb.getMappingManager().mapper(NetworkEntity.class);
50 private static final NetworkAccessor accessor =
51 noSqlDb.getMappingManager().createAccessor(NetworkAccessor.class);
52 private static final UDTMapper<Version> versionMapper =
53 noSqlDb.getMappingManager().udtMapper(Version.class);
56 public void registerVersioning(String versionableEntityType) {
57 VersionableEntityMetadata metadata = new VersionableEntityMetadata(
58 mapper.getTableMetadata().getName(),
59 mapper.getTableMetadata().getPartitionKey().get(0).getName(),
60 mapper.getTableMetadata().getPartitionKey().get(1).getName());
63 metadata.setUniqueValuesMetadata(Collections.singletonList(new UniqueValueMetadata(
64 VendorSoftwareProductConstants.UniqueValues.NETWORK_NAME,
65 Arrays.asList(mapper.getTableMetadata().getPartitionKey().get(0).getName(),
66 mapper.getTableMetadata().getPartitionKey().get(1).getName(), "name"))));
68 VersioningManagerFactory.getInstance().createInterface()
69 .register(versionableEntityType, metadata);
73 protected Mapper<NetworkEntity> getMapper() {
78 protected Object[] getKeys(NetworkEntity entity) {
79 return new Object[]{entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
84 public void update(NetworkEntity entity) {
85 accessor.updateCompositionData(entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
86 entity.getId(), entity.getCompositionData());
90 public void updateQuestionnaireData(String vspId, Version version, String id,
91 String questionnaireData) {
92 accessor.updateQuestionnaireData(questionnaireData, vspId, versionMapper.toUDT(version), id);
96 public void deleteAll(String vspId, Version version) {
97 accessor.deleteAll(vspId, version);
103 public Collection<NetworkEntity> list(NetworkEntity entity) {
104 return accessor.list(entity.getVspId(), versionMapper.toUDT(entity.getVersion())).all();
108 interface NetworkAccessor {
111 "select vsp_id, version, network_id, composition_data from vsp_network where vsp_id=?"
113 Result<NetworkEntity> list(String vspId, UDTValue version);
116 "insert into vsp_network (vsp_id, version, network_id, composition_data) values (?,?,?,?)")
117 ResultSet updateCompositionData(String vspId, UDTValue version, String id,
118 String compositionData);
121 "update vsp_network set questionnaire_data=? where vsp_id=? and version=? and network_id=?")
122 ResultSet updateQuestionnaireData(String questionnaireData, String vspId, UDTValue version,
125 @Query("delete from vsp_network where vsp_id=? and version=?")
126 ResultSet deleteAll(String vspId, Version version);