src/java.sql/share/classes/javax/sql/PooledConnection.java
author darcy
Thu, 01 Nov 2018 20:37:45 -0700
changeset 52380 6b31efbf833e
parent 47216 71c04702a3d5
permissions -rw-r--r--
6304578: (reflect) toGenericString fails to print bounds of type variables on generic methods Reviewed-by: vromero, plevart, briangoetz, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
44774
21440c558571 8178915: Minor update to the PooledConnection javadoc
lancea
parents: 33524
diff changeset
     2
 * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.sql;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.sql.Connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.sql.SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * An object that provides hooks for connection pool management.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A <code>PooledConnection</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * represents a physical connection to a data source.  The connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * can be recycled rather than being closed when an application is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * finished with it, thus reducing the number of connections that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * need to be made.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * An application programmer does not use the <code>PooledConnection</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * interface directly; rather, it is used by a middle tier infrastructure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * that manages the pooling of connections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * When an application calls the method <code>DataSource.getConnection</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * it gets back a <code>Connection</code> object.  If connection pooling is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * being done, that <code>Connection</code> object is actually a handle to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a <code>PooledConnection</code> object, which is a physical connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * The connection pool manager, typically the application server, maintains
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * a pool of <code>PooledConnection</code> objects.  If there is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <code>PooledConnection</code> object available in the pool, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * connection pool manager returns a <code>Connection</code> object that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * is a handle to that physical connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * If no <code>PooledConnection</code> object is available, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * connection pool manager calls the <code>ConnectionPoolDataSource</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * method <code>getPoolConnection</code> to create a new physical connection.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *  JDBC driver implementing <code>ConnectionPoolDataSource</code> creates a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *  new <code>PooledConnection</code> object and returns a handle to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * When an application closes a connection, it calls the <code>Connection</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * method <code>close</code>. When connection pooling is being done,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * the connection pool manager is notified because it has registered itself as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * a <code>ConnectionEventListener</code> object using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <code>ConnectionPool</code> method <code>addConnectionEventListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * The connection pool manager deactivates the handle to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the <code>PooledConnection</code> object and  returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <code>PooledConnection</code> object to the pool of connections so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * it can be used again.  Thus, when an application closes its connection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the underlying physical connection is recycled rather than being closed.
33524
f42f1ed3be7f 8136496: Add Connection.begin/endRequest
lancea
parents: 25859
diff changeset
    69
 * <p>
f42f1ed3be7f 8136496: Add Connection.begin/endRequest
lancea
parents: 25859
diff changeset
    70
 * If the connection pool manager wraps or provides a proxy to the logical
f42f1ed3be7f 8136496: Add Connection.begin/endRequest
lancea
parents: 25859
diff changeset
    71
 * handle returned from a call to {@code PoolConnection.getConnection}, the pool
44774
21440c558571 8178915: Minor update to the PooledConnection javadoc
lancea
parents: 33524
diff changeset
    72
 * manager must do one of the following when the connection pool manager
21440c558571 8178915: Minor update to the PooledConnection javadoc
lancea
parents: 33524
diff changeset
    73
 * closes or returns the {@code PooledConnection} to the pool in response to
21440c558571 8178915: Minor update to the PooledConnection javadoc
lancea
parents: 33524
diff changeset
    74
 * the application calling {@code Connection.close}:
33524
f42f1ed3be7f 8136496: Add Connection.begin/endRequest
lancea
parents: 25859
diff changeset
    75
 * <ul>
f42f1ed3be7f 8136496: Add Connection.begin/endRequest
lancea
parents: 25859
diff changeset
    76
 * <li>call {@code endRequest} on the logical {@code Connection} handle
f42f1ed3be7f 8136496: Add Connection.begin/endRequest
lancea
parents: 25859
diff changeset
    77
 * <li>call {@code close} on the logical {@code Connection} handle
f42f1ed3be7f 8136496: Add Connection.begin/endRequest
lancea
parents: 25859
diff changeset
    78
 * </ul>
f42f1ed3be7f 8136496: Add Connection.begin/endRequest
lancea
parents: 25859
diff changeset
    79
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * The physical connection is not closed until the connection pool manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * calls the <code>PooledConnection</code> method <code>close</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * This method is generally called to have an orderly shutdown of the server or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * if a fatal error has made the connection unusable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14342
diff changeset
    86
 * A connection pool manager is often also a statement pool manager, maintaining
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *  a pool of <code>PreparedStatement</code> objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *  When an application closes a prepared statement, it calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *  <code>PreparedStatement</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * method <code>close</code>. When <code>Statement</code> pooling is being done,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * the pool manager is notified because it has registered itself as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * a <code>StatementEventListener</code> object using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <code>ConnectionPool</code> method <code>addStatementEventListener</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *  Thus, when an application closes its  <code>PreparedStatement</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * the underlying prepared statement is recycled rather than being closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
public interface PooledConnection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
   * Creates and returns a <code>Connection</code> object that is a handle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
   * for the physical connection that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
   * this <code>PooledConnection</code> object represents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
   * The connection pool manager calls this method when an application has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
   * called the method <code>DataSource.getConnection</code> and there are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
   * no <code>PooledConnection</code> objects available. See the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
   * {@link PooledConnection interface description} for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
   * @return  a <code>Connection</code> object that is a handle to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
   *          this <code>PooledConnection</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
   * @exception SQLException if a database access error occurs
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   114
   * @exception java.sql.SQLFeatureNotSupportedException if the JDBC driver does not support
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
   * this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
   * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
  Connection getConnection() throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
   * Closes the physical connection that this <code>PooledConnection</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
   * object represents.  An application never calls this method directly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
   * it is called by the connection pool module, or manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
   * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
   * See the {@link PooledConnection interface description} for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
   * information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
   * @exception SQLException if a database access error occurs
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 5506
diff changeset
   129
   * @exception java.sql.SQLFeatureNotSupportedException if the JDBC driver does not support
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
   * this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
   * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
  void close() throws SQLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
   * Registers the given event listener so that it will be notified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
   * when an event occurs on this <code>PooledConnection</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
   * @param listener a component, usually the connection pool manager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
   *        that has implemented the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
   *        <code>ConnectionEventListener</code> interface and wants to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
   *        notified when the connection is closed or has an error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
   * @see #removeConnectionEventListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
  void addConnectionEventListener(ConnectionEventListener listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
  /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
   * Removes the given event listener from the list of components that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
   * will be notified when an event occurs on this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
   * <code>PooledConnection</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
   *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
   * @param listener a component, usually the connection pool manager,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
   *        that has implemented the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
   *        <code>ConnectionEventListener</code> interface and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
   *        been registered with this <code>PooledConnection</code> object as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
   *        a listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
   * @see #addConnectionEventListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
  void removeConnectionEventListener(ConnectionEventListener listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * Registers a <code>StatementEventListener</code> with this <code>PooledConnection</code> object.  Components that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * wish to be notified when  <code>PreparedStatement</code>s created by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * connection are closed or are detected to be invalid may use this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         * to register a <code>StatementEventListener</code> with this <code>PooledConnection</code> object.
24197
a5c2cff81e25 8039488: Tidy warnings cleanup for javax.sql
yan
parents: 23010
diff changeset
   166
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         * @param listener      an component which implements the <code>StatementEventListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         *                                      interface that is to be registered with this <code>PooledConnection</code> object
24197
a5c2cff81e25 8039488: Tidy warnings cleanup for javax.sql
yan
parents: 23010
diff changeset
   169
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        public void addStatementEventListener(StatementEventListener listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * Removes the specified <code>StatementEventListener</code> from the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         * components that will be notified when the driver detects that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * <code>PreparedStatement</code> has been closed or is invalid.
24197
a5c2cff81e25 8039488: Tidy warnings cleanup for javax.sql
yan
parents: 23010
diff changeset
   178
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         * @param listener      the component which implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         *                                      <code>StatementEventListener</code> interface that was previously
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         *                                      registered with this <code>PooledConnection</code> object
24197
a5c2cff81e25 8039488: Tidy warnings cleanup for javax.sql
yan
parents: 23010
diff changeset
   182
         *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        public void removeStatementEventListener(StatementEventListener listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 }