Fix OSGi wiring issues
[ccsdk/features.git] / blueprints-processor / adaptors / data-adaptor-provider / src / main / java / org / onap / ccsdk / config / data / adaptor / db / DataSourceWrap.java
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  * \r
5  * Licensed under the Apache License, Version 2.0 (the "License");\r
6  * you may not use this file except in compliance with the License.\r
7  * You may obtain a copy of the License at\r
8  * \r
9  * http://www.apache.org/licenses/LICENSE-2.0\r
10  * \r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 \r
18 package org.onap.ccsdk.config.data.adaptor.db;\r
19 \r
20 import java.io.PrintWriter;\r
21 import java.sql.Connection;\r
22 import java.sql.SQLException;\r
23 import java.sql.SQLFeatureNotSupportedException;\r
24 import javax.sql.DataSource;\r
25 import com.att.eelf.configuration.EELFLogger;\r
26 import com.att.eelf.configuration.EELFManager;\r
27 \r
28 public class DataSourceWrap implements DataSource {\r
29 \r
30     private static EELFLogger logger = EELFManager.getInstance().getLogger(DataSourceWrap.class);\r
31 \r
32     private DataSource dataSource;\r
33 \r
34     public DataSourceWrap(DataSource dataSource) {\r
35         logger.info("Setting Data Source {} ", dataSource);\r
36         this.dataSource = dataSource;\r
37     }\r
38 \r
39     @Override\r
40     public PrintWriter getLogWriter() throws SQLException {\r
41         return dataSource.getLogWriter();\r
42     }\r
43 \r
44     @Override\r
45     public void setLogWriter(PrintWriter out) throws SQLException {\r
46         dataSource.setLogWriter(out);\r
47     }\r
48 \r
49     @Override\r
50     public void setLoginTimeout(int seconds) throws SQLException {\r
51         dataSource.setLoginTimeout(seconds);\r
52     }\r
53 \r
54     @Override\r
55     public int getLoginTimeout() throws SQLException {\r
56         return dataSource.getLoginTimeout();\r
57     }\r
58 \r
59     @Override\r
60     public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {\r
61         return dataSource.getParentLogger();\r
62     }\r
63 \r
64     @Override\r
65     public <T> T unwrap(Class<T> iface) throws SQLException {\r
66         return dataSource.unwrap(iface);\r
67     }\r
68 \r
69     @Override\r
70     public boolean isWrapperFor(Class<?> iface) throws SQLException {\r
71         return dataSource.isWrapperFor(iface);\r
72     }\r
73 \r
74     @SuppressWarnings("squid:S2095")\r
75     @Override\r
76     public Connection getConnection() throws SQLException {\r
77         Connection c = dataSource.getConnection();\r
78         logger.trace("getConnection: ({})", c.getClass().getName());\r
79         c.setAutoCommit(true);\r
80         return c;\r
81     }\r
82 \r
83     @SuppressWarnings("squid:S2095")\r
84     @Override\r
85     public Connection getConnection(String username, String pass) throws SQLException {\r
86         Connection c = dataSource.getConnection(username, pass);\r
87         c.setAutoCommit(true);\r
88         return c;\r
89     }\r
90 \r
91 }\r