001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.threetier;
038:
039: import oracle.toplink.essentials.internal.databaseaccess.*;
040: import oracle.toplink.essentials.sessions.Login;
041: import oracle.toplink.essentials.exceptions.*;
042:
043: /**
044: * <p>
045: * <b>Purpose</b>: This subclass is intended to be used with external connection pools.
046: * For these pools, TopLink does not control the pooling behaviour.
047: * The login should have the usesExternalConnectionPooling set to "true".
048: */
049: public class ExternalConnectionPool extends ConnectionPool {
050: protected Accessor cachedConnection;
051:
052: /**
053: * PUBLIC:
054: * Build a new external connection pool. The JDBC driver is responsible for pooling the connections.
055: */
056: public ExternalConnectionPool() {
057: super ();
058: }
059:
060: /**
061: * PUBLIC:
062: * Build a new external connection pool. The JDBC driver is responsible for pooling the connections.
063: */
064: public ExternalConnectionPool(String name, Login login,
065: ServerSession owner) {
066: super (name, login, 0, 0, owner);
067: }
068:
069: /**
070: * INTERNAL:
071: * When we acquire a connection from an ExternalConnectionPool we build
072: * a new connection (retrieve it from the external pool).
073: */
074: public synchronized Accessor acquireConnection()
075: throws ConcurrencyException {
076: return (Accessor) getCachedConnection().clone();
077: }
078:
079: /**
080: * INTERNAL:
081: * Return the currently cached connection to the external connection pool
082: * @return oracle.toplink.essentials.internal.databaseaccess.Accessor
083: */
084: protected Accessor getCachedConnection() {
085: return cachedConnection;
086: }
087:
088: /**
089: * INTERNAL:
090: * Assume true as the driver is responsible for blocking.
091: */
092: public boolean hasConnectionAvailable() {
093: return true;
094: }
095:
096: /**
097: * INTERNAL:
098: * Checks for a conflict between pool's type and pool's login
099: */
100: public boolean isThereConflictBetweenLoginAndType() {
101: return !getLogin().shouldUseExternalConnectionPooling();
102: }
103:
104: /**
105: * INTERNAL:
106: * When you release an external connection, you simply let it go.
107: */
108: public synchronized void releaseConnection(Accessor connection)
109: throws DatabaseException {
110: getConnectionsUsed().removeElement(connection);
111: connection.closeConnection();
112: notify();
113: }
114:
115: /**
116: * Set the currently cached connection to the external connection pool.
117: * @param oracle.toplink.essentials.internal.databaseaccess.Accessor
118: */
119: protected void setCachedConnection(Accessor cachedConnection) {
120: this .cachedConnection = cachedConnection;
121: }
122:
123: /**
124: * INTERNAL:
125: * This mehtod is a no-op for external pools.
126: */
127: public synchronized void shutDown() {
128: //do nothing
129: setIsConnected(false);
130: }
131:
132: /**
133: * INTERNAL:
134: * Build the default connection.
135: * This validates that connect will work and sets up the parent accessor to clone.
136: */
137: public synchronized void startUp() {
138: setCachedConnection(buildConnection());
139: setIsConnected(true);
140: }
141: }
|