oracle.toplink.essentials.threetier.ExternalConnectionPool Maven / Gradle / Ivy
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* glassfish/bootstrap/legal/CDDLv1.0.txt or
* https://glassfish.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
* permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* HEADER in each file and include the License file at
* glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
* add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your
* own identifying information: Portions Copyright [yyyy]
* [name of copyright owner]
*/
// Copyright (c) 1998, 2007, Oracle. All rights reserved.
package oracle.toplink.essentials.threetier;
import oracle.toplink.essentials.internal.databaseaccess.*;
import oracle.toplink.essentials.sessions.Login;
import oracle.toplink.essentials.exceptions.*;
/**
*
* Purpose: This subclass is intended to be used with external connection pools.
* For these pools, TopLink does not control the pooling behaviour.
* The login should have the usesExternalConnectionPooling set to "true".
*/
public class ExternalConnectionPool extends ConnectionPool {
protected Accessor cachedConnection;
/**
* PUBLIC:
* Build a new external connection pool. The JDBC driver is responsible for pooling the connections.
*/
public ExternalConnectionPool() {
super();
}
/**
* PUBLIC:
* Build a new external connection pool. The JDBC driver is responsible for pooling the connections.
*/
public ExternalConnectionPool(String name, Login login, ServerSession owner) {
super(name, login, 0, 0, owner);
}
/**
* INTERNAL:
* When we acquire a connection from an ExternalConnectionPool we build
* a new connection (retrieve it from the external pool).
*/
public synchronized Accessor acquireConnection() throws ConcurrencyException {
return (Accessor)getCachedConnection().clone();
}
/**
* INTERNAL:
* Return the currently cached connection to the external connection pool
* @return oracle.toplink.essentials.internal.databaseaccess.Accessor
*/
protected Accessor getCachedConnection() {
return cachedConnection;
}
/**
* INTERNAL:
* Assume true as the driver is responsible for blocking.
*/
public boolean hasConnectionAvailable() {
return true;
}
/**
* INTERNAL:
* Checks for a conflict between pool's type and pool's login
*/
public boolean isThereConflictBetweenLoginAndType() {
return !getLogin().shouldUseExternalConnectionPooling();
}
/**
* INTERNAL:
* When you release an external connection, you simply let it go.
*/
public synchronized void releaseConnection(Accessor connection) throws DatabaseException {
getConnectionsUsed().removeElement(connection);
connection.closeConnection();
notify();
}
/**
* Set the currently cached connection to the external connection pool.
* @param oracle.toplink.essentials.internal.databaseaccess.Accessor
*/
protected void setCachedConnection(Accessor cachedConnection) {
this.cachedConnection = cachedConnection;
}
/**
* INTERNAL:
* This mehtod is a no-op for external pools.
*/
public synchronized void shutDown() {
//do nothing
setIsConnected(false);
}
/**
* INTERNAL:
* Build the default connection.
* This validates that connect will work and sets up the parent accessor to clone.
*/
public synchronized void startUp() {
setCachedConnection(buildConnection());
setIsConnected(true);
}
}