01: package net.xoetrope.optional.data.sql;
02:
03: import java.sql.Connection;
04:
05: import net.xoetrope.optional.pool.PoolManager;
06: import net.xoetrope.optional.pool.PoolObject;
07:
08: /**
09: * <p>A wrapper for a connection for use by a ConnectionManager</p>
10: * <p>Copyright (c) Xoetrope Ltd. 2001-2003</p>
11: * $Revision: 1.1 $
12: */
13: public class ConnectionObject extends PoolObject {
14: /**
15: * The JDBC connection
16: */
17: Connection connection;
18:
19: /**
20: * The PoolManager that owns this object
21: */
22: PoolManager poolManager;
23:
24: /**
25: * Constructs a new connection object
26: * @param conn a JDBC connection
27: * @param pool the pool manager
28: */
29: public ConnectionObject(Connection conn, PoolManager pool) {
30: connection = conn;
31: poolManager = pool;
32: }
33:
34: /**
35: * Check to see if a connection can be made and is still in a working state
36: * @return true if the connection is still working
37: */
38: public boolean validate() {
39: try {
40: connection.getMetaData();
41: } catch (Exception e) {
42: return false;
43: }
44: return true;
45: }
46:
47: /**
48: * Return the connection to the connection manager
49: * @throws Exception
50: */
51: public void close() throws Exception {
52: poolManager.returnObject(this);
53: }
54: }
|