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.vendorlicense.dao.impl;
19 import com.datastax.driver.mapping.Mapper;
20 import com.datastax.driver.mapping.Result;
21 import com.datastax.driver.mapping.UDTMapper;
22 import com.datastax.driver.mapping.annotations.Accessor;
23 import com.datastax.driver.mapping.annotations.Query;
24 import java.util.Collection;
25 import org.openecomp.core.dao.impl.CassandraBaseDao;
26 import org.openecomp.core.nosqldb.api.NoSqlDb;
27 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
28 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
29 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
30 import org.openecomp.sdc.versioning.ActionVersioningManagerFactory;
31 import org.openecomp.sdc.versioning.dao.types.Version;
32 import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
34 public class VendorLicenseModelCassandraDaoImpl extends CassandraBaseDao<VendorLicenseModelEntity>
36 VendorLicenseModelDao {
38 private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
39 private static Mapper<VendorLicenseModelEntity> mapper =
40 noSqlDb.getMappingManager().mapper(VendorLicenseModelEntity.class);
41 private static VendorLicenseModelAccessor accessor =
42 noSqlDb.getMappingManager().createAccessor(VendorLicenseModelAccessor.class);
43 private static UDTMapper<Version> versionMapper =
44 noSqlDb.getMappingManager().udtMapper(Version.class);
47 public void registerVersioning(String versionableEntityType) {
48 ActionVersioningManagerFactory.getInstance().createInterface()
49 .register(versionableEntityType, new VersionableEntityMetadata(
50 mapper.getTableMetadata().getName(),
51 mapper.getTableMetadata().getPartitionKey().get(0).getName(),
52 mapper.getTableMetadata().getPartitionKey().get(1).getName()));
56 protected Mapper<VendorLicenseModelEntity> getMapper() {
61 protected Object[] getKeys(VendorLicenseModelEntity entity) {
62 return new Object[]{entity.getId(), versionMapper.toUDT(entity.getVersion())};
66 public Collection<VendorLicenseModelEntity> list(VendorLicenseModelEntity vendorLicenseModel) {
67 return accessor.getAll().all();
71 interface VendorLicenseModelAccessor {
73 @Query("SELECT * FROM vendor_license_model")
74 Result<VendorLicenseModelEntity> getAll();