01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.pool.connection;
09:
10: import java.sql.SQLException;
11: import java.sql.Connection;
12:
13: import org.huihoo.jfox.pool.ObjectPool;
14:
15: /**
16: * wrap a physical connection and make it can put into pool
17: * @author <a href="mailto:kelvin_wym@hotmail.com">Kelvin Wu</a>
18: */
19:
20: public class SimplePoolableConnection implements PoolableConnection {
21:
22: private ObjectPool pool = null;
23: private Connection conn = null;
24: private boolean using = false;
25:
26: public SimplePoolableConnection(Connection conn) {
27: this .conn = conn;
28: }
29:
30: public ObjectPool getPool() {
31: return pool;
32: }
33:
34: public void setPool(ObjectPool pool) {
35: this .pool = pool;
36: }
37:
38: public void reallyClose() {
39: try {
40: conn.close();
41: } catch (SQLException e) {
42: e.printStackTrace();
43: }
44: }
45:
46: public void activate() throws Exception {
47: // System.out.println("SimplePoolableConnection.active");
48: this .setUsing(true);
49: }
50:
51: public void passivate() throws Exception {
52: this .setUsing(false);
53: }
54:
55: public void setUsing(boolean b) {
56: using = b;
57: }
58:
59: public boolean isUsing() {
60: return using;
61: }
62:
63: public Connection getConnection() {
64: return conn;
65: }
66:
67: // override java.sql.Connection.close() method
68: // just restore itself to pool ,and setUsint false
69: public void close() {
70: this .setUsing(false);
71: pool.restoreObject(this);
72: }
73:
74: }
|