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.versioning.dao.impl;
19 import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
20 import com.datastax.driver.mapping.Mapper;
21 import com.datastax.driver.mapping.Result;
22 import com.datastax.driver.mapping.annotations.Accessor;
23 import com.datastax.driver.mapping.annotations.Query;
25 import java.util.Collection;
27 import org.openecomp.core.dao.impl.CassandraBaseDao;
28 import org.openecomp.core.nosqldb.api.NoSqlDb;
29 import org.openecomp.sdc.versioning.dao.VersionInfoDao;
30 import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
31 import org.openecomp.sdc.versioning.dao.types.VersionStatus;
33 public class VersionInfoDaoImpl extends CassandraBaseDao<VersionInfoEntity>
34 implements VersionInfoDao {
37 private final NoSqlDb noSqlDb;
38 private final Mapper<VersionInfoEntity> mapper;
39 private final VersionInfoAccessor accessor;
42 public VersionInfoDaoImpl(NoSqlDb noSqlDb) {
43 this.noSqlDb = noSqlDb;
44 this.mapper = this.noSqlDb.getMappingManager().mapper(VersionInfoEntity.class);
45 this.accessor = this.noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class);
46 this.noSqlDb.getMappingManager().getSession().getCluster().getConfiguration().getCodecRegistry()
47 .register(new EnumNameCodec<>(VersionStatus.class));
51 protected Mapper<VersionInfoEntity> getMapper() {
56 protected Object[] getKeys(VersionInfoEntity entity) {
57 return new Object[]{entity.getEntityType(), entity.getEntityId()};
61 public Collection<VersionInfoEntity> list(VersionInfoEntity entity) {
62 return accessor.getAll(entity.getEntityType()).all();
66 interface VersionInfoAccessor {
67 @Query("select * from version_info where entity_type=?")
68 Result<VersionInfoEntity> getAll(String entityType);