KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > tools > profiler > DataSourceWrapper


1 /*
2  * Copyright (c) 1998-2005 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Sam
27  */

28
29
30 package com.caucho.tools.profiler;
31
32 import com.caucho.util.L10N;
33
34 import javax.sql.DataSource JavaDoc;
35 import java.io.PrintWriter JavaDoc;
36 import java.sql.Connection JavaDoc;
37 import java.sql.SQLException JavaDoc;
38
39 public final class DataSourceWrapper
40   implements DataSource JavaDoc
41 {
42   private static final L10N L = new L10N(DataSourceWrapper.class);
43
44   private final DataSource JavaDoc _dataSource;
45   private final ProfilerPoint _profilerPoint;
46
47   public DataSourceWrapper(ProfilerPoint profilerPoint, DataSource JavaDoc dataSource)
48   {
49     _profilerPoint = profilerPoint;
50     _dataSource = dataSource;
51   }
52
53   private Connection JavaDoc wrap(Connection JavaDoc connection)
54   {
55     return new ConnectionWrapper(_profilerPoint, connection);
56   }
57
58   public Connection JavaDoc getConnection()
59     throws SQLException JavaDoc
60   {
61     return wrap(_dataSource.getConnection());
62   }
63
64   public Connection JavaDoc getConnection(String JavaDoc username, String JavaDoc password)
65     throws SQLException JavaDoc
66   {
67     return wrap(_dataSource.getConnection(username, password));
68   }
69
70   public PrintWriter JavaDoc getLogWriter()
71     throws SQLException JavaDoc
72   {
73     Profiler profiler = _profilerPoint.start();
74
75     try {
76       return _dataSource.getLogWriter();
77     }
78     finally {
79       profiler.finish();
80     }
81   }
82
83   public void setLogWriter(PrintWriter JavaDoc out)
84     throws SQLException JavaDoc
85   {
86     Profiler profiler = _profilerPoint.start();
87
88     try {
89       _dataSource.setLogWriter(out);
90     }
91     finally {
92       profiler.finish();
93     }
94   }
95
96   public void setLoginTimeout(int seconds)
97     throws SQLException JavaDoc
98   {
99     Profiler profiler = _profilerPoint.start();
100
101     try {
102       _dataSource.setLoginTimeout(seconds);
103     }
104     finally {
105       profiler.finish();
106     }
107   }
108
109   public int getLoginTimeout()
110     throws SQLException JavaDoc
111   {
112     Profiler profiler = _profilerPoint.start();
113
114     try {
115       return _dataSource.getLoginTimeout();
116     }
117     finally {
118       profiler.finish();
119     }
120   }
121
122   public String JavaDoc toString()
123   {
124     return "DataSourceWrapper[" + _profilerPoint.getName() + "]";
125   }
126 }
127
Popular Tags