KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > example > ConnectionFactoryImpl


1 package example;
2
3 import java.io.*;
4 import java.util.*;
5
6 import javax.resource.ResourceException JavaDoc;
7
8 import javax.resource.spi.ConnectionManager JavaDoc;
9
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 JavaDoc _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 JavaDoc connManager)
37   {
38     _mcFactory = mcFactory;
39     _connManager = connManager;
40   }
41
42   /**
43    * Gets an available connection. Something like
44    * <code>getConnection</code>
45    * is the main method most connections factories will implement.
46    * It returns a class specific to the connector.
47    *
48    * @return the user connection facade.
49    */

50   public ConnectionImpl getConnection()
51     throws ResourceException JavaDoc
52   {
53     // Asks Resin to return a new user connection. The second argument
54
// (ConnectionRequestInfo) is null since we have no specific
55
// configuration information to pass along.
56
return (ConnectionImpl) _connManager.allocateConnection(_mcFactory, null);
57   }
58
59   public String JavaDoc toString()
60   {
61     return "ConnectionFactoryImpl[" + _mcFactory + "]";
62   }
63 }
64
Popular Tags