01: package example;
02:
03: import java.io.*;
04: import java.util.*;
05:
06: import javax.resource.*;
07: import javax.resource.spi.*;
08: import javax.security.auth.*;
09:
10: /**
11: * Implementation of the user's view of the connection. This
12: * class is entirely customizable.
13: *
14: * Normally, it will just be a facade to the underlying managed
15: * connection.
16: */
17: public class ConnectionImpl {
18: private String _name;
19:
20: // Reference to the underlying connection
21: private ManagedConnectionImpl _mConn;
22:
23: private volatile boolean _isClosed;
24:
25: /**
26: * Create the connection, with a reference to the underlying
27: * connection.
28: */
29: ConnectionImpl(String name, ManagedConnectionImpl mConn) {
30: _name = name;
31: _mConn = mConn;
32: }
33:
34: /**
35: * Adding a <code>close()</code> method is very important for any
36: * connection API. It lets Resin know that the user has
37: * closed the connection and Resin can mark the managed connection
38: * as idle and reuse it.
39: *
40: * It is also important that the connection let the user call
41: * <code>close()</code>, but only the allow the first <code>close</code>
42: * to have any effect.
43: *
44: * In particular, it would be a mistake to call <code>_mConn.close</code>
45: * twice since that would tell Resin that the connection had closed
46: * twice, which might confuse Resin's pool.
47: */
48: public void close() {
49: synchronized (this ) {
50: if (_isClosed)
51: return;
52: _isClosed = true;
53: }
54:
55: ManagedConnectionImpl mConn = _mConn;
56: _mConn = null;
57:
58: mConn.close(this );
59: }
60:
61: public String toString() {
62: return "ConnectionImpl[" + _name + "," + _mConn + "]";
63: }
64:
65: public void finalize() {
66: close();
67: }
68: }
|