2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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=========================================================
20 package org.openecomp.core.tools.store;
22 import com.datastax.driver.core.ResultSet;
23 import com.datastax.driver.mapping.annotations.Accessor;
24 import com.datastax.driver.mapping.annotations.Query;
25 import java.util.List;
26 import org.openecomp.core.nosqldb.api.NoSqlDb;
27 import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
28 import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity;
31 * Created by ayalaben on 10/15/2017
33 public class HealingHandler {
35 private static NoSqlDb nnoSqlDb = NoSqlDbFactory.getInstance().createInterface();
36 private static HealingAccessor accessor = nnoSqlDb.getMappingManager().createAccessor(HealingAccessor.class);
38 public void populateHealingTable(List<HealingEntity> healingEntities) {
39 healingEntities.forEach(healingEntity -> {
40 if (isHealingRecordExist(healingEntity)) {
41 accessor.updateFlag(healingEntity.isHealingFlag(), healingEntity.getSpace(), healingEntity.getItemId(), healingEntity.getVersionId());
43 accessor.create(healingEntity.getSpace(), healingEntity.getItemId(), healingEntity.getVersionId(), healingEntity.isHealingFlag(),
44 healingEntity.getOldVersion());
49 private boolean isHealingRecordExist(HealingEntity healingEntity) {
50 return accessor.getFlag(healingEntity.getSpace(), healingEntity.getItemId(), healingEntity.getVersionId()).getAvailableWithoutFetching() == 1;
54 interface HealingAccessor {
56 @Query("SELECT healing_needed FROM healing WHERE space=? AND item_id=? AND version_id=?")
57 ResultSet getFlag(String space, String itemId, String versionId);
59 @Query("Insert into healing (space, item_id, version_id, healing_needed, old_version) " + "values (?,?,?,?,?)")
60 void create(String space, String itemId, String versionId, boolean flag, String oldVersion);
62 @Query("UPDATE healing SET healing_needed=? WHERE space=? AND item_id=? AND version_id=?")
63 void updateFlag(boolean flag, String space, String itemId, String versionId);