Package javax.sql

Examples of javax.sql.ConnectionEventListener


   * Test the nb of closeEvents generated by a PooledConnection. A
   * JDBC-compliant driver should only generate 1 closeEvent each time
   * connection.close() is called.
   */
  public void testCloseEvent() {
    final ConnectionEventListener conListener = new ConnectionListener();
    PooledConnection pc = null;
    final int NB_TESTS = 5;

    try {
      pc = this.cpds.getPooledConnection();
View Full Code Here


        if (eventListener != null && !eventListener.isEmpty()) {
            ConnectionEvent event = new ConnectionEvent(this, exception);
            eventIterators++;
            try {
                for (Iterator it = eventListener.iterator(); it.hasNext();) {
                    ConnectionEventListener l =
                            (ConnectionEventListener) it.next();
                    if (exception == null) {
                        l.connectionClosed(event);
                    } else {
                        l.connectionErrorOccurred(event);
                    }
                }
            } finally {
                eventIterators--;
            }
View Full Code Here

     * ConnectionEventListener.connectionClosed() is called.
     */
    private void subtestPooledReuseOnClose(final PooledConnection pc) throws SQLException
    {
      final Connection[] newConn = new Connection[1];
      pc.addConnectionEventListener(new ConnectionEventListener() {

        /**
         * Mimic a pool handler that returns the PooledConnection
         * to the pool and then reallocates it to a new logical connection.
         */
 
View Full Code Here

     * Tests that a pooled connection can successfully be closed
     * during the processing of its close event by its listener.
     */
    private void subtestPooledCloseOnClose(final PooledConnection pc) throws SQLException
    {
        pc.addConnectionEventListener(new ConnectionEventListener() {

            /**
             * Mimic a pool handler that closes the PooledConnection
             * (say it no longer needs it, pool size being reduced)
             */
 
View Full Code Here

     */
    private void subtestPooledRemoveListenerOnClose(final PooledConnection pc) throws SQLException
    {
       
        final int[] count1 = new int[1];
        pc.addConnectionEventListener(new ConnectionEventListener() {

            /**
             * Mimic a pool handler that removes the listener during
             * a logical close.
             */
            public void connectionClosed(ConnectionEvent event) {
                PooledConnection pce = (PooledConnection) event.getSource();
                assertSame(pc, pce);
                count1[0]++;
                pce.removeConnectionEventListener(this);
            }

            public void connectionErrorOccurred(ConnectionEvent event) {
            }
           
        });
       
        // and have another listener to ensure removing one leaves
        // the other working and intact.
        final int[] count2 = new int[1];
        pc.addConnectionEventListener(new ConnectionEventListener() {

            /**
             * Mimic a pool handler that closes the PooledConnection
             * (say it no longer needs it, pool size being reduced)
             */
 
View Full Code Here

        // has been triggered, number of times added listeners have been
        // triggered }.
        final int[] count = new int[2];

        // Register the main listener
        pc.addConnectionEventListener(new ConnectionEventListener() {

            public void connectionClosed(ConnectionEvent event) {
                assertSame(pc, event.getSource());
                count[0]++;
                // Register a new listener
                pc.addConnectionEventListener(new ConnectionEventListener() {
                    public void connectionClosed(ConnectionEvent e) {
                        assertSame(pc, e.getSource());
                        count[1]++;
                    }
                    public void connectionErrorOccurred(ConnectionEvent e) {
View Full Code Here

    ConnectionEvent connectionevent = new ConnectionEvent(this,
        sqlException);

    while (enumeration.hasMoreElements()) {

      ConnectionEventListener connectioneventlistener = (ConnectionEventListener) enumeration
          .nextElement();
      ConnectionEventListener connectioneventlistener1 = (ConnectionEventListener) this.eventListeners
          .get(connectioneventlistener);

      if (eventType == CONNECTION_CLOSED_EVENT) {
        connectioneventlistener1.connectionClosed(connectionevent);
      } else if (eventType == CONNECTION_ERROR_EVENT) {
        connectioneventlistener1
            .connectionErrorOccurred(connectionevent);
      }
    }
  }
View Full Code Here

                new ConnectionEvent(this) :
                new ConnectionEvent(this, exception.getSQLException());
            eventIterators++;
            try {
                for (Iterator it = listeners_.iterator(); it.hasNext(); ) {
                    final ConnectionEventListener listener =
                        (ConnectionEventListener) it.next();
                    if (exception == null) {
                        listener.connectionClosed(event);
                    } else {
                        listener.connectionErrorOccurred(event);
                    }
                }
            } finally {
                eventIterators--;
            }
View Full Code Here

                return;

            ConnectionEvent closedEvent = new ConnectionEvent(this, exception);
            Iterator listeners = connectionEventListeners.iterator();
            while (listeners.hasNext()) {
                ConnectionEventListener nextListener = (ConnectionEventListener) listeners
                        .next();
                nextListener.connectionErrorOccurred(closedEvent);
            }
        }
    }
View Full Code Here

            ConnectionEvent closedEvent = new ConnectionEvent(this);
            Iterator listeners = connectionEventListeners.iterator();

            while (listeners.hasNext()) {
                ConnectionEventListener nextListener = (ConnectionEventListener) listeners
                        .next();
                nextListener.connectionClosed(closedEvent);
            }
        }
    }
View Full Code Here

TOP

Related Classes of javax.sql.ConnectionEventListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.