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.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.ProcessDao;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
35 import org.openecomp.sdc.versioning.VersioningManagerFactory;
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 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.Collections;
44 public class ProcessDaoCassandraImpl implements ProcessDao {
46 private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
47 private static final Mapper<ProcessEntity> mapper =
48 noSqlDb.getMappingManager().mapper(ProcessEntity.class);
49 private static final ProcessAccessor accessor =
50 noSqlDb.getMappingManager().createAccessor(ProcessAccessor.class);
51 private static final UDTMapper<Version> versionMapper =
52 noSqlDb.getMappingManager().udtMapper(Version.class);
55 public void registerVersioning(String versionableEntityType) {
56 VersionableEntityMetadata metadata = new VersionableEntityMetadata(
57 mapper.getTableMetadata().getName(),
58 mapper.getTableMetadata().getPartitionKey().get(0).getName(),
59 mapper.getTableMetadata().getPartitionKey().get(1).getName());
61 metadata.setUniqueValuesMetadata(Collections.singletonList(
62 new UniqueValueMetadata(VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME,
63 Arrays.asList("vsp_id", "version", "component_id", "name"))));
65 VersioningManagerFactory.getInstance().createInterface()
66 .register(versionableEntityType, metadata);
70 public Collection<ProcessEntity> list(ProcessEntity entity) {
72 .list(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), entity.getComponentId())
77 public void create(ProcessEntity entity) {
78 accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
79 entity.getComponentId(), entity.getId(), entity.getName(), entity.getDescription());
83 public void update(ProcessEntity entity) {
84 accessor.update(entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
85 entity.getComponentId(), entity.getId(), entity.getName(), entity.getDescription());
89 public ProcessEntity get(ProcessEntity entity) {
91 .get(entity.getVspId(), versionMapper.toUDT(entity.getVersion()), entity.getComponentId(),
96 public void delete(ProcessEntity entity) {
97 if (entity.getId() == null) {
98 accessor.deleteAll(entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
99 entity.getComponentId());
101 accessor.delete(entity.getVspId(), versionMapper.toUDT(entity.getVersion()),
102 entity.getComponentId(), entity.getId());
106 public void deleteAll(ProcessEntity entity) {
107 accessor.deleteAll(entity.getVspId(), versionMapper.toUDT(entity.getVersion()));
111 interface ProcessAccessor {
114 "insert into vsp_process (vsp_id, version, component_id, process_id, name, description) "
115 + "values (?,?,?,?,?,?)")
116 ResultSet update(String vspId, UDTValue version, String componentId, String id, String name,
120 "select vsp_id, version, component_id, process_id, name, description, artifact_name "
121 + "from vsp_process where vsp_id=? and version=? and component_id=? and process_id=?")
122 ProcessEntity get(String vspId, UDTValue version, String componentId, String id);
125 "select vsp_id, version, component_id, process_id, name, description, artifact_name "
126 + "from vsp_process where vsp_id=? and version=? and component_id=?")
127 Result<ProcessEntity> list(String vspId, UDTValue version, String componentId);
130 "delete from vsp_process where vsp_id=? and version=? and component_id=? and process_id=?")
131 ResultSet delete(String vspId, UDTValue version, String componentId, String id);
133 @Query("delete from vsp_process where vsp_id=? and version=? and component_id=?")
134 ResultSet deleteAll(String vspId, UDTValue version, String componentId);
136 @Query("delete from vsp_process where vsp_id=? and version=?")
137 ResultSet deleteAll(String vspId, UDTValue version);