01: package example;
02:
03: import java.io.*;
04: import java.util.*;
05:
06: import javax.resource.ResourceException;
07:
08: import javax.resource.spi.ConnectionManager;
09:
10: import javax.security.auth.*;
11:
12: /**
13: * Application's view of the connection factory. This
14: * class may have any API the connector wants.
15: *
16: * Often, it will just create connections.
17: */
18: public class ConnectionFactoryImpl {
19: // Reference to Resin's ConnectionManager API, used to
20: // allocate a new connection
21: private ConnectionManager _connManager;
22:
23: // Reference to the underlying SPI ManagedConnectionFactory
24: private ManagedConnectionFactoryImpl _mcFactory;
25:
26: private volatile boolean _isClosed;
27:
28: /**
29: * Create the connection factory, with a reference to
30: * Resin's ConnectionManager interface.
31: *
32: * @param mcFactory the connector's SPI ManagedConnectionFactory
33: * @param connManager Resin's ConnectionManager for allocating connections
34: */
35: ConnectionFactoryImpl(ManagedConnectionFactoryImpl mcFactory,
36: ConnectionManager connManager) {
37: _mcFactory = mcFactory;
38: _connManager = connManager;
39: }
40:
41: /**
42: * Gets an available connection. Something like
43: * <code>getConnection</code>
44: * is the main method most connections factories will implement.
45: * It returns a class specific to the connector.
46: *
47: * @return the user connection facade.
48: */
49: public ConnectionImpl getConnection() throws ResourceException {
50: // Asks Resin to return a new user connection. The second argument
51: // (ConnectionRequestInfo) is null since we have no specific
52: // configuration information to pass along.
53: return (ConnectionImpl) _connManager.allocateConnection(
54: _mcFactory, null);
55: }
56:
57: public String toString() {
58: return "ConnectionFactoryImpl[" + _mcFactory + "]";
59: }
60: }
|