Java Code Examples for javax.sql.ConnectionEvent#getSource()

The following examples show how to use javax.sql.ConnectionEvent#getSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyedCPDSConnectionFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo info = pcMap.get(pc);
    if (info == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(info.getUserPassKey(), info);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
        e.printStackTrace();
    }
}
 
Example 2
Source File: CPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo pci = pcMap.get(pc);
    if (pci == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(pci);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
        e.printStackTrace();
    }
}
 
Example 3
Source File: CPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the
 * user calls the close() method of this connection object. What we need to do here is to release this
 * PooledConnection from our pool...
 */
@Override
public void connectionClosed(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    // if this event occurred because we were validating, ignore it
    // otherwise return the connection to the pool.
    if (!validatingSet.contains(pc)) {
        final PooledConnectionAndInfo pci = pcMap.get(pc);
        if (pci == null) {
            throw new IllegalStateException(NO_KEY_MESSAGE);
        }

        try {
            pool.returnObject(pci);
        } catch (final Exception e) {
            System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + "NOT BE RETURNED TO THE POOL");
            pc.removeConnectionEventListener(this);
            try {
                doDestroyObject(pci);
            } catch (final Exception e2) {
                System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
                e2.printStackTrace();
            }
        }
    }
}
 
Example 4
Source File: KeyedCPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo info = pcMap.get(pc);
    if (info == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(info.getUserPassKey(), info);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + info);
        e.printStackTrace();
    }
}
 
Example 5
Source File: KeyedCPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 6 votes vote down vote up
/**
 * This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the
 * user calls the close() method of this connection object. What we need to do here is to release this
 * PooledConnection from our pool...
 */
@Override
public void connectionClosed(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    // if this event occurred because we were validating, or if this
    // connection has been marked for removal, ignore it
    // otherwise return the connection to the pool.
    if (!validatingSet.contains(pc)) {
        final PooledConnectionAndInfo pci = pcMap.get(pc);
        if (pci == null) {
            throw new IllegalStateException(NO_KEY_MESSAGE);
        }
        try {
            pool.returnObject(pci.getUserPassKey(), pci);
        } catch (final Exception e) {
            System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + "NOT BE RETURNED TO THE POOL");
            pc.removeConnectionEventListener(this);
            try {
                pool.invalidateObject(pci.getUserPassKey(), pci);
            } catch (final Exception e3) {
                System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
                e3.printStackTrace();
            }
        }
    }
}
 
Example 6
Source File: PooledCassandraDataSource.java    From cassandra-jdbc-wrapper with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void connectionErrorOccurred(ConnectionEvent event)
{
	PooledCassandraConnection connection = (PooledCassandraConnection) event.getSource();
	try
	{
		if (!connection.getConnection().isValid(CONNECTION_IS_VALID_TIMEOUT)) {
			connection.getConnection().close();
		}
	}
	catch (SQLException e)
	{
		logger.error(e.getMessage());
	}
	usedConnections.remove(connection);
}
 
Example 7
Source File: PooledCassandraDataSource.java    From cassandra-jdbc-wrapper with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void connectionClosed(ConnectionEvent event)
{
	PooledCassandraConnection connection = (PooledCassandraConnection) event.getSource();
	usedConnections.remove(connection);
	int freeConnectionsCount = freeConnections.size();
	if (freeConnectionsCount < MIN_POOL_SIZE)
	{
		freeConnections.add(connection);
	}
	else
	{
		try
		{
			connection.close();
		}
		catch (SQLException e)
		{
			logger.error(e.getMessage());
		}
	}
}
 
Example 8
Source File: CPDSConnectionFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * If a fatal error occurs, close the underlying physical connection so as not to be returned in the future
 */
@Override
public void connectionErrorOccurred(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    if (null != event.getSQLException()) {
        System.err.println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" + event.getSQLException() + ")");
    }
    pc.removeConnectionEventListener(this);

    final PooledConnectionAndInfo pci = pcMap.get(pc);
    if (pci == null) {
        throw new IllegalStateException(NO_KEY_MESSAGE);
    }
    try {
        pool.invalidateObject(pci);
    } catch (final Exception e) {
        System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
        e.printStackTrace();
    }
}
 
Example 9
Source File: CPDSConnectionFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the
 * user calls the close() method of this connection object. What we need to do here is to release this
 * PooledConnection from our pool...
 */
@Override
public void connectionClosed(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    // if this event occurred because we were validating, ignore it
    // otherwise return the connection to the pool.
    if (!validatingSet.contains(pc)) {
        final PooledConnectionAndInfo pci = pcMap.get(pc);
        if (pci == null) {
            throw new IllegalStateException(NO_KEY_MESSAGE);
        }

        try {
            pool.returnObject(pci);
        } catch (final Exception e) {
            System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + "NOT BE RETURNED TO THE POOL");
            pc.removeConnectionEventListener(this);
            try {
                doDestroyObject(pci);
            } catch (final Exception e2) {
                System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
                e2.printStackTrace();
            }
        }
    }
}
 
Example 10
Source File: KeyedCPDSConnectionFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * This will be called if the Connection returned by the getConnection method came from a PooledConnection, and the
 * user calls the close() method of this connection object. What we need to do here is to release this
 * PooledConnection from our pool...
 */
@Override
public void connectionClosed(final ConnectionEvent event) {
    final PooledConnection pc = (PooledConnection) event.getSource();
    // if this event occurred because we were validating, or if this
    // connection has been marked for removal, ignore it
    // otherwise return the connection to the pool.
    if (!validatingSet.contains(pc)) {
        final PooledConnectionAndInfo pci = pcMap.get(pc);
        if (pci == null) {
            throw new IllegalStateException(NO_KEY_MESSAGE);
        }
        try {
            pool.returnObject(pci.getUserPassKey(), pci);
        } catch (final Exception e) {
            System.err.println("CLOSING DOWN CONNECTION AS IT COULD " + "NOT BE RETURNED TO THE POOL");
            pc.removeConnectionEventListener(this);
            try {
                pool.invalidateObject(pci.getUserPassKey(), pci);
            } catch (final Exception e3) {
                System.err.println("EXCEPTION WHILE DESTROYING OBJECT " + pci);
                e3.printStackTrace();
            }
        }
    }
}
 
Example 11
Source File: GemFireConnPooledDataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Implementation of call back function from ConnectionEventListener
 * interface. This callback will be invoked on connection error event.
 * 
 * @param event
 */
public void connectionErrorOccurred(ConnectionEvent event) {
  if (isActive) {
    try {
      PooledConnection conn = (PooledConnection) event.getSource();
      provider.returnAndExpireConnection(conn);
    }
    catch (Exception ex) {
      String exception = "GemFireConnPooledDataSource::connectionErrorOccured:error in returning and expiring connection due to "
          + ex;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, ex);
    }
  }
}
 
Example 12
Source File: GemFireConnPooledDataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Implementation of call back function from ConnectionEventListener
 * interface. This callback will be invoked on connection close event.
 * 
 * @param event
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    try {
      PooledConnection conn = (PooledConnection) event.getSource();
      provider.returnConnection(conn);
    }
    catch (Exception ex) {
      String exception = "GemFireConnPooledDataSource::connectionclosed:Exception ="
          + ex;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, ex);
    }
  }
}
 
Example 13
Source File: GemFireConnPooledDataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Implementation of call back function from ConnectionEventListener
 * interface. This callback will be invoked on connection error event.
 * 
 * @param event
 */
public void connectionErrorOccurred(ConnectionEvent event) {
  if (isActive) {
    try {
      PooledConnection conn = (PooledConnection) event.getSource();
      provider.returnAndExpireConnection(conn);
    }
    catch (Exception ex) {
      String exception = "GemFireConnPooledDataSource::connectionErrorOccured:error in returning and expiring connection due to "
          + ex;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, ex);
    }
  }
}
 
Example 14
Source File: GemFireConnPooledDataSource.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Implementation of call back function from ConnectionEventListener
 * interface. This callback will be invoked on connection close event.
 * 
 * @param event
 */
public void connectionClosed(ConnectionEvent event) {
  if (isActive) {
    try {
      PooledConnection conn = (PooledConnection) event.getSource();
      provider.returnConnection(conn);
    }
    catch (Exception ex) {
      String exception = "GemFireConnPooledDataSource::connectionclosed:Exception ="
          + ex;
      LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
      if (writer.fineEnabled()) writer.fine(exception, ex);
    }
  }
}
 
Example 15
Source File: JDBCPool.java    From evosql with Apache License 2.0 5 votes vote down vote up
public void connectionErrorOccurred(ConnectionEvent event) {
    PooledConnection connection = (PooledConnection) event.getSource();

    for (int i = 0; i < connections.length; i++) {
        if (connections[i] == connection) {
            states.set(i, RefState.allocated);
            connections[i] = null;
            states.set(i, RefState.empty);
            break;
        }
    }
}
 
Example 16
Source File: JDBCPool.java    From evosql with Apache License 2.0 5 votes vote down vote up
public void connectionClosed(ConnectionEvent event) {
    PooledConnection connection = (PooledConnection) event.getSource();

    for (int i = 0; i < connections.length; i++) {
        if (connections[i] == connection) {
            states.set(i, RefState.available);

            break;
        }
    }
}
 
Example 17
Source File: ConnectionEventMatcher.java    From jaybird with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public boolean matchesSafely(ConnectionEvent item) {
    return item.getSource() == pooled && exceptionMatcher.matches(item.getSQLException());
}
 
Example 18
Source File: MiniConnectionPoolManager.java    From fixflow with Apache License 2.0 4 votes vote down vote up
public void connectionClosed(ConnectionEvent event) {
	PooledConnection pconn = (PooledConnection) event.getSource();
	recycleConnection(pconn);
}
 
Example 19
Source File: MiniConnectionPoolManager.java    From fixflow with Apache License 2.0 4 votes vote down vote up
public void connectionErrorOccurred(ConnectionEvent event) {
	PooledConnection pconn = (PooledConnection) event.getSource();
	disposeConnection(pconn);
}