Java 8 ConnectionEvent - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ConnectionEvent class.

This code example shows how to use the following methods:getSource
public class OldConnectionEventTest extends TestCase {
 
    public void testConstructorConnection() { 
        Impl_PooledConnection ipc = new Impl_PooledConnection();
        ConnectionEvent ce = new ConnectionEvent(ipc);
        ConnectionEvent ce2 = new ConnectionEvent(ipc,null);
        assertSame(ce2.getSource(),ce.getSource());
    } 
 
    public void testGetSQLException() { 
        Impl_PooledConnection ipc = new Impl_PooledConnection();
        ConnectionEvent ce = new ConnectionEvent(ipc);
 
        ConnectionEvent ce2 = new ConnectionEvent(ipc, null);
        assertNull(ce.getSQLException());
        assertEquals(ce2.getSQLException(), ce.getSQLException());
 
        SQLException e = new SQLException();
        ConnectionEvent ce3 = new ConnectionEvent(ipc, e);
        assertNotNull(ce3.getSQLException());
5
CodeRank
This code example shows how to use the following methods:getSource, getSQLException
     * If a fatal error occurs, close the underlying physical connection so as 
     * not to be returned in the future 
     */ 
    @Override 
    public void connectionErrorOccurred(ConnectionEvent event) {
        PooledConnection pc = (PooledConnection)event.getSource();
        if (null != event.getSQLException()) {
            System.err
                .println("CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" +
                         event.getSQLException() + ")");
        } 
        pc.removeConnectionEventListener(this);
 
        PooledConnectionAndInfo info = pcMap.get(pc);
        if (info == null) {
            throw new IllegalStateException(NO_KEY_MESSAGE);
        } 
        try { 
            _pool.invalidateObject(info.getUserPassKey(), info);
        } catch (Exception e) {
5
CodeRank
This code example shows how to use the following methods:getSource, getSQLException
     * If a fatal error occurs, close the underlying physical connection so as 
     * not to be returned in the future 
     */ 
    @Override 
    public void connectionErrorOccurred(ConnectionEvent event) {
        PooledConnection pc = (PooledConnection)event.getSource();
        if (null != event.getSQLException()) {
            System.err.println(
                    "CLOSING DOWN CONNECTION DUE TO INTERNAL ERROR (" 
                    + event.getSQLException() + ")");
        } 
        pc.removeConnectionEventListener(this);
 
        PooledConnectionAndInfo pci = pcMap.get(pc);
        if (pci == null) {
            throw new IllegalStateException(NO_KEY_MESSAGE);
        } 
        try { 
            _pool.invalidateObject(pci);
        } catch (Exception e) {
5
CodeRank
This code example shows how to use the following methods:getSource
     * method of this connection object. What we need to do here is to 
     * release this PooledConnection from our pool... 
     */ 
    @Override 
    public void connectionClosed(ConnectionEvent event) {
        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)) {
            PooledConnectionAndInfo pci = pcMap.get(pc);
            if (pci == null) {
                throw new IllegalStateException(NO_KEY_MESSAGE);
            } 
 
            try { 
                _pool.returnObject(pci);
            } catch (Exception e) {
                System.err.println("CLOSING DOWN CONNECTION AS IT COULD "
                        + "NOT BE RETURNED TO THE POOL"); 
                pc.removeConnectionEventListener(this);
3
CodeRank
This code example shows how to use the following methods:getSource
     * 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... 
     */ 
    public void connectionClosed(ConnectionEvent event) {
        PooledConnection pc = (PooledConnection) event.getSource();
        // if this event occured becase we were validating, ignore it 
        // otherwise return the connection to the pool. 
        if (!validatingMap.containsKey(pc)) {
            Object info = pcMap.get(pc);
            if (info == null) { 
                throw new IllegalStateException(NO_KEY_MESSAGE);
            } 
 
            try { 
                _pool.returnObject(info);
            } catch (Exception e) {
                System.err.println("CLOSING DOWN CONNECTION AS IT COULD "
                        + "NOT BE RETURNED TO THE POOL"); 
                try { 
4
CodeRank
This code example shows how to use the following methods:getSource
     * method of this connection object. What we need to do here is to 
     * release this PooledConnection from our pool... 
     */ 
    @Override 
    public void connectionClosed(ConnectionEvent event) {
        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)) {
            PooledConnectionAndInfo pci = pcMap.get(pc);
            if (pci == null) {
                throw new IllegalStateException(NO_KEY_MESSAGE);
            } 
            try { 
                _pool.returnObject(pci.getUserPassKey(), pci);
            } catch (Exception e) {
                System.err.println("CLOSING DOWN CONNECTION AS IT COULD " +
                "NOT BE RETURNED TO THE POOL"); 
                pc.removeConnectionEventListener(this);
3
CodeRank
This code example shows how to use the following methods:getSource
     * 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... 
     */ 
    public void connectionClosed(ConnectionEvent event) {
        PooledConnection pc = (PooledConnection)event.getSource();
        // if this event occured becase we were validating, ignore it 
        // otherwise return the connection to the pool. 
        if (!validatingMap.containsKey(pc)) {
            PooledConnectionAndInfo info =
                (PooledConnectionAndInfo) pcMap.get(pc);
            if (info == null) {
                throw new IllegalStateException(NO_KEY_MESSAGE);
            } 
            try { 
                _pool.returnObject(info.getUserPassKey(), info);
            } catch (Exception e) {
                System.err.println("CLOSING DOWN CONNECTION AS IT COULD " +
                                   "NOT BE RETURNED TO THE POOL"); 
                try { 
4
CodeRank
This code example shows how to use the following methods:getSource
        return this.maxPoolSize > size();
    } 
 
    public synchronized void connectionClosed(ConnectionEvent event) {
 
        PooledConnection connection = (PooledConnection) event.getSource();
 
        this.connectionsInUse.remove(connection);
        this.sessionConnectionWrappers.remove(connection);
 
        if (!this.isPoolClosed) {
            enqueue(connection);
            logInfo("Connection returned to pool."); 
        } else { 
            closePhysically(connection, "closing returned connection.");
            logInfo( 
                "Connection returned to pool was closed because pool is closed."); 
            this.notifyAll();    //notifies evt. threads waiting for connection or for the pool to close.
        } 
    } 
4
CodeRank
This code example shows how to use the following methods:getSource
 
    /** 
     * INTERNAL 
     */ 
    public void connectionClosed(ConnectionEvent event) {
        PooledConnection pc = (PooledConnection) event.getSource();
        pc.removeConnectionEventListener(this);
        recycleConnection(pc);
    } 
 
    /** 
     * INTERNAL 
     */ 
    public void connectionErrorOccurred(ConnectionEvent event) {
        // not used 
    } 
 
    /** 
     * Returns the number of active (open) connections of this pool. This is the 
     * number of <code>Connection</code> objects that have been issued by 
4
CodeRank
This code example shows how to use the following methods:getSource
	/** 
	 * INTERNAL 
	 */ 
	@Override 
	public void connectionClosed(final ConnectionEvent event) {
		final PooledConnection pc = (PooledConnection) event.getSource();
		pc.removeConnectionEventListener(this);
		recycleConnection(pc);
	} 
 
	/** 
	 * INTERNAL 
	 */ 
	@Override 
	public void connectionErrorOccurred(final ConnectionEvent event) {
		// not used 
	} 
 
	/** 
	 * Returns the number of active (open) connections of this pool. This is the 
4
CodeRank
See Code Examples for Java 8 ConnectionEvent Methods: