/** Initializes DatabaseFactory. */
  public static synchronized void init() {
    if (dataSource != null) {
      return;
    }

    DatabaseConfig.load();

    try {
      DatabaseConfig.DATABASE_DRIVER.newInstance();
    } catch (Exception e) {
      log.fatal("Error obtaining DB driver", e);
      throw new Error("DB Driver doesnt exist!");
    }

    connectionPool = new GenericObjectPool();

    if (DatabaseConfig.DATABASE_CONNECTIONS_MIN > DatabaseConfig.DATABASE_CONNECTIONS_MAX) {
      log.error(
          "Please check your database configuration. Minimum amount of connections is > maximum");
      DatabaseConfig.DATABASE_CONNECTIONS_MAX = DatabaseConfig.DATABASE_CONNECTIONS_MIN;
    }

    connectionPool.setMaxIdle(DatabaseConfig.DATABASE_CONNECTIONS_MIN);
    connectionPool.setMaxActive(DatabaseConfig.DATABASE_CONNECTIONS_MAX);

    /* test if connection is still valid before returning */
    connectionPool.setTestOnBorrow(true);

    try {
      dataSource = setupDataSource();
      Connection c = getConnection();
      DatabaseMetaData dmd = c.getMetaData();
      databaseName = dmd.getDatabaseProductName();
      databaseMajorVersion = dmd.getDatabaseMajorVersion();
      databaseMinorVersion = dmd.getDatabaseMinorVersion();
      c.close();
    } catch (Exception e) {
      log.fatal("Error with connection string: " + DatabaseConfig.DATABASE_URL, e);
      throw new Error("DatabaseFactory not initialized!");
    }

    log.info("Successfully connected to database");
  }