ception occurs or no connection was found.
     */
    public static Connection getConnection() throws SQLException {
        ensureConnectionProvider();

        Integer currentRetryCount = 0;
        Integer maxRetries = JiveGlobals.getXMLProperty(SETTING_DATABASE_MAX_RETRIES, 10);
        Integer retryWait = JiveGlobals.getXMLProperty(SETTING_DATABASE_RETRY_DELAY, 250); // milliseconds
        SQLException lastException = null;
        boolean loopIfNoConnection = false;
        do {
            try {
                Connection con = connectionProvider.getConnection();
                if (con != null) {
                    // Got one, lets hand it off.
                    // Usually profiling is not enabled. So we return a normal 
                    // connection unless profiling is enabled. If yes, wrap the
                    // connection with a profiled connection.
                    if (!profilingEnabled) {
                        return con;
                    } else {
                        return new ProfiledConnection(con); 
                    }
                }
            } catch (SQLException e) {
                // TODO distinguish recoverable from non-recoverable exceptions.
                lastException = e;
                Log.info("Unable to get a connection from the database pool " +
                        "(attempt " + currentRetryCount + " out of " + maxRetries + ").", e);
            }
            
            currentRetryCount++;
            loopIfNoConnection = currentRetryCount <= maxRetries;
            if (loopIfNoConnection) {
                try {
                    Thread.sleep(retryWait);
                } catch (InterruptedException ex) {
                    String msg = "Interrupted waiting for DB connection";
                    Log.info(msg,ex);
                    Thread.currentThread().interrupt();
                    throw new SQLException(msg,ex);
                }
            }
        } while (loopIfNoConnection);
        
        throw new SQLException("Connecti