KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > threetier > ExternalConnectionPool


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.threetier;
23
24 import oracle.toplink.essentials.internal.databaseaccess.*;
25 import oracle.toplink.essentials.sessions.Login;
26 import oracle.toplink.essentials.exceptions.*;
27
28 /**
29  * <p>
30  * <b>Purpose</b>: This subclass is intended to be used with external connection pools.
31  * For these pools, TopLink does not control the pooling behaviour.
32  * The login should have the usesExternalConnectionPooling set to "true".
33  */

34 public class ExternalConnectionPool extends ConnectionPool {
35     protected Accessor cachedConnection;
36
37     /**
38      * PUBLIC:
39      * Build a new external connection pool. The JDBC driver is responsible for pooling the connections.
40      */

41     public ExternalConnectionPool() {
42         super();
43     }
44
45     /**
46      * PUBLIC:
47      * Build a new external connection pool. The JDBC driver is responsible for pooling the connections.
48      */

49     public ExternalConnectionPool(String JavaDoc name, Login login, ServerSession owner) {
50         super(name, login, 0, 0, owner);
51     }
52
53     /**
54      * INTERNAL:
55      * When we acquire a connection from an ExternalConnectionPool we build
56      * a new connection (retrieve it from the external pool).
57      */

58     public synchronized Accessor acquireConnection() throws ConcurrencyException {
59         return (Accessor)getCachedConnection().clone();
60     }
61
62     /**
63      * INTERNAL:
64      * Return the currently cached connection to the external connection pool
65      * @return oracle.toplink.essentials.internal.databaseaccess.Accessor
66      */

67     protected Accessor getCachedConnection() {
68         return cachedConnection;
69     }
70
71     /**
72      * INTERNAL:
73      * Assume true as the driver is responsible for blocking.
74      */

75     public boolean hasConnectionAvailable() {
76         return true;
77     }
78
79     /**
80      * INTERNAL:
81      * Checks for a conflict between pool's type and pool's login
82      */

83     public boolean isThereConflictBetweenLoginAndType() {
84         return !getLogin().shouldUseExternalConnectionPooling();
85     }
86
87     /**
88      * INTERNAL:
89      * When you release an external connection, you simply let it go.
90      */

91     public synchronized void releaseConnection(Accessor connection) throws DatabaseException {
92         getConnectionsUsed().removeElement(connection);
93         connection.closeConnection();
94         notify();
95     }
96
97     /**
98      * Set the currently cached connection to the external connection pool.
99      * @param oracle.toplink.essentials.internal.databaseaccess.Accessor
100      */

101     protected void setCachedConnection(Accessor cachedConnection) {
102         this.cachedConnection = cachedConnection;
103     }
104
105     /**
106      * INTERNAL:
107      * This mehtod is a no-op for external pools.
108      */

109     public synchronized void shutDown() {
110         //do nothing
111
setIsConnected(false);
112     }
113
114     /**
115      * INTERNAL:
116      * Build the default connection.
117      * This validates that connect will work and sets up the parent accessor to clone.
118      */

119     public synchronized void startUp() {
120         setCachedConnection(buildConnection());
121         setIsConnected(true);
122     }
123 }
124
Popular Tags