2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
20 package org.openecomp.portalsdk.analytics.system.fusion.adapter;
25 import javax.naming.Context;
26 import javax.naming.InitialContext;
27 import javax.servlet.*;
29 import com.mchange.v2.c3p0.ComboPooledDataSource;
31 import org.hibernate.SessionFactory;
32 import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
33 import org.hibernate.engine.spi.SessionFactoryImplementor;
34 import org.hibernate.engine.spi.SessionImplementor;
35 import org.openecomp.portalsdk.core.FusionObject;
36 import org.openecomp.portalsdk.core.service.DataAccessService;
37 import org.openecomp.portalsdk.core.util.SystemProperties;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.context.annotation.Configuration;
41 public class FusionAdapter implements FusionObject {
43 public static final String LOCAL_SESSION_FACTORY_KEY = "local";
46 private ComboPooledDataSource dataSource;
47 private Map<String,ComboPooledDataSource> dataSourceMap;
49 //private SessionFactory sessionFactory;
50 private ServletContext servletContext;
52 public FusionAdapter() {
56 public ServletContext getServletContext() {
57 return servletContext;
60 public void setServletContext(ServletContext servletContext) {
61 this.servletContext = servletContext;
64 /** Gets connection to the database **/
65 public Connection getConnection() {
66 Connection connection = null;
68 connection = getDataSource().getConnection();
69 } catch(Exception ex) {
76 /** Gets connection to the database indicated via the session factory key **/
77 public synchronized Connection getConnection(String schemaId) {
78 Connection connection = null;
80 connection = getDataSourceMap().get(schemaId).getConnection();
81 } catch (Exception e) {
89 /** Releases connection to the database **/
90 public void releaseConnection(Connection conn) {
100 public ComboPooledDataSource getDataSource() {
106 public void setDataSource(ComboPooledDataSource dataSource) {
107 this.dataSource = dataSource;
110 public Map<String,ComboPooledDataSource> getDataSourceMap() {
111 if(dataSourceMap==null)
112 dataSourceMap = (Map<String,ComboPooledDataSource>)SpringContext.getApplicationContext().getBean("dataSourceMap");
114 return dataSourceMap;
117 public void setdataSourceMap(Map<String,ComboPooledDataSource> dataSourceMap) {
118 this.dataSourceMap = dataSourceMap;