PooledConnection addConnectionEventListener - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for PooledConnection addConnectionEventListener method.

This code example shows how to use the following methods:addConnectionEventListener, getConnection
        if (!recycledConnections.isEmpty()) {
            pc = recycledConnections.remove(recycledConnections.size() - 1);
        } else { 
            pc = dataSource.getPooledConnection();
        } 
        Connection conn = pc.getConnection();
        activeConnections++;
        pc.addConnectionEventListener(this);
        return conn;
    } 
 
    /** 
     * This method usually puts the connection back into the pool. There are 
     * some exceptions: if the pool is disposed, the connection is disposed as 
     * well. If the pool is full, the connection is closed. 
     * 
     * @param pc the pooled connection 
     */ 
    synchronized void recycleConnection(PooledConnection pc) {
        if (activeConnections <= 0) {
5
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getConnection
    if (!recycledConnections.isEmpty()) {
      pc = recycledConnections.remove(recycledConnections.size() - 1);
    } else { 
      pc = dataSource.getPooledConnection();
    } 
    Connection conn = pc.getConnection();
    activeConnections.incrementAndGet();
    pc.addConnectionEventListener(this);
    return conn;
  } 
 
  /** 
   * This method usually puts the connection back into the pool. There are some 
   * exceptions: if the pool is disposed, the connection is disposed as well. If 
   * the pool is full, the connection is closed. 
   *  
   * @param pc 
   *          the pooled connection 
   */ 
  synchronized void recycleConnection(PooledConnection pc) {
5
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getConnection
        if (!recycledConnections.isEmpty()) {
            pc = recycledConnections.remove(recycledConnections.size() - 1);
        } else { 
            pc = dataSource.getPooledConnection();
        } 
        Connection conn = pc.getConnection();
        activeConnections++;
        pc.addConnectionEventListener(this);
        return conn;
    } 
 
    /** 
     * This method usually puts the connection back into the pool. There are 
     * some exceptions: if the pool is disposed, the connection is disposed as 
     * well. If the pool is full, the connection is closed. 
     * 
     * @param pc the pooled connection 
     */ 
    synchronized void recycleConnection(PooledConnection pc) {
        if (activeConnections <= 0) {
5
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getConnection, getXAResource
        } else { 
            xaConnection = xaDataSource.getXAConnection(username, password);
        } 
 
        // get the real connection and XAResource from the connection 
        Connection connection = xaConnection.getConnection();
        XAResource xaResource = xaConnection.getXAResource();
 
        // register the xa resource for the connection 
        transactionRegistry.registerConnection(connection, xaResource);
 
        // The Connection we're returning is a handle on the XAConnection. 
        // When the pool calling us closes the Connection, we need to 
        // also close the XAConnection that holds the physical connection. 
        xaConnection.addConnectionEventListener(new ConnectionEventListener() {
 
            @Override 
            public void connectionClosed(ConnectionEvent event) {
                PooledConnection pc = (PooledConnection) event.getSource();
                pc.removeConnectionEventListener(this);
5
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getXAResource
    public synchronized XAResource getXAResource() 
        throws SQLException
    { 
        createConnection(); 
 
        return _connection.getXAResource();
    } 
 
    public boolean hasMoreResources() 
    { 
        if (_dataSource == null)
            try 
            { 
                createDataSource(); 
            } 
            catch (SQLException sqlException)
            { 
                return false; 
            } 
 

4
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getConnection
        if (!recycledConnections.isEmpty()) {
            pc = recycledConnections.remove(recycledConnections.size() - 1);
        } else { 
            pc = dataSource.getPooledConnection();
        } 
        Connection conn = pc.getConnection();
        activeConnections++;
        pc.addConnectionEventListener(this);
        return conn;
    } 
 
    /** 
     * This method usually puts the connection back into the pool. There are 
     * some exceptions: if the pool is disposed, the connection is disposed as 
     * well. If the pool is full, the connection is closed. 
     * 
     * @param pc the pooled connection 
     */ 
    synchronized void recycleConnection(PooledConnection pc) {
        if (activeConnections <= 0) {
5
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getConnection
		if (!recycledConnections.isEmpty()) {
			pc = recycledConnections.remove(recycledConnections.size() - 1);
		} else { 
			pc = dataSource.getPooledConnection();
		} 
		final Connection conn = pc.getConnection();
		activeConnections.incrementAndGet();
		pc.addConnectionEventListener(this);
		return conn;
	} 
 
	/** 
	 * This method usually puts the connection back into the pool. There are 
	 * some exceptions: if the pool is disposed, the connection is disposed as 
	 * well. If the pool is full, the connection is closed. 
	 *  
	 * @param pc 
	 *            the pooled connection 
	 */ 
	synchronized void recycleConnection(final PooledConnection pc) {
5
CodeRank
This code example shows how to use the following methods:addConnectionEventListener
        public void close() throws SQLException {
            delegate.close();
        } 
 
        public void addConnectionEventListener(ConnectionEventListener listener) {
            delegate.addConnectionEventListener(listener);
        } 
 
        public void removeConnectionEventListener(ConnectionEventListener listener) {
            delegate.removeConnectionEventListener(listener);
        } 
 
        public void addStatementEventListener(StatementEventListener listener) {
            delegate.addStatementEventListener(listener);
        } 
 
        public void removeStatementEventListener(StatementEventListener listener) {
            delegate.removeStatementEventListener(listener);
        } 
 
4
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getConnection
        //Get the correct ConnectionPoolDataSource object 
        ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
 
        PooledConnection pc = ds.getPooledConnection();
        //Add a connection event listener to ConnectionPoolDataSource 
        pc.addConnectionEventListener(aes12);
        Connection conn = pc.getConnection();
         
        dropTable(conn, "TAB1");
 
        //No event should have been generated at this point 
        assertFalse(aes12.didConnectionClosedEventHappen());
        assertFalse(aes12.didConnectionErrorEventHappen());
        aes12.resetState();
        //Shutdown the Derby engine or Network Server depending on what  
        //mode we are running in. 
        if (usingEmbedded()) 
        { 
        	getTestConfiguration().shutdownDatabase(); 
        } else 
5
CodeRank
This code example shows how to use the following methods:addConnectionEventListener, getConnection
if (!recycledConnections.isEmpty()) {
   pconn = recycledConnections.remove(); }
 else { 
   pconn = dataSource.getPooledConnection();
   pconn.addConnectionEventListener(poolConnectionEventListener); }
Connection conn = pconn.getConnection();
activeConnections++;
assertInnerState(); 
return conn; }
 
/** 
* Retrieves a connection from the connection pool and ensures that it is valid 
* by calling {@link Connection#isValid(int)}. 
* 
* <p>If a connection is not valid, the method tries to get another connection 
* until one is valid (or a timeout occurs). 
* 
* <p>Pooled connections may become invalid when e.g. the database server is 
* restarted. 
* 
4
CodeRank
addConnectionEventListener Method Overview
Registers the given event listener so that it will be notified when an event occurs on this PooledConnection object.
See Code Examples for other Java 8 PooledConnection Methods: