2 * Copyright 2016-2017 ZTE Corporation.
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.onap.aai.esr.dao;
19 import org.hibernate.SessionFactory;
20 import org.onap.aai.esr.common.ExtSysResuorceType;
21 import org.onap.aai.esr.exception.ExtsysException;
24 * DAO manager class.<br>
25 * a class to store DAO instances and provide methods to get these instances
29 public class DaoManager {
30 private static DaoManager instance = new DaoManager();
32 private VimDao vimDao;
33 private EmsDao emsDao;
34 private VnfmDao vnfmDao;
35 private SdncDao sdncDao;
36 private CommonDao commonDao;
37 private SessionFactory sessionFactory;
39 private DaoManager() {}
41 public static synchronized DaoManager getInstance() {
46 * according to resource type and return proper DAO.
48 * @param type resource Type
51 public BaseDao<?> getDao(String type) throws ExtsysException {
52 if (sessionFactory == null) {
53 throw new ExtsysException("", "errorMsg:database connect init faild!");
55 switch (ExtSysResuorceType.getType(type)) {
65 return getCommonDao();
69 public void setSessionFactory(SessionFactory sessionFactory) {
70 this.sessionFactory = sessionFactory;
73 public SessionFactory getSessionFactory() {
74 return sessionFactory;
78 * @return Returns the vim dao.
80 public VimDao getVimDao() {
81 vimDao = new VimDao(sessionFactory);
85 public void setVimDao(VimDao vimDao) {
90 * @return Returns the ems dao.
92 public EmsDao getEmsDao() {
93 emsDao = new EmsDao(sessionFactory);
97 public void setEmsDao(EmsDao emsDao) {
102 * @return Returns the vnfm dao.
104 public VnfmDao getVnfmDao() {
105 vnfmDao = new VnfmDao(sessionFactory);
109 public void setVnfmDao(VnfmDao vnfmDao) {
110 this.vnfmDao = vnfmDao;
114 * @return Returns the sdnc dao.
116 public SdncDao getSdncDao() {
117 sdncDao = new SdncDao(sessionFactory);
121 public void setSdncDao(SdncDao sdncDao) {
122 this.sdncDao = sdncDao;
126 * @return Returns the common dao.
128 public CommonDao getCommonDao() {
129 commonDao = new CommonDao(sessionFactory);
133 public void setCommonDao(CommonDao commonDao) {
134 this.commonDao = commonDao;