KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > sql > spy > SpyPooledConnection


1 /*
2  * Copyright (c) 1998-2006 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 Scott Ferguson
27  */

28
29 package com.caucho.sql.spy;
30
31 import com.caucho.log.Log;
32 import com.caucho.util.L10N;
33
34 import javax.sql.ConnectionEventListener JavaDoc;
35 import javax.sql.PooledConnection JavaDoc;
36 import java.sql.Connection JavaDoc;
37 import java.sql.SQLException JavaDoc;
38 import java.util.logging.Logger JavaDoc;
39
40 /**
41  * Spying on a connection.
42  */

43 public class SpyPooledConnection implements javax.sql.PooledConnection JavaDoc {
44   protected final static Logger JavaDoc log = Log.open(SpyPooledConnection.class);
45   protected final static L10N L = new L10N(SpyPooledConnection.class);
46
47   protected int _id;
48   private int _connCount;
49
50   // The underlying connection
51
private PooledConnection JavaDoc _pconn;
52
53   /**
54    * Creates a new SpyConnection.
55    */

56   public SpyPooledConnection(PooledConnection JavaDoc conn, int id)
57   {
58     _pconn = conn;
59     _id = id;
60   }
61
62   public void addConnectionEventListener(ConnectionEventListener JavaDoc listener)
63   {
64     _pconn.addConnectionEventListener(listener);
65   }
66
67   public void removeConnectionEventListener(ConnectionEventListener JavaDoc listener)
68   {
69     _pconn.removeConnectionEventListener(listener);
70   }
71   
72   public Connection JavaDoc getConnection()
73     throws SQLException JavaDoc
74   {
75     try {
76       Connection JavaDoc conn = _pconn.getConnection();
77
78       int connId = _connCount++;
79
80       log.info(_id + ":connect() -> " + connId + ":" + conn);
81
82       return new SpyConnection(conn, connId);
83     } catch (SQLException JavaDoc e) {
84       log.info(_id + ":exn-connect(" + e + ")");
85       
86       throw e;
87     }
88   }
89
90   public void close()
91     throws SQLException JavaDoc
92   {
93     try {
94       _pconn.close();
95
96       log.info(_id + ":close()");
97     } catch (SQLException JavaDoc e) {
98       log.info(_id + ":exn-close(" + e + ")");
99       
100       throw e;
101     }
102   }
103
104   public String JavaDoc toString()
105   {
106     return "SpyPooledConnection[id=" + _id + ",conn=" + _pconn + "]";
107   }
108 }
109
Popular Tags