Exemplo n.º 1
0
  /**
   * PUBLIC: Return a session broker that behaves as a client session broker. An acquire session
   * broker is done under the covers on each session inside the session broker, and a new broker is
   * returned.
   *
   * <p>NOTE: when finished with the client broker, it should be releases. See
   * releaseClientSessionBroker.
   */
  public SessionBroker acquireClientSessionBroker() {
    log(SessionLog.FINER, SessionLog.CONNECTION, "acquire_client_session_broker");
    SessionBroker clientBroker = copySessionBroker();
    clientBroker.parent = this;
    clientBroker
        .getIdentityMapAccessorInstance()
        .setIdentityMapManager(getIdentityMapAccessorInstance().getIdentityMapManager());
    clientBroker.commitManager = getCommitManager();
    clientBroker.commandManager = getCommandManager();
    clientBroker.externalTransactionController = getExternalTransactionController();
    clientBroker.setServerPlatform(getServerPlatform());
    String sessionName;
    AbstractSession serverSession;
    Iterator names = this.getSessionsByName().keySet().iterator();
    while (names.hasNext()) {
      sessionName = (String) names.next();
      serverSession = getSessionForName(sessionName);
      if (serverSession instanceof org.eclipse.persistence.sessions.server.ServerSession) {
        if (serverSession.getProject().hasIsolatedClasses()) {
          throw ValidationException.isolatedDataNotSupportedInSessionBroker(sessionName);
        }
        clientBroker.internalRegisterSession(
            sessionName,
            ((org.eclipse.persistence.sessions.server.ServerSession) serverSession)
                .acquireClientSession());
      } else {
        throw ValidationException.cannotAcquireClientSessionFromSession();
      }
    }

    clientBroker.initializeSequencing();
    return clientBroker;
  }
Exemplo n.º 2
0
  /**
   * 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;
    }
  }
Exemplo n.º 3
0
  /** INTERNAL: Return the session by name. */
  public AbstractSession getSessionForName(String name) throws ValidationException {
    AbstractSession sessionByName = getSessionsByName().get(name);
    if (sessionByName == null) {
      throw ValidationException.noSessionRegisteredForName(name);
    }

    return sessionByName;
  }
Exemplo n.º 4
0
 /** INTERNAL: Return the session to be used for the class. */
 public AbstractSession getSessionForClass(Class domainClass) throws ValidationException {
   if (domainClass == null) {
     // CR2114; we don't have a session name. Return us.
     return this;
   }
   String sessionName = getSessionNamesByClass().get(domainClass);
   if (sessionName == null) {
     throw ValidationException.noSessionRegisteredForClass(domainClass);
   }
   return getSessionsByName().get(sessionName);
 }
Exemplo n.º 5
0
  /** INTERNAL: Acquires a special historical session for reading objects as of a past time. */
  public org.eclipse.persistence.sessions.Session acquireHistoricalSession(AsOfClause clause)
      throws ValidationException {
    if (isServerSessionBroker()) {
      throw ValidationException.cannotAcquireHistoricalSession();
    }

    // ? logMessage("acquire_client_session_broker", (Object[])null);
    SessionBroker historicalBroker = copySessionBroker();
    String sessionName;
    AbstractSession session;
    Iterator names = this.getSessionsByName().keySet().iterator();
    while (names.hasNext()) {
      sessionName = (String) names.next();
      session = getSessionForName(sessionName);
      historicalBroker.registerSession(sessionName, session.acquireHistoricalSession(clause));
    }
    return historicalBroker;
  }
Exemplo n.º 6
0
 /** PUBLIC: You cannot add a project to a session broker, you must add it to its session. */
 public void addDescriptors(org.eclipse.persistence.sessions.Project project)
     throws ValidationException {
   throw ValidationException.cannotAddDescriptorsToSessionBroker();
 }
Exemplo n.º 7
0
 /** PUBLIC: You cannot add descriptors to a session broker, you must add them to its session. */
 public void addDescriptors(Vector descriptors) throws ValidationException {
   throw ValidationException.cannotAddDescriptorsToSessionBroker();
 }
Exemplo n.º 8
0
 /** PUBLIC: You cannot add a descriptor to a session broker, you must add it to its session. */
 public void addDescriptor(ClassDescriptor descriptor) {
   throw ValidationException.cannotAddDescriptorsToSessionBroker();
 }