public static Connection getConnection() throws SQLException {
        synchronized (lock) {
            if (connectionProvider == null) {
                String className = AppGlobals.getProperty("connectionProvider.className");
                if (className == null || className.isEmpty()) {
                    setConnectionProvider(new DefaultConnectionProvider());
                } else {
                    try {
                        Class provider = Class.forName(className);
                        setConnectionProvider((ConnectionProvider) provider.newInstance());
                    } catch (Exception ex) {
                        logger.warn("Failed to create the "
                                + "connection provider specified by connection"
                                + "Provider.className. Using the default pool.", ex);
                        setConnectionProvider(new DefaultConnectionProvider());
                    }
                }
            }
        }
        // TODO: May want to make these settings configurable
        Integer retryCnt = 0;
        Integer retryMax = 10;
        Integer retryWait = 250; // milliseconds
        Connection con = null;
        SQLException lastException = null;
        do {
            try {
                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);
//                    }
                    return con;
                }
            } catch (SQLException e) {
                // TODO distinguish recoverable from non-recoverable exceptions.
                lastException = e;
                logger.warn("Unable to get a connection from the database pool "
                        + "(attempt " + retryCnt + " out of " + retryMax + ").", e);
            }
            try {
                Thread.sleep(retryWait);
            } catch (Exception e) {
                // Ignored
            }
            retryCnt++;
        } while (retryCnt <= retryMax);
        throw new SQLException("ConnectionManager.getConnection() "
                + "failed to obtain a connection after " + retryCnt + " retries. "
                + "The exception from the last attempt is as follows: " + lastException);
    }