/** Retrieve previous object from the remote scrollable cursor */
  public Object scrollableCursorPreviousObject(
      ObjID remoteScrollableCursorOid, ReadQuery query, DistributedSession session) {
    Transporter transporter = null;
    try {
      transporter =
          getRemoteSessionController()
              .scrollableCursorPreviousObject(new Transporter(remoteScrollableCursorOid));
    } catch (RemoteException exception) {
      throw CommunicationException.errorInInvocation(exception);
    }

    if (transporter == null) {
      return null;
    }

    if (!transporter.wasOperationSuccessful()) {
      throw transporter.getException();
    }

    Object object = transporter.getObject();
    if (object == null) {
      // For bug 2797683 do not close if at end of stream.
      return null;
    }

    if (query.isReadAllQuery() && (!query.isReportQuery())) { // could be DataReadQuery
      object =
          session.getObjectCorrespondingTo(
              object,
              transporter.getObjectDescriptors(),
              new IdentityHashMap(),
              (ObjectLevelReadQuery) query);
    }
    return object;
  }
 /** INTERNAL: Extract the correct query result from the transporter. */
 public Object extractRemoteResult(Transporter transporter) {
   return ((RemoteSession) getSession())
       .getObjectsCorrespondingToAll(
           transporter.getObject(),
           transporter.getObjectDescriptors(),
           new IdentityHashMap(),
           this,
           getContainerPolicy());
 }
 /** Return the scrollable cursor size */
 public int scrollableCursorSize(ObjID cursorId) {
   Transporter transporter = null;
   try {
     transporter = getRemoteSessionController().scrollableCursorSize(new Transporter(cursorId));
   } catch (RemoteException exception) {
     throw CommunicationException.errorInInvocation(exception);
   }
   if (!transporter.wasOperationSuccessful()) {
     throw transporter.getException();
   }
   return ((Integer) transporter.getObject()).intValue();
 }
 /** INTERNAL: Return the table descriptor specified for the class. */
 public Login getLogin() {
   try {
     Transporter transporter = getRemoteSessionController().getLogin();
     if (!transporter.wasOperationSuccessful()) {
       throw transporter.getException();
     } else {
       return (Login) transporter.getObject();
     }
   } catch (RemoteException exception) {
     throw CommunicationException.errorInInvocation(exception);
   }
 }
 /** INTERNAL Return the read-only classes */
 public Vector getDefaultReadOnlyClasses() {
   try {
     Transporter transporter = getRemoteSessionController().getDefaultReadOnlyClasses();
     if (!transporter.wasOperationSuccessful()) {
       throw transporter.getException();
     } else {
       return (Vector) transporter.getObject();
     }
   } catch (RemoteException exception) {
     throw CommunicationException.errorInInvocation(exception);
   }
 }
 /** INTERNAL: Return the table descriptor specified for the alias. */
 public ClassDescriptor getDescriptorForAlias(String alias) {
   try {
     Transporter transporter =
         getRemoteSessionController().getDescriptorForAlias(new Transporter(alias));
     if (!transporter.wasOperationSuccessful()) {
       throw transporter.getException();
     } else {
       return (ClassDescriptor) transporter.getObject();
     }
   } catch (RemoteException exception) {
     throw CommunicationException.errorInInvocation(exception);
   }
 }
  /** INTERNAL: Perform remote function call */
  public Object getSequenceNumberNamed(Object remoteFunctionCall) {
    try {
      Transporter transporter =
          getRemoteSessionController().getSequenceNumberNamed(new Transporter(remoteFunctionCall));
      Object returnValue = transporter.getObject();

      if (!transporter.wasOperationSuccessful()) {
        throw transporter.getException();
      }

      return returnValue;
    } catch (RemoteException exception) {
      throw CommunicationException.errorInInvocation(exception);
    }
  }
 /** INTERNAL: Commit root unit of work from the client side to the server side. */
 public RemoteUnitOfWork commitRootUnitOfWork(RemoteUnitOfWork theRemoteUnitOfWork) {
   try {
     Transporter transporter = new Transporter();
     transporter.setObject(theRemoteUnitOfWork);
     transporter.prepare(this.session);
     transporter = getRemoteSessionController().commitRootUnitOfWork(transporter);
     transporter.expand(this.session);
     if (!transporter.wasOperationSuccessful()) {
       throw transporter.getException();
     } else {
       return (RemoteUnitOfWork) transporter.getObject();
     }
   } catch (RemoteException exception) {
     throw CommunicationException.errorInInvocation(exception);
   }
 }
  /** Indicates whether the cursor is after the last row in the result set. */
  public boolean scrollableCursorIsAfterLast(ObjID remoteScrollableCursorOid) {
    Transporter transporter = null;
    try {
      transporter =
          getRemoteSessionController()
              .scrollableCursorIsAfterLast(new Transporter(remoteScrollableCursorOid));
    } catch (RemoteException exception) {
      throw CommunicationException.errorInInvocation(exception);
    }
    if (transporter == null) {
      return false;
    }

    if (!transporter.wasOperationSuccessful()) {
      throw transporter.getException();
    }
    return ((Boolean) transporter.getObject()).booleanValue();
  }
  /** Retrieves the current row index number */
  public int scrollableCursorCurrentIndex(ObjID remoteScrollableCursorOid) {
    Transporter transporter = null;
    try {
      transporter =
          getRemoteSessionController()
              .scrollableCursorAfterLast(new Transporter(remoteScrollableCursorOid));
    } catch (RemoteException exception) {
      throw CommunicationException.errorInInvocation(exception);
    }
    if (transporter == null) {
      return -1;
    }

    if (!transporter.wasOperationSuccessful()) {
      throw transporter.getException();
    }
    return ((Integer) transporter.getObject()).intValue();
  }
  /** Retrieve next page size of objects from the remote cursored stream */
  public Vector cursoredStreamNextPage(
      RemoteCursoredStream remoteCursoredStream,
      ReadQuery query,
      DistributedSession session,
      int pageSize) {
    Transporter transporter = null;
    try {
      transporter =
          getRemoteSessionController()
              .cursoredStreamNextPage(new Transporter(remoteCursoredStream.getID()), pageSize);
    } catch (RemoteException exception) {
      throw CommunicationException.errorInInvocation(exception);
    }

    if (transporter == null) {
      return null;
    }

    if (!transporter.wasOperationSuccessful()) {
      throw transporter.getException();
    }

    Vector serverNextPageObjects = (Vector) transporter.getObject();
    if (serverNextPageObjects == null) {
      cursoredStreamClose(remoteCursoredStream.getID());
      return null;
    }
    Vector clientNextPageObjects = serverNextPageObjects;
    if (query.isReadAllQuery() && (!query.isReportQuery())) { // could be DataReadQuery
      clientNextPageObjects = new Vector(serverNextPageObjects.size());
      for (Enumeration objEnum = serverNextPageObjects.elements(); objEnum.hasMoreElements(); ) {
        // 2612538 - the default size of Map (32) is appropriate
        Object clientObject =
            session.getObjectCorrespondingTo(
                objEnum.nextElement(),
                transporter.getObjectDescriptors(),
                new IdentityHashMap(),
                (ObjectLevelReadQuery) query);
        clientNextPageObjects.addElement(clientObject);
      }
    }

    return clientNextPageObjects;
  }
  /** INTERNAL: Returns remote cursor stream */
  public RemoteScrollableCursor cursorSelectObjects(
      ScrollableCursorPolicy policy, DistributedSession session) {
    try {
      Transporter transporter =
          getRemoteSessionController().cursorSelectObjects(new Transporter(policy));
      if (!transporter.wasOperationSuccessful()) {
        throw transporter.getException();
      }

      RemoteScrollableCursor remoteScrollableCursor =
          (RemoteScrollableCursor) transporter.getObject();
      remoteScrollableCursor.setSession(session);
      remoteScrollableCursor.setPolicy(policy);

      return remoteScrollableCursor;
    } catch (RemoteException exception) {
      throw CommunicationException.errorInInvocation(exception);
    }
  }
  /** INTERNAL: Returns remote cursor stream */
  public RemoteCursoredStream cursorSelectObjects(
      CursoredStreamPolicy policy, DistributedSession session) {
    try {
      Transporter transporter =
          getRemoteSessionController().cursorSelectObjects(new Transporter(policy));
      if (!transporter.wasOperationSuccessful()) {
        throw transporter.getException();
      }

      RemoteCursoredStream remoteCursoredStream = (RemoteCursoredStream) transporter.getObject();
      remoteCursoredStream.setSession(session);
      remoteCursoredStream.setPolicy(policy);

      if (policy.getQuery().isReadAllQuery()
          && (!policy.getQuery().isReportQuery())) { // could be DataReadQuery
        fixObjectReferences(transporter, (ObjectLevelReadQuery) policy.getQuery(), session);
      }
      return remoteCursoredStream;
    } catch (RemoteException exception) {
      throw CommunicationException.errorInInvocation(exception);
    }
  }