/** INTERNAL: */
 @Override
 public List<DatabaseField> getSelectionFields(ReadQuery query) {
   if (getDescriptor() == null) {
     DatabaseMapping mapping = getMapping();
     if (mapping != null) {
       return mapping.getSelectFields();
     }
     return new ArrayList<DatabaseField>(0);
   }
   if (descriptor.hasInheritance()
           && descriptor.getInheritancePolicy().shouldReadSubclasses()
           && (!descriptor.getInheritancePolicy().hasMultipleTableChild())
       || shouldUseOuterJoinForMultitableInheritance()) {
     // return all fields because we can.
     if (query != null && query.isObjectLevelReadQuery()) {
       return descriptor.getAllSelectionFields((ObjectLevelReadQuery) query);
     } else {
       return descriptor.getAllSelectionFields();
     }
   } else {
     if (query != null && query.isObjectLevelReadQuery()) {
       return descriptor.getSelectionFields((ObjectLevelReadQuery) query);
     } else {
       return descriptor.getSelectionFields();
     }
   }
 }
Ejemplo n.º 2
0
  @Override
  public void printSQLSelectStatement(
      DatabaseCall call, ExpressionSQLPrinter printer, SQLSelectStatement statement) {
    int max = 0;
    int firstRow = 0;
    ReadQuery query = statement.getQuery();
    if (query != null) {
      max = query.getMaxRows();
      firstRow = query.getFirstResult();
    }

    if (max <= 0 && firstRow <= 0) {
      // neither max nor firstRow is set
      super.printSQLSelectStatement(call, printer, statement);
      return;
    }
    if (max <= 0) {
      // if max row is not set use MAX_VALUE instead
      // this is done, because NewDB does not allow
      // OFFSET without LIMIT, and scrollable cursor is not supported
      // in order to support firstRows without MaxRows also MaxRow has to be set
      // this limits also the size of the result set in this case to Integer.MAX_VALUE rows
      query.setMaxRows(Integer.MAX_VALUE);
    }
    statement.setUseUniqueFieldAliases(true);
    call.setFields(statement.printSQL(printer));
    printer.printString(" LIMIT ");
    printer.printParameter(DatabaseCall.MAXROW_FIELD);
    printer.printString(" OFFSET ");
    printer.printParameter(DatabaseCall.FIRSTRESULT_FIELD);
    call.setIgnoreFirstRowSetting(true);
    call.setIgnoreMaxResultsSetting(true);
  }
Ejemplo n.º 3
0
  /** 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;
  }
Ejemplo n.º 4
0
  /** 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: Return the value of the reference attribute or a value holder. Check whether the
   * mapping's attribute should be optimized through batch and joining.
   */
  public Object valueFromRow(
      AbstractRecord row,
      JoinedAttributeManager joinManager,
      ObjectBuildingQuery sourceQuery,
      AbstractSession executionSession)
      throws DatabaseException {
    if (((EISDescriptor) this.getDescriptor()).getDataFormat() == EISDescriptor.XML) {
      ((XMLRecord) row).setSession(executionSession);
    }

    ReadQuery targetQuery = getSelectionQuery();
    if (!isForeignKeyRelationship) {
      // if the source query is cascading then the target query must use the same settings
      if (targetQuery.isObjectLevelReadQuery()
          && (sourceQuery.shouldCascadeAllParts()
              || (sourceQuery.shouldCascadePrivateParts() && isPrivateOwned())
              || (sourceQuery.shouldCascadeByMapping() && this.cascadeRefresh))) {
        targetQuery = (ObjectLevelReadQuery) targetQuery.clone();
        ((ObjectLevelReadQuery) targetQuery)
            .setShouldRefreshIdentityMapResult(sourceQuery.shouldRefreshIdentityMapResult());
        targetQuery.setCascadePolicy(sourceQuery.getCascadePolicy());
        // CR #4365
        targetQuery.setQueryId(sourceQuery.getQueryId());
        // For queries that have turned caching off, such as aggregate collection, leave it off.
        if (targetQuery.shouldMaintainCache()) {
          targetQuery.setShouldMaintainCache(sourceQuery.shouldMaintainCache());
        }
      }

      return getIndirectionPolicy().valueFromQuery(targetQuery, row, sourceQuery.getSession());
    } else {
      if (getIndirectionPolicy().usesIndirection()) {
        EISOneToManyQueryBasedValueHolder valueholder =
            new EISOneToManyQueryBasedValueHolder(this, targetQuery, row, sourceQuery.getSession());
        return valueholder;
      } else {
        Vector subRows = getForeignKeyRows(row);

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

        ContainerPolicy cp = this.getContainerPolicy();
        Object results = cp.containerInstance(subRows.size());

        for (int i = 0; i < subRows.size(); i++) {
          XMLRecord subRow = (XMLRecord) subRows.elementAt(i);
          subRow.setSession(executionSession);
          Object object =
              getIndirectionPolicy().valueFromQuery(targetQuery, subRow, sourceQuery.getSession());
          if (object instanceof Collection) {
            java.util.Iterator iter = ((Collection) object).iterator();
            while (iter.hasNext()) {
              cp.addInto(iter.next(), results, executionSession);
            }
          } else if (object instanceof java.util.Map) {
            java.util.Iterator iter = ((java.util.Map) object).values().iterator();
            while (iter.hasNext()) {
              cp.addInto(iter.next(), results, executionSession);
            }
          } else {
            cp.addInto(object, results, executionSession);
          }
        }
        if (cp.sizeFor(results) == 0) {
          return null;
        }
        return results;
      }
    }
  }
 /**
  * INTERNAL Build the context to be used when generating the expression from the subquery parse
  * tree.
  */
 private GenerationContext buildSubqueryContext(ReadQuery readQuery, GenerationContext outer) {
   GenerationContext context = new SelectGenerationContext(outer, this);
   context.setBaseQueryClass(readQuery.getReferenceClass());
   return context;
 }
  /** INTERNAL Build the context to be used when generating the expression from the parse tree */
  public GenerationContext buildContext(ReadQuery readQuery, AbstractSession session) {
    GenerationContext contextForGeneration = super.buildContext(readQuery, session);

    contextForGeneration.setBaseQueryClass(readQuery.getReferenceClass());
    return contextForGeneration;
  }