01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sam/trunk/component/src/java/org/sakaiproject/spring/DataSourceWrapperAutoCommit.java $
03: * $Id: DataSourceWrapperAutoCommit.java 13802 2006-08-16 23:13:50Z ktsao@stanford.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the"License");
09: * 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.opensource.org/licenses/ecl1.php
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: *
20: **********************************************************************************/package org.sakaiproject.spring;
21:
22: import java.io.PrintWriter;
23: import java.sql.Connection;
24: import java.sql.SQLException;
25:
26: import javax.sql.DataSource;
27:
28: /**
29: * Wraps an existing DataSource for the sole purpose of setting
30: * autoCommit=true when the connection is gotten. This allows
31: * the same underlying DataSource to serve for tools that need
32: * autoCommit=false, as well as tools that need autoCommit=true.
33: */
34: public class DataSourceWrapperAutoCommit implements DataSource {
35: protected DataSource m_wrapped = null;
36:
37: public DataSourceWrapperAutoCommit() {
38: }
39:
40: public void setDataSource(DataSource d) {
41: m_wrapped = d;
42: }
43:
44: public DataSource getDataSource() {
45: return m_wrapped;
46: }
47:
48: public Connection getConnection() throws SQLException {
49: Connection c = m_wrapped.getConnection();
50: if (c != null)
51: c.setAutoCommit(true);
52: return c;
53: }
54:
55: public Connection getConnection(String username, String password)
56: throws SQLException {
57: Connection c = m_wrapped.getConnection(username, password);
58: if (c != null)
59: c.setAutoCommit(true);
60: return c;
61: }
62:
63: public int getLoginTimeout() throws SQLException {
64: return m_wrapped.getLoginTimeout();
65: }
66:
67: public PrintWriter getLogWriter() throws SQLException {
68: return m_wrapped.getLogWriter();
69: }
70:
71: public void setLoginTimeout(int timeout) throws SQLException {
72: m_wrapped.setLoginTimeout(timeout);
73: }
74:
75: public void setLogWriter(PrintWriter writer) throws SQLException {
76: m_wrapped.setLogWriter(writer);
77: }
78: }
|