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=========================================================
21 package org.openecomp.core.tools.store;
23 import com.datastax.driver.core.ResultSet;
24 import com.datastax.driver.mapping.annotations.Accessor;
25 import com.datastax.driver.mapping.annotations.Query;
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;
30 import java.util.List;
33 * Created by ayalaben on 10/15/2017
35 public class HealingHandler {
37 private static NoSqlDb nnoSqlDb = NoSqlDbFactory.getInstance().createInterface();
38 private static HealingAccessor accessor =
39 nnoSqlDb.getMappingManager().createAccessor(HealingAccessor.class);
42 public void populateHealingTable(List<HealingEntity> healingEntities) {
43 healingEntities.forEach(healingEntity -> {
44 if (isHealingRecordExist(healingEntity)) {
45 accessor.updateFlag(healingEntity.getHealingFlag(), healingEntity.getSpace(),
46 healingEntity.getItemId(), healingEntity.getVersionId());
48 accessor.create(healingEntity.getSpace(), healingEntity.getItemId(),
49 healingEntity.getVersionId(), healingEntity.getHealingFlag(),
50 healingEntity.getOldVersion());
55 private boolean isHealingRecordExist(HealingEntity healingEntity) {
56 return accessor.getFlag(healingEntity.getSpace(), healingEntity.getItemId(),
57 healingEntity.getVersionId()).getAvailableWithoutFetching() == 1;
61 interface HealingAccessor {
63 @Query("SELECT healing_needed FROM healing WHERE space=? AND item_id=? AND version_id=?")
64 ResultSet getFlag(String space, String itemId, String versionId);
66 @Query("Insert into healing (space, item_id, version_id, healing_needed, old_version) " +
68 void create(String space, String itemId, String versionId, boolean flag, String oldVersion);
70 @Query("UPDATE healing SET healing_needed=? WHERE space=? AND item_id=? AND version_id=?")
71 void updateFlag(boolean flag, String space, String itemId, String versionId);