Java 8 PooledConnection - 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 PooledConnection class.

This code example shows how to use the following methods:close, removeConnectionEventListener
     */ 
    public synchronized void connectionErrorOccurred(ConnectionEvent event) {
 
        PooledConnection connection = (PooledConnection) event.getSource();
 
        connection.removeConnectionEventListener(this);
        this.connectionsInUse.remove(connection);
        this.sessionConnectionWrappers.remove(connection);
        logInfo( 
            "Fatal exception occurred on pooled connection. Connection is removed from pool: "); 
        logInfo(event.getSQLException());
        closePhysically(connection, "closing invalid, removed connection.");
 
        //notify threads waiting for connections or for the pool to close. 
        //one waiting thread can now create a new connection since the pool has space for a new connection. 
        //if a thread waits for the pool to close this could be the last unclosed connection in the pool. 
        this.notifyAll();
    } 
 
    /** 

6
CodeRank
This code example shows how to use the following methods:close, removeConnectionEventListener
        } 
    } 
 
    private void closeConnection(PooledConnection pc) {
        try { 
            pc.close();
        } catch (SQLException e) {
            if (logWriter != null) {
                e.printStackTrace(logWriter);
            } 
        } 
    } 
 
    /** 
     * INTERNAL 
     */ 
    public void connectionClosed(ConnectionEvent event) {
        PooledConnection pc = (PooledConnection) event.getSource();
        pc.removeConnectionEventListener(this);
        recycleConnection(pc);

5
CodeRank
This code example shows how to use the following methods:close, removeConnectionEventListener
    } 
  } 
 
  private void closeConnection(PooledConnection pc) {
    try { 
      pc.close();
    } catch (SQLException e) {
      if (logWriter != null) {
        e.printStackTrace(logWriter);
      } 
    } 
  } 
 
  /** 
   * INTERNAL 
   */ 
  public void connectionClosed(ConnectionEvent event) {
    PooledConnection pc = (PooledConnection) event.getSource();
    pc.removeConnectionEventListener(this);
    recycleConnection(pc);

5
CodeRank
This code example shows how to use the following methods:close, removeConnectionEventListener
		if (activeConnections.get() <= 0) {
			throw new AssertionError();
		} 
		activeConnections.decrementAndGet();
		if (!isDisposed && activeConnections.get() < maxConnections) {
			recycledConnections.add(pc);
		} else { 
			closeConnection(pc);
		} 
		if (activeConnections.get() >= maxConnections - 1) {
			notifyAll();
		} 
	} 
 
	private void closeConnection(final PooledConnection pc) {
		try { 
			pc.close();
		} catch (final SQLException e) {
			if (logWriter != null) {
				e.printStackTrace(logWriter);

5
CodeRank
This code example shows how to use the following methods:removeConnectionEventListener
    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);
                try { 
                    _pool.invalidateObject(pci.getUserPassKey(), pci);
                } catch (Exception e3) {
                    System.err.println("EXCEPTION WHILE DESTROYING OBJECT " +
                            pci);
5
CodeRank
This code example shows how to use the following methods:removeConnectionEventListener
    @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);
                try { 
                    doDestroyObject(pci);
                } catch (Exception e2) {

5
CodeRank
This code example shows how to use the following methods:getConnection, getXAResource
	 * @throws GenericJTAException 
	 */ 
	private void insertIntoTransaction(XADataSource xads, TransactionManager tm, String value, boolean toCommit) throws SQLException, GenericJTAException{
		 
		XAConnection xaConnection = xads.getXAConnection();
		Connection connection = xaConnection.getConnection();
		XAResource xaResource  = xaConnection.getXAResource();
		try{ 
			tm.begin();
			Transaction transaction = tm.getTransaction();
			transaction.enlistResource(xaResource);
	 
			PreparedStatement insertStatement = connection.prepareStatement(INSERT_INTO_TABLE);
			insertStatement.setString(1, value);
			insertStatement.executeUpdate();
			if(toCommit){
				transaction.commit();
			} else { 
				transaction.rollback();
			} 
5
CodeRank
This code example shows how to use the following methods:close, removeConnectionEventListener
        } 
    } 
 
    private void closeConnection(PooledConnection pc) {
        try { 
            pc.close();
        } catch (SQLException e) {
            if (logWriter != null) {
                e.printStackTrace(logWriter);
            } 
        } 
    } 
 
    /** 
     * INTERNAL 
     */ 
    @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:removeConnectionEventListener
            } 
 
            PooledConnection pooledConnection = null;
            try { 
                pooledConnection = (PooledConnection) event.getSource();
                pooledConnection.removeConnectionEventListener(this);
 
                stats.connectionReturned(nanosSince(checkoutTime));
            } 
            finally { 
                semaphore.release();
 
                if (pooledConnection != null) {
                    connectionReturned(pooledConnection, checkoutTime);
                } 
            } 
        } 
 
        @Override 
        public void connectionErrorOccurred(ConnectionEvent event)
5
CodeRank
This code example shows how to use the following methods:getConnection
			if (username != null) {
				xaConnection = xaDataSource.getXAConnection(username, password);
			} else { 
				xaConnection = xaDataSource.getXAConnection();
			} 
			return xaConnection.getConnection();
		} catch (SQLException sex) {
			throw new DbSqlException("Unable to get connection from XA datasource", sex);
		} 
	} 
 
	public void closeConnection(Connection connection) {
		try { 
			connection.close();
		} catch (SQLException sex) {
			// ignore 
		} 
	} 
 
	public void close() {} 
5
CodeRank
See Code Examples for Java 8 PooledConnection Methods: