/**
   * PUBLIC: Connect to the database using the predefined login. This connects all of the child
   * sessions and expects that they are in a valid state to be connected.
   */
  public void login(String userName, String password) throws DatabaseException {
    // Bug#3440544 Check if logged in already to stop the attempt to login more than once
    if (isLoggedIn) {
      throw ValidationException.alreadyLoggedIn(this.getName());
    } else {
      if (this.eventManager != null) {
        this.eventManager.preLogin(this);
      }
      // Bug 3848021 - ensure the external transaction controller is initialized
      if (!isConnected()) {
        getServerPlatform().initializeExternalTransactionController();
      }

      // Connection all sessions and initialize
      for (Iterator sessionEnum = getSessionsByName().values().iterator();
          sessionEnum.hasNext(); ) {
        DatabaseSessionImpl session = (DatabaseSessionImpl) sessionEnum.next();
        if (session.hasEventManager()) {
          session.getEventManager().preLogin(session);
        }
        session.getDatasourceLogin().setUserName(userName);
        session.getDatasourceLogin().setPassword(password);

        if (!session.isConnected()) {
          session.connect();
        }
      }
      initializeDescriptors();
      this.isLoggedIn = true;
    }
  }