b01b31f9f1c7bb9f4fc4b4af24dbdfbd7ae8c17b
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / main / java / org / openecomp / sdnc / util / db / DataSourceWrap.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 ONAP Intellectual Property. All rights
6  * reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.sdnc.util.db;
23
24 import java.io.PrintWriter;
25 import java.sql.Connection;
26 import java.sql.SQLException;
27 import java.sql.SQLFeatureNotSupportedException;
28
29 import javax.sql.DataSource;
30
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class DataSourceWrap implements DataSource {
35
36     private static final Logger log = LoggerFactory.getLogger(DataSourceWrap.class);
37
38     private DataSource dataSource;
39
40     @Override
41     public PrintWriter getLogWriter() throws SQLException {
42         return dataSource.getLogWriter();
43     }
44
45     @Override
46     public void setLogWriter(PrintWriter out) throws SQLException {
47         dataSource.setLogWriter(out);
48     }
49
50     @Override
51     public void setLoginTimeout(int seconds) throws SQLException {
52         dataSource.setLoginTimeout(seconds);
53     }
54
55     @Override
56     public int getLoginTimeout() throws SQLException {
57         return dataSource.getLoginTimeout();
58     }
59
60     @Override
61     public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
62         return dataSource.getParentLogger();
63     }
64
65     @Override
66     public <T> T unwrap(Class<T> iface) throws SQLException {
67         return dataSource.unwrap(iface);
68     }
69
70     @Override
71     public boolean isWrapperFor(Class<?> iface) throws SQLException {
72         return dataSource.isWrapperFor(iface);
73     }
74
75     @Override
76     public Connection getConnection() throws SQLException {
77         Connection c = dataSource.getConnection();
78
79         log.debug("getConnection: " + c.getClass().getName());
80
81         c.setAutoCommit(true);
82         return c;
83     }
84
85     @Override
86     public Connection getConnection(String username, String password) throws SQLException {
87         Connection c = dataSource.getConnection(username, password);
88
89         log.debug("getConnection: " + c.getClass().getName());
90
91         c.setAutoCommit(true);
92         return c;
93     }
94
95     public void setDataSource(DataSource dataSource) {
96         this.dataSource = dataSource;
97     }
98 }