/**
   * 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() 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);
        }
        if (!session.isConnected()) {
          session.connect();
        }
      }
      initializeDescriptors();
      if (getCommandManager() != null) {
        getCommandManager().initialize();
      }
      isLoggedIn = true;
    }
  }
 /**
  * PUBLIC: Disconnect from all databases.
  *
  * @exception EclipseLinkException if a transaction is active, you must rollback any active
  *     transaction before logout.
  * @exception DatabaseException the database will also raise an error if their is an active
  *     transaction, or a general error occurs.
  */
 public void logout() throws DatabaseException {
   for (Iterator sessionEnum = getSessionsByName().values().iterator(); sessionEnum.hasNext(); ) {
     DatabaseSessionImpl session = (DatabaseSessionImpl) sessionEnum.next();
     session.logout();
   }
   if (!isClientSessionBroker()) {
     if (hasExternalTransactionController()) {
       getExternalTransactionController().clearSequencingListeners();
     }
   }
   sequencing = null;
   isLoggedIn = false;
 }
  /**
   * PUBLIC: Set the profiler for the session. This allows for performance operations to be
   * profiled.
   */
  public void setProfiler(SessionProfiler profiler) {
    super.setProfiler(profiler);

    for (Iterator sessionEnum = getSessionsByName().values().iterator(); sessionEnum.hasNext(); ) {
      AbstractSession session = (AbstractSession) sessionEnum.next();
      session.setProfiler(profiler);
    }
  }
  /**
   * PUBLIC: Set the message log.
   *
   * @see #logMessages()
   */
  public void setLog(Writer log) {
    super.setLog(log);

    for (Iterator sessionEnum = getSessionsByName().values().iterator(); sessionEnum.hasNext(); ) {
      AbstractSession session = (AbstractSession) sessionEnum.next();
      session.setLog(log);
    }
  }
  /**
   * PUBLIC: set the integrityChecker. IntegrityChecker holds all the ClassDescriptor Exceptions.
   */
  public void setIntegrityChecker(IntegrityChecker integrityChecker) {
    super.setIntegrityChecker(integrityChecker);

    for (Iterator sessionEnum = getSessionsByName().values().iterator(); sessionEnum.hasNext(); ) {
      AbstractSession session = (AbstractSession) sessionEnum.next();
      session.setIntegrityChecker(integrityChecker);
    }
  }
 /**
  * INTERNAL: Set isSynchronized flag to indicate that members of session broker are synchronized.
  * This method should only be called by setSynchronized method of UnitOfWork obtained from either
  * DatabaseSession Broker or ClientSession Broker.
  */
 public void setSynchronized(boolean synched) {
   if (!isServerSessionBroker()) {
     super.setSynchronized(synched);
     Iterator itSessions = getSessionsByName().values().iterator();
     while (itSessions.hasNext()) {
       ((AbstractSession) itSessions.next()).setSynchronized(synched);
     }
   }
 }
 /**
  * PUBLIC: Release the session. This does nothing by default, but allows for other sessions such
  * as the ClientSession to do something.
  */
 public void release() {
   if (isClientSessionBroker()) {
     log(SessionLog.FINER, SessionLog.CONNECTION, "releasing_client_session_broker");
   }
   AbstractSession session;
   for (Iterator enumtr = getSessionsByName().values().iterator(); enumtr.hasNext(); ) {
     session = (AbstractSession) enumtr.next();
     session.release();
   }
   super.release();
 }
  /**
   * INTERNAL: Allow each descriptor to initialize any dependencies on this session. This is done in
   * two passes to allow the inheritance to be resolved first. Normally the descriptors are added
   * before login, then initialized on login.
   */
  public void initializeDescriptors() {
    // ClientSession initializes sequencing during construction,
    // however DatabaseSession and ServerSession normally call initializeSequencing()
    // in initializeDescriptors method.
    // Because initializeDescriptors() is not called for a session-member of a SessionBroker,
    // initializeSequencing() for the sessions should be called here.
    if (!isClientSessionBroker()) {
      for (Iterator enumtr = getSessionsByName().values().iterator(); enumtr.hasNext(); ) {
        DatabaseSessionImpl databaseSession = (DatabaseSessionImpl) enumtr.next();
        databaseSession.initializeSequencing();
      }
      if (hasExternalTransactionController()) {
        getExternalTransactionController().initializeSequencingListeners();
      }
    }
    super.initializeDescriptors();
    // Must reset project options to session broker project, as initialization occurs
    // with local projects.
    for (Iterator enumtr = getSessionsByName().values().iterator(); enumtr.hasNext(); ) {
      DatabaseSessionImpl databaseSession = (DatabaseSessionImpl) enumtr.next();
      if (databaseSession.getProject().hasGenericHistorySupport()) {
        getProject().setHasGenericHistorySupport(true);
      }
      if (databaseSession.getProject().hasIsolatedClasses()) {
        getProject().setHasIsolatedClasses(true);
      }
      if (databaseSession.getProject().hasNonIsolatedUOWClasses()) {
        getProject().setHasNonIsolatedUOWClasses(true);
      }
      getProject()
          .getDefaultReadOnlyClasses()
          .addAll(databaseSession.getProject().getDefaultReadOnlyClasses());
    }

    // ServerSessionBroker doesn't need sequencing.
    // Sequencing should be obtained either from the ClientSessionBroker or directly
    // from the ClientSession.
    if (isServerSessionBroker()) {
      sequencing = null;
    }
  }