Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sql/PooledConnection.java
38829 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sql;2627import java.sql.Connection;28import java.sql.SQLException;2930/**31* An object that provides hooks for connection pool management.32* A <code>PooledConnection</code> object33* represents a physical connection to a data source. The connection34* can be recycled rather than being closed when an application is35* finished with it, thus reducing the number of connections that36* need to be made.37* <P>38* An application programmer does not use the <code>PooledConnection</code>39* interface directly; rather, it is used by a middle tier infrastructure40* that manages the pooling of connections.41* <P>42* When an application calls the method <code>DataSource.getConnection</code>,43* it gets back a <code>Connection</code> object. If connection pooling is44* being done, that <code>Connection</code> object is actually a handle to45* a <code>PooledConnection</code> object, which is a physical connection.46* <P>47* The connection pool manager, typically the application server, maintains48* a pool of <code>PooledConnection</code> objects. If there is a49* <code>PooledConnection</code> object available in the pool, the50* connection pool manager returns a <code>Connection</code> object that51* is a handle to that physical connection.52* If no <code>PooledConnection</code> object is available, the53* connection pool manager calls the <code>ConnectionPoolDataSource</code>54* method <code>getPoolConnection</code> to create a new physical connection. The55* JDBC driver implementing <code>ConnectionPoolDataSource</code> creates a56* new <code>PooledConnection</code> object and returns a handle to it.57* <P>58* When an application closes a connection, it calls the <code>Connection</code>59* method <code>close</code>. When connection pooling is being done,60* the connection pool manager is notified because it has registered itself as61* a <code>ConnectionEventListener</code> object using the62* <code>ConnectionPool</code> method <code>addConnectionEventListener</code>.63* The connection pool manager deactivates the handle to64* the <code>PooledConnection</code> object and returns the65* <code>PooledConnection</code> object to the pool of connections so that66* it can be used again. Thus, when an application closes its connection,67* the underlying physical connection is recycled rather than being closed.68* <P>69* The physical connection is not closed until the connection pool manager70* calls the <code>PooledConnection</code> method <code>close</code>.71* This method is generally called to have an orderly shutdown of the server or72* if a fatal error has made the connection unusable.73*74* <p>75* A connection pool manager is often also a statement pool manager, maintaining76* a pool of <code>PreparedStatement</code> objects.77* When an application closes a prepared statement, it calls the78* <code>PreparedStatement</code>79* method <code>close</code>. When <code>Statement</code> pooling is being done,80* the pool manager is notified because it has registered itself as81* a <code>StatementEventListener</code> object using the82* <code>ConnectionPool</code> method <code>addStatementEventListener</code>.83* Thus, when an application closes its <code>PreparedStatement</code>,84* the underlying prepared statement is recycled rather than being closed.85* <P>86*87* @since 1.488*/8990public interface PooledConnection {9192/**93* Creates and returns a <code>Connection</code> object that is a handle94* for the physical connection that95* this <code>PooledConnection</code> object represents.96* The connection pool manager calls this method when an application has97* called the method <code>DataSource.getConnection</code> and there are98* no <code>PooledConnection</code> objects available. See the99* {@link PooledConnection interface description} for more information.100*101* @return a <code>Connection</code> object that is a handle to102* this <code>PooledConnection</code> object103* @exception SQLException if a database access error occurs104* @exception java.sql.SQLFeatureNotSupportedException if the JDBC driver does not support105* this method106* @since 1.4107*/108Connection getConnection() throws SQLException;109110/**111* Closes the physical connection that this <code>PooledConnection</code>112* object represents. An application never calls this method directly;113* it is called by the connection pool module, or manager.114* <P>115* See the {@link PooledConnection interface description} for more116* information.117*118* @exception SQLException if a database access error occurs119* @exception java.sql.SQLFeatureNotSupportedException if the JDBC driver does not support120* this method121* @since 1.4122*/123void close() throws SQLException;124125/**126* Registers the given event listener so that it will be notified127* when an event occurs on this <code>PooledConnection</code> object.128*129* @param listener a component, usually the connection pool manager,130* that has implemented the131* <code>ConnectionEventListener</code> interface and wants to be132* notified when the connection is closed or has an error133* @see #removeConnectionEventListener134*/135void addConnectionEventListener(ConnectionEventListener listener);136137/**138* Removes the given event listener from the list of components that139* will be notified when an event occurs on this140* <code>PooledConnection</code> object.141*142* @param listener a component, usually the connection pool manager,143* that has implemented the144* <code>ConnectionEventListener</code> interface and145* been registered with this <code>PooledConnection</code> object as146* a listener147* @see #addConnectionEventListener148*/149void removeConnectionEventListener(ConnectionEventListener listener);150151/**152* Registers a <code>StatementEventListener</code> with this <code>PooledConnection</code> object. Components that153* wish to be notified when <code>PreparedStatement</code>s created by the154* connection are closed or are detected to be invalid may use this method155* to register a <code>StatementEventListener</code> with this <code>PooledConnection</code> object.156* <p>157* @param listener an component which implements the <code>StatementEventListener</code>158* interface that is to be registered with this <code>PooledConnection</code> object159* <p>160* @since 1.6161*/162public void addStatementEventListener(StatementEventListener listener);163164/**165* Removes the specified <code>StatementEventListener</code> from the list of166* components that will be notified when the driver detects that a167* <code>PreparedStatement</code> has been closed or is invalid.168* <p>169* @param listener the component which implements the170* <code>StatementEventListener</code> interface that was previously171* registered with this <code>PooledConnection</code> object172* <p>173* @since 1.6174*/175public void removeStatementEventListener(StatementEventListener listener);176177}178179180