src/share/classes/javax/sql/StatementEventListener.java

Print this page




  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  * <p>
  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          * <p>
  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          * <p>
  82          * @since 1.6
  83          */
  84         void statementErrorOccurred(StatementEvent event);
  85 
  86 }


  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 }