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