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.UDTValue;
24 import com.datastax.driver.mapping.Mapper;
25 import com.datastax.driver.mapping.Result;
26 import com.datastax.driver.mapping.UDTMapper;
27 import com.datastax.driver.mapping.annotations.Accessor;
28 import com.datastax.driver.mapping.annotations.Query;
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.dao.UploadDataDao;
33 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity;
34 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
35 import org.openecomp.sdc.versioning.dao.types.Version;
37 import java.nio.ByteBuffer;
38 import java.util.Collection;
40 public class UploadDataDaoImpl extends CassandraBaseDao<UploadDataEntity> implements UploadDataDao {
42 private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
43 private static final Mapper<UploadDataEntity> mapper =
44 noSqlDb.getMappingManager().mapper(UploadDataEntity.class);
45 private static final UploadDataAccessor accessor =
46 noSqlDb.getMappingManager().createAccessor(UploadDataAccessor.class);
47 private static final UDTMapper<Version> versionMapper =
48 noSqlDb.getMappingManager().udtMapper(Version.class);
51 protected Mapper<UploadDataEntity> getMapper() {
56 protected Object[] getKeys(UploadDataEntity entity) {
57 return new Object[]{entity.getId(), versionMapper.toUDT(entity.getVersion())};
61 public Collection<UploadDataEntity> list(UploadDataEntity entity) {
62 return accessor.listAll().all();
66 public void deleteContentDataAndValidationData(String vspId, Version version) {
67 accessor.deleteContentDataAndValidationData(vspId, versionMapper.toUDT(version));
71 public ByteBuffer getContentData(String vspId, Version version) {
72 return accessor.getContentData(vspId, version).one().getContentData();
77 interface UploadDataAccessor {
80 "SELECT package_name, package_version, content_data, validation_data FROM vsp_information")
81 Result<UploadDataEntity> listAll();
84 "DELETE package_name, package_version, content_data, validation_data FROM vsp_information "
85 + "WHERE vsp_id=? and version=?")
86 Result<VspDetails> deleteContentDataAndValidationData(String vspId, UDTValue udtValue);
88 @Query("SELECT CONTENT_DATA FROM vsp_information WHERE vsp_id=? and version=?")
89 Result<UploadDataEntity> getContentData(String vspId, Version version);