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

This code example shows how to use the following methods:getPooledConnection
	// ---------------------------------------------------------------- get/free 
 
	public Connection getConnection() {
		PooledConnection pconn;
		try { 
			pconn = cpds.getPooledConnection();
		} catch (SQLException sex) {
			throw new DbSqlException("Invalid pooled connection", sex);
		} 
		try { 
			return pconn.getConnection();
		} catch (SQLException sex) {
			throw new DbSqlException("Invalid pooled connection", sex);
		} 
	} 
 
	public void closeConnection(Connection connection) {
		try { 
			if (connection != null) {
				connection.close();
5
CodeRank
This code example shows how to use the following methods:getPooledConnection
    /** 
     * Return a TesterPooledConnection with notifyOnClose turned on 
     */ 
    @Override 
    public PooledConnection getPooledConnection() throws SQLException {
        return wrapPooledConnection(delegate.getPooledConnection());
    } 
 
    /** 
     * Return a TesterPooledConnection with notifyOnClose turned on 
     */ 
    @Override 
    public PooledConnection getPooledConnection(String user, String password)
            throws SQLException {
        return wrapPooledConnection(delegate.getPooledConnection(user, password));
    } 
 
    @Override 
    public void setLoginTimeout(int seconds) throws SQLException {
        delegate.setLoginTimeout(seconds);     
4
CodeRank
This code example shows how to use the following methods:getPooledConnection
        try { 
            if (username != null) {
                conn = cpds.getPooledConnection(username, password);
            } 
            else { 
                conn = cpds.getPooledConnection();
            } 
            if (conn == null) {
                throw new SQLException(
                    "Cannot connect using the supplied username/password"); 
            } 
        } 
        finally { 
            if (conn != null) {
                try { 
                    conn.close();
                } 
                catch (SQLException e) {
                    // at least we could connect 
                } 
4
CodeRank
This code example shows how to use the following methods:getPooledConnection
        } 
    } 
     
    @Override 
    public PooledConnection getPooledConnection() throws SQLException {
        return new DelegatingPooledConnection(delegate.getPooledConnection());
    } 
 
    @Override 
    public PooledConnection getPooledConnection(String user, String password) throws SQLException {
        return new DelegatingPooledConnection(delegate.getPooledConnection(user, password));
    } 
 
    @Override 
    public PrintWriter getLogWriter() throws SQLException {
        return delegate.getLogWriter();
    } 
 
    @Override 
    public void setLogWriter(PrintWriter out) throws SQLException {
4
CodeRank
This code example shows how to use the following methods:setLogWriter
  } 
 
  public void setLogWriter(PrintWriter out)
    throws SQLException 
  { 
    _dataSource.setLogWriter(out);
  } 
 
  public void setLoginTimeout(int seconds)
    throws SQLException 
  { 
    _dataSource.setLoginTimeout(seconds);
  } 
 
  public int getLoginTimeout() 
    throws SQLException 
  { 
    return _dataSource.getLoginTimeout();
  } 
   
4
CodeRank
This code example shows how to use the following methods:getPooledConnection
    public synchronized Object makeObject() { 
        Object obj; 
        try { 
            PooledConnection pc = null;
            if (_username == null) {
                pc = _cpds.getPooledConnection();
            } else { 
                pc = _cpds.getPooledConnection(_username, _password);
            } 
            // should we add this object as a listener or the pool. 
            // consider the validateObject method in decision 
            pc.addConnectionEventListener(this);
            obj = new PooledConnectionAndInfo(pc, _username, _password);
            pcMap.put(pc, obj);
        } catch (SQLException e) {
            throw new RuntimeException(e.getMessage());
        } 
        return obj; 
    } 
 
4
CodeRank
This code example shows how to use the following methods:setLoginTimeout
        return wrapPooledConnection(delegate.getPooledConnection(user, password));
    } 
 
    @Override 
    public void setLoginTimeout(int seconds) throws SQLException {
        delegate.setLoginTimeout(seconds);     
    } 
 
    @Override 
    public void setLogWriter(PrintWriter out) throws SQLException {
        delegate.setLogWriter(out);     
    } 
     
    @Override 
    public Logger getParentLogger() throws SQLFeatureNotSupportedException {
        return delegate.getParentLogger();
    } 
 
    /** 
     * Create a TesterPooledConnection with notifyOnClose turned on 
4
CodeRank
This code example shows how to use the following methods:getPooledConnection
PooledConnection pc;
    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 
5
CodeRank
This code example shows how to use the following methods:getPooledConnection
	@Override 
	public Connection connect(Decoder decoder) throws SQLExceptionConnectionPoolDataSource dataSource = this.getConnectionSource();
		Credentials credentials = this.getCredentials();
		PooledConnection connection = (credentials != null) ? dataSource.getPooledConnection(credentials.getUser(), credentials.decodePassword(decoder)) : dataSource.getPooledConnection();
		return connection.getConnection();
	} 
} 
4
CodeRank
This code example shows how to use the following methods:getLogWriter
 
    protected JdbcConnectionPool(ConnectionPoolDataSource dataSource) {
        this.dataSource = dataSource;
        if (dataSource != null) {
            try { 
                logWriter = dataSource.getLogWriter();
            } catch (SQLException e) {
                // ignore 
            } 
        } 
    } 
 
    /** 
     * Constructs a new connection pool. 
     * 
     * @param dataSource the data source to create connections 
     * @return the connection pool 
     */ 
    public static JdbcConnectionPool create(ConnectionPoolDataSource dataSource) {
        return new JdbcConnectionPool(dataSource);
4
CodeRank
See Code Examples for Java 8 ConnectionPoolDataSource Methods: