2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalsdk.analytics.system.fusion.adapter;
40 import java.sql.Connection;
43 import javax.servlet.ServletContext;
45 import org.onap.portalsdk.analytics.model.runtime.FormField;
46 import org.onap.portalsdk.core.FusionObject;
47 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
48 import org.springframework.beans.factory.annotation.Autowired;
50 import com.mchange.v2.c3p0.ComboPooledDataSource;
52 public class FusionAdapter implements FusionObject {
54 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FusionAdapter.class);
56 public static final String LOCAL_SESSION_FACTORY_KEY = "local";
59 private ComboPooledDataSource dataSource;
60 private Map<String,ComboPooledDataSource> dataSourceMap;
62 //private SessionFactory sessionFactory;
63 private ServletContext servletContext;
65 public FusionAdapter() {
69 public ServletContext getServletContext() {
70 return servletContext;
73 public void setServletContext(ServletContext servletContext) {
74 this.servletContext = servletContext;
77 /** Gets connection to the database **/
78 public Connection getConnection() {
79 Connection connection = null;
81 connection = getDataSource().getConnection();
82 } catch(Exception ex) {
83 logger.error(EELFLoggerDelegate.errorLogger,ex.getMessage(), ex);
89 /** Gets connection to the database indicated via the session factory key **/
90 public synchronized Connection getConnection(String schemaId) {
91 Connection connection = null;
93 connection = getDataSourceMap().get(schemaId).getConnection();
94 } catch (Exception e) {
95 logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), e);
102 /** Releases connection to the database **/
103 public void releaseConnection(Connection conn) {
107 catch (Exception e) {
108 logger.error(EELFLoggerDelegate.errorLogger,e.getMessage(), e);
113 public ComboPooledDataSource getDataSource() {
119 public void setDataSource(ComboPooledDataSource dataSource) {
120 this.dataSource = dataSource;
123 public Map<String,ComboPooledDataSource> getDataSourceMap() {
124 if(dataSourceMap==null)
125 dataSourceMap = (Map<String,ComboPooledDataSource>)SpringContext.getApplicationContext().getBean("dataSourceMap");
127 return dataSourceMap;
130 public void setdataSourceMap(Map<String,ComboPooledDataSource> dataSourceMap) {
131 this.dataSourceMap = dataSourceMap;