@Test public void reserveConnection_oneConnectionLeft_returnsConnection() throws SQLException { try { connectionPool.reserveConnection(); } catch (SQLException e) { e.printStackTrace(); Assert.fail("Exception before all connections used! " + e.getMessage()); } Connection conn = connectionPool.reserveConnection(); Assert.assertNotNull(conn); }
@Override public synchronized Connection reserveConnection() throws SQLException { if (!initialized) { initializeConnections(); } if (availableConnections.isEmpty()) { if (reservedConnections.size() < maxConnections) { availableConnections.add(createConnection()); } else { throw new SQLException("Connection limit has been reached."); } } Connection c = availableConnections.iterator().next(); availableConnections.remove(c); reservedConnections.add(c); return c; }
SimpleJDBCConnectionPool implements JDBCConnectionPool { @Override public synchronized Connection reserveConnection() throws SQLException { if (!initialized) { initializeConnections(); } if (availableConnections.isEmpty()) { if (reservedConnections.size() < maxConnections) { availableConnections.add(createConnection()); } else { throw new SQLException("Connection limit has been reached."); } } Connection c = availableConnections.iterator().next(); availableConnections.remove(c); reservedConnections.add(c); return c; } }
SimpleJDBCConnectionPool implements JDBCConnectionPool { @Override public synchronized Connection reserveConnection() throws SQLException { if (!initialized) { initializeConnections(); } if (availableConnections.isEmpty()) { if (reservedConnections.size() < maxConnections) { availableConnections.add(createConnection()); } else { throw new SQLException("Connection limit has been reached."); } } Connection c = availableConnections.iterator().next(); availableConnections.remove(c); reservedConnections.add(c); return c; } SimpleJDBCConnectionPool(String driverName, String connectionUri,
            String userName, String password);  SimpleJDBCConnectionPool(String driverName, String connectionUri,
            String userName, String password, int initialConnections,
            int maxConnections); }
SimpleJDBCConnectionPool implements JDBCConnectionPool { @Override public synchronized Connection reserveConnection() throws SQLException { if (!initialized) { initializeConnections(); } if (availableConnections.isEmpty()) { if (reservedConnections.size() < maxConnections) { availableConnections.add(createConnection()); } else { throw new SQLException("Connection limit has been reached."); } } Connection c = availableConnections.iterator().next(); availableConnections.remove(c); reservedConnections.add(c); return c; } SimpleJDBCConnectionPool(String driverName, String connectionUri,
            String userName, String password);  SimpleJDBCConnectionPool(String driverName, String connectionUri,
            String userName, String password, int initialConnections,
            int maxConnections); @Override synchronized Connection reserveConnection(); @Override synchronized void releaseConnection(Connection conn); @Override void destroy(); }
SimpleJDBCConnectionPool implements JDBCConnectionPool { @Override public synchronized Connection reserveConnection() throws SQLException { if (!initialized) { initializeConnections(); } if (availableConnections.isEmpty()) { if (reservedConnections.size() < maxConnections) { availableConnections.add(createConnection()); } else { throw new SQLException("Connection limit has been reached."); } } Connection c = availableConnections.iterator().next(); availableConnections.remove(c); reservedConnections.add(c); return c; } SimpleJDBCConnectionPool(String driverName, String connectionUri,
            String userName, String password);  SimpleJDBCConnectionPool(String driverName, String connectionUri,
            String userName, String password, int initialConnections,
            int maxConnections); @Override synchronized Connection reserveConnection(); @Override synchronized void releaseConnection(Connection conn); @Override void destroy();  }