示例#1
0
  private static void processRecord(
      final ORecordSchemaAware<?> record,
      final Object iUserObject,
      final Map<String, Integer> iFetchPlan,
      final int iCurrentLevel,
      final int iLevelFromRoot,
      final int iFieldDepthLevel,
      final Map<ORID, Integer> parsedRecords,
      final String iFieldPathFromRoot,
      final OFetchListener iListener,
      final OFetchContext iContext,
      final String iFormat)
      throws IOException {

    Object fieldValue;

    iContext.onBeforeFetch(record);
    if (debug) {
      System.out.println("processRecord start");
      System.out.println("iFieldDepthLevel: " + iFieldDepthLevel);
      System.out.println("record: " + record.toString());
      System.out.println("iFetchPlan: " + iFetchPlan);
      System.out.println("iCurrentLevel: " + iCurrentLevel);
      System.out.println("iLevelFromRoot: " + iLevelFromRoot);
      System.out.println("iCurrentLevel: " + iCurrentLevel);
      System.out.println("parsedRecords: " + parsedRecords);
      System.out.println("iFieldPathFromRoot: " + iFieldPathFromRoot);
    }

    for (String fieldName : record.fieldNames()) {
      String fieldPath =
          !iFieldPathFromRoot.isEmpty() ? iFieldPathFromRoot + "." + fieldName : fieldName;
      if (debug) {
        System.out.println("     fieldName: " + fieldName);
        System.out.println("     fieldPath: " + fieldPath);
      }
      int depthLevel;
      depthLevel = getDepthLevel(iFetchPlan, fieldPath);
      if (depthLevel == -2) continue;
      if (iFieldDepthLevel > -1) depthLevel = iFieldDepthLevel;

      if (debug) System.out.println("     depthLevel: " + depthLevel);

      fieldValue = record.field(fieldName);

      boolean fetch =
          !iFormat.contains("shallow")
              && (!(fieldValue instanceof ODocument)
                  || depthLevel == -1
                  || iCurrentLevel <= depthLevel
                  || iFetchPlan.containsKey(fieldPath));

      final boolean isEmbedded =
          fieldValue instanceof ODocument
              && (((ODocument) fieldValue).isEmbedded()
                  || !((ODocument) fieldValue).getIdentity().isValid());

      if (!fetch && isEmbedded && iContext.fetchEmbeddedDocuments())
        // EMBEDDED, GO DEEPER
        fetch = true;

      if (iFormat.contains("shallow")
          || fieldValue == null
          || (!fetch && fieldValue instanceof OIdentifiable)
          || !(fieldValue instanceof OIdentifiable)
              && (!(fieldValue instanceof ORecordLazyMultiValue)
                  || !((ORecordLazyMultiValue) fieldValue).rawIterator().hasNext()
                  || !(((ORecordLazyMultiValue) fieldValue).rawIterator().next()
                      instanceof OIdentifiable))
              && (!(OMultiValue.getFirstValue(fieldValue) instanceof OIdentifiable
                  || OMultiValue.getFirstValue(OMultiValue.getFirstValue(fieldValue))
                      instanceof OIdentifiable
                  || OMultiValue.getFirstValue(
                          OMultiValue.getFirstValue(OMultiValue.getFirstValue(fieldValue)))
                      instanceof OIdentifiable))) {
        iContext.onBeforeStandardField(fieldValue, fieldName, iUserObject);
        iListener.processStandardField(
            record, fieldValue, fieldName, iContext, iUserObject, iFormat);
        iContext.onAfterStandardField(fieldValue, fieldName, iUserObject);
      } else {
        try {
          if (fetch) {
            final int nextLevel = isEmbedded ? iLevelFromRoot : iLevelFromRoot + 1;

            fetch(
                record,
                iUserObject,
                iFetchPlan,
                fieldValue,
                fieldName,
                iCurrentLevel,
                nextLevel,
                iFieldDepthLevel,
                parsedRecords,
                depthLevel,
                fieldPath,
                iListener,
                iContext);
          }

        } catch (Exception e) {
          e.printStackTrace();
          OLogManager.instance()
              .error(null, "Fetching error on record %s", e, record.getIdentity());
        }
      }
    }

    iContext.onAfterFetch(record);
  }