re base code
[sdc.git] / openecomp-be / lib / openecomp-sdc-versioning-lib / openecomp-sdc-versioning-core / src / main / java / org / openecomp / sdc / versioning / dao / impl / VersionInfoDaoImpl.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.versioning.dao.impl;
18
19 import com.datastax.driver.mapping.Mapper;
20 import com.datastax.driver.mapping.Result;
21 import com.datastax.driver.mapping.annotations.Accessor;
22 import com.datastax.driver.mapping.annotations.Query;
23 import org.openecomp.core.dao.impl.CassandraBaseDao;
24 import org.openecomp.core.nosqldb.api.NoSqlDb;
25 import org.openecomp.sdc.versioning.dao.VersionInfoDao;
26 import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
27
28 import java.util.Collection;
29
30 public class VersionInfoDaoImpl extends CassandraBaseDao<VersionInfoEntity>
31     implements VersionInfoDao {
32
33
34   private final NoSqlDb noSqlDb;
35   private final Mapper<VersionInfoEntity> mapper;
36   private final VersionInfoAccessor accessor;
37
38
39   public VersionInfoDaoImpl(NoSqlDb noSqlDb) {
40     this.noSqlDb = noSqlDb;
41     this.mapper = this.noSqlDb.getMappingManager().mapper(VersionInfoEntity.class);
42     this.accessor = this.noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class);
43   }
44
45   @Override
46   protected Mapper<VersionInfoEntity> getMapper() {
47     return mapper;
48   }
49
50   @Override
51   protected Object[] getKeys(VersionInfoEntity entity) {
52     return new Object[]{entity.getEntityType(), entity.getEntityId()};
53   }
54
55   @Override
56   public Collection<VersionInfoEntity> list(VersionInfoEntity entity) {
57     return accessor.getAll(entity.getEntityType()).all();
58   }
59
60   @Accessor
61   interface VersionInfoAccessor {
62     @Query("select * from version_info where entity_type=?")
63     Result<VersionInfoEntity> getAll(String entityType);
64   }
65 }