1 /*
   2  * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * Created on Apr 28, 2005
  28  */
  29 package javax.sql;
  30 
  31 /**
  32  * An object that registers to be notified of events that occur on PreparedStatements
  33  * that are in the Statement pool.
  34  * <p>
  35  * The JDBC 3.0 specification added the maxStatements
  36  * <code>ConnectionPooledDataSource</code> property to provide a standard mechanism for
  37  * enabling the pooling of <code>PreparedStatements</code>
  38  * and to specify the size of the statement
  39  * pool.  However, there was no way for a driver to notify an external
  40  * statement pool when a <code>PreparedStatement</code> becomes invalid.  For some databases, a
  41  * statement becomes invalid if a DDL operation is performed that affects the
  42  * table.  For example an application may create a temporary table to do some work
  43  * on the table and then destroy it.  It may later recreate the same table when
  44  * it is needed again.  Some databases will invalidate any prepared statements
  45  * that reference the temporary table when the table is dropped.
  46  * <p>
  47  * Similar to the methods defined in the <code>ConnectionEventListener</code> interface,
  48  * the driver will call the <code>StatementEventListener.statementErrorOccurred</code>
  49  * method prior to throwing any exceptions when it detects a statement is invalid.
  50  * The driver will also call the <code>StatementEventListener.statementClosed</code>
  51  * method when a <code>PreparedStatement</code> is closed.
  52  * <p>
  53  * Methods which allow a component to register a StatementEventListener with a
  54  * <code>PooledConnection</code> have been added to the <code>PooledConnection</code> interface.
  55  *
  56  * @since 1.6
  57  */
  58 public interface StatementEventListener  extends java.util.EventListener{
  59   /**
  60    * The driver calls this method on all <code>StatementEventListener</code>s registered on the connection when it detects that a
  61    * <code>PreparedStatement</code> is closed.
  62    *
  63    * @param event an event object describing the source of
  64    * the event and that the <code>PreparedStatement</code> was closed.
  65    * @since 1.6
  66    */
  67   void statementClosed(StatementEvent event);
  68 
  69         /**
  70          * The driver calls this method on all <code>StatementEventListener</code>s
  71          * registered on the connection when it detects that a
  72          * <code>PreparedStatement</code> is invalid. The driver calls this method
  73          * just before it throws the <code>SQLException</code>,
  74          * contained in the given event, to the application.
  75          *
  76          * @param event    an event object describing the source of the event,
  77          *                 the statement that is invalid and the exception the
  78          *                 driver is about to throw.  The source of the event is
  79          *                 the <code>PooledConnection</code> which the invalid <code>PreparedStatement</code>
  80          *                 is associated with.
  81          *
  82          * @since 1.6
  83          */
  84         void statementErrorOccurred(StatementEvent event);
  85 
  86 }