2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 * not use this file except in compliance with the License. You may obtain
6 * 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
13 * implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 package org.akraino.validation.ui.daoimpl;
18 import java.util.List;
20 import javax.annotation.Nonnull;
22 import org.akraino.validation.ui.dao.BlueprintInstanceDAO;
23 import org.akraino.validation.ui.entity.Blueprint;
24 import org.akraino.validation.ui.entity.BlueprintInstance;
25 import org.hibernate.Criteria;
26 import org.hibernate.Session;
27 import org.hibernate.SessionFactory;
28 import org.hibernate.criterion.Restrictions;
29 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Repository;
34 public class BlueprintInstanceDAOImpl implements BlueprintInstanceDAO {
36 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(BlueprintInstanceDAOImpl.class);
39 private SessionFactory sessionFactory;
41 protected Session getSession() {
42 return sessionFactory.getCurrentSession();
46 public List<BlueprintInstance> getBlueprintInstances() {
47 Criteria criteria = getSession().createCriteria(BlueprintInstance.class);
48 criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
49 return criteria.list();
53 public BlueprintInstance getBlueprintInstance(@Nonnull Integer instId) {
54 Criteria criteria = getSession().createCriteria(BlueprintInstance.class);
55 criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
56 criteria.add(Restrictions.eq("id", instId));
57 return criteria.list() == null || criteria.list().size() < 1 ? null
58 : (BlueprintInstance) criteria.list().get(0);
62 public BlueprintInstance getBlueprintInstance(Blueprint blueprint, String version) {
63 Criteria criteria = getSession().createCriteria(BlueprintInstance.class);
64 criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
65 if (blueprint != null) {
66 criteria.add(Restrictions.eq("blueprint", blueprint));
68 if (version != null) {
69 criteria.add(Restrictions.eq("version", version));
71 return criteria.list() == null || criteria.list().size() < 1 ? null
72 : (BlueprintInstance) criteria.list().get(0);
76 public void saveOrUpdate(@Nonnull BlueprintInstance blueprintInst) {
77 getSession().saveOrUpdate(blueprintInst);
82 public void merge(@Nonnull BlueprintInstance blueprintInst) {
83 getSession().merge(blueprintInst);
88 public void deleteBlueprintInstance(@Nonnull BlueprintInstance blueprintInst) {
89 getSession().delete(blueprintInst);
94 public void deleteAll() {
95 if (getSession().createQuery("delete from BlueprintInstance").executeUpdate() > 0) {
96 LOGGER.info(EELFLoggerDelegate.applicationLogger, "All blueprint instances entries are cleaned up");