001: /*
002: * Copyright (c) 1998-2005 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.tools.profiler;
030:
031: import com.caucho.util.L10N;
032:
033: import javax.sql.DataSource;
034: import java.io.PrintWriter;
035: import java.sql.Connection;
036: import java.sql.SQLException;
037:
038: public final class DataSourceWrapper implements DataSource {
039: private static final L10N L = new L10N(DataSourceWrapper.class);
040:
041: private final DataSource _dataSource;
042: private final ProfilerPoint _profilerPoint;
043:
044: public DataSourceWrapper(ProfilerPoint profilerPoint,
045: DataSource dataSource) {
046: _profilerPoint = profilerPoint;
047: _dataSource = dataSource;
048: }
049:
050: private Connection wrap(Connection connection) {
051: return new ConnectionWrapper(_profilerPoint, connection);
052: }
053:
054: public Connection getConnection() throws SQLException {
055: return wrap(_dataSource.getConnection());
056: }
057:
058: public Connection getConnection(String username, String password)
059: throws SQLException {
060: return wrap(_dataSource.getConnection(username, password));
061: }
062:
063: public PrintWriter getLogWriter() throws SQLException {
064: Profiler profiler = _profilerPoint.start();
065:
066: try {
067: return _dataSource.getLogWriter();
068: } finally {
069: profiler.finish();
070: }
071: }
072:
073: public void setLogWriter(PrintWriter out) throws SQLException {
074: Profiler profiler = _profilerPoint.start();
075:
076: try {
077: _dataSource.setLogWriter(out);
078: } finally {
079: profiler.finish();
080: }
081: }
082:
083: public void setLoginTimeout(int seconds) throws SQLException {
084: Profiler profiler = _profilerPoint.start();
085:
086: try {
087: _dataSource.setLoginTimeout(seconds);
088: } finally {
089: profiler.finish();
090: }
091: }
092:
093: public int getLoginTimeout() throws SQLException {
094: Profiler profiler = _profilerPoint.start();
095:
096: try {
097: return _dataSource.getLoginTimeout();
098: } finally {
099: profiler.finish();
100: }
101: }
102:
103: public String toString() {
104: return "DataSourceWrapper[" + _profilerPoint.getName() + "]";
105: }
106:
107: public <T> T unwrap(Class<T> iface) throws SQLException {
108: throw new UnsupportedOperationException("Not supported yet.");
109: }
110:
111: public boolean isWrapperFor(Class<?> iface) throws SQLException {
112: throw new UnsupportedOperationException("Not supported yet.");
113: }
114: }
|