예제 #1
0
 private static void fetchArray(
     final ORecordSchemaAware<?> iRootRecord,
     final Object iUserObject,
     final Map<String, Integer> iFetchPlan,
     Object fieldValue,
     String fieldName,
     final int iCurrentLevel,
     final int iLevelFromRoot,
     final int iFieldDepthLevel,
     final Map<ORID, Integer> parsedRecords,
     final String iFieldPathFromRoot,
     final OFetchListener iListener,
     final OFetchContext iContext)
     throws IOException {
   if (fieldValue instanceof ODocument[]) {
     final ODocument[] linked = (ODocument[]) fieldValue;
     iContext.onBeforeArray(iRootRecord, fieldName, iUserObject, linked);
     for (ODocument d : linked) {
       // GO RECURSIVELY
       final Integer fieldDepthLevel = parsedRecords.get(d.getIdentity());
       if (!d.getIdentity().isValid()
           || (fieldDepthLevel != null && fieldDepthLevel.intValue() == iLevelFromRoot)) {
         removeParsedFromMap(parsedRecords, d);
         iContext.onBeforeDocument(iRootRecord, d, fieldName, iUserObject);
         final Object userObject =
             iListener.fetchLinked(iRootRecord, iUserObject, fieldName, d, iContext);
         processRecord(
             d,
             userObject,
             iFetchPlan,
             iCurrentLevel,
             iLevelFromRoot,
             iFieldDepthLevel,
             parsedRecords,
             iFieldPathFromRoot,
             iListener,
             iContext,
             "");
         iContext.onAfterDocument(iRootRecord, d, fieldName, iUserObject);
       } else {
         iListener.parseLinkedCollectionValue(iRootRecord, d, iUserObject, fieldName, iContext);
       }
     }
     iContext.onAfterArray(iRootRecord, fieldName, iUserObject);
   } else {
     iListener.processStandardField(iRootRecord, fieldValue, fieldName, iContext, iUserObject, "");
   }
 }
예제 #2
0
 private static void fetchDocument(
     final ORecordSchemaAware<?> iRootRecord,
     final Object iUserObject,
     final Map<String, Integer> iFetchPlan,
     final OIdentifiable fieldValue,
     final String fieldName,
     final int iCurrentLevel,
     final int iLevelFromRoot,
     final int iFieldDepthLevel,
     final Map<ORID, Integer> parsedRecords,
     final String iFieldPathFromRoot,
     final OFetchListener iListener,
     final OFetchContext iContext)
     throws IOException {
   final Integer fieldDepthLevel = parsedRecords.get(fieldValue.getIdentity());
   if (!fieldValue.getIdentity().isValid()
       || (fieldDepthLevel != null && fieldDepthLevel.intValue() == iLevelFromRoot)) {
     removeParsedFromMap(parsedRecords, fieldValue);
     final ODocument linked = (ODocument) fieldValue;
     iContext.onBeforeDocument(iRootRecord, linked, fieldName, iUserObject);
     Object userObject =
         iListener.fetchLinked(iRootRecord, iUserObject, fieldName, linked, iContext);
     processRecord(
         linked,
         userObject,
         iFetchPlan,
         iCurrentLevel,
         iLevelFromRoot,
         iFieldDepthLevel,
         parsedRecords,
         iFieldPathFromRoot,
         iListener,
         iContext,
         "");
     iContext.onAfterDocument(iRootRecord, linked, fieldName, iUserObject);
   } else {
     iListener.parseLinked(iRootRecord, fieldValue, iUserObject, fieldName, iContext);
   }
 }
예제 #3
0
  @SuppressWarnings("unchecked")
  private static void fetchCollection(
      final ORecordSchemaAware<?> iRootRecord,
      final Object iUserObject,
      final Map<String, Integer> iFetchPlan,
      final Object fieldValue,
      final String fieldName,
      final int iCurrentLevel,
      final int iLevelFromRoot,
      final int iFieldDepthLevel,
      final Map<ORID, Integer> parsedRecords,
      final String iFieldPathFromRoot,
      final OFetchListener iListener,
      final OFetchContext iContext)
      throws IOException {
    final Collection<?> linked;
    if (fieldValue instanceof ODocument)
      linked = new OMVRBTreeRIDSet().fromDocument((ODocument) fieldValue);
    else if (fieldValue instanceof Collection<?>) {
      linked = (Collection<OIdentifiable>) fieldValue;
      iContext.onBeforeCollection(iRootRecord, fieldName, iUserObject, linked);
    } else if (fieldValue instanceof Map<?, ?>) {
      linked = (Collection<?>) ((Map<?, ?>) fieldValue).values();
      iContext.onBeforeMap(iRootRecord, fieldName, iUserObject);
    } else throw new IllegalStateException("Unrecognized type: " + fieldValue.getClass());

    final Iterator<?> iter;
    if (linked instanceof ORecordLazyMultiValue)
      iter = ((ORecordLazyMultiValue) linked).rawIterator();
    else iter = linked.iterator();

    while (iter.hasNext()) {
      final Object o = iter.next();
      if (o == null) continue;

      if (o instanceof OIdentifiable) {
        OIdentifiable d = (OIdentifiable) o;

        // GO RECURSIVELY
        final Integer fieldDepthLevel = parsedRecords.get(d.getIdentity());
        if (!d.getIdentity().isValid()
            || (fieldDepthLevel != null && fieldDepthLevel.intValue() == iLevelFromRoot)) {
          removeParsedFromMap(parsedRecords, d);
          d = d.getRecord();

          if (!(d instanceof ODocument)) {
            iListener.processStandardField(null, d, fieldName, iContext, iUserObject, "");
          } else {
            iContext.onBeforeDocument(iRootRecord, (ODocument) d, fieldName, iUserObject);
            final Object userObject =
                iListener.fetchLinkedCollectionValue(
                    iRootRecord, iUserObject, fieldName, (ODocument) d, iContext);
            processRecord(
                (ODocument) d,
                userObject,
                iFetchPlan,
                iCurrentLevel,
                iLevelFromRoot,
                iFieldDepthLevel,
                parsedRecords,
                iFieldPathFromRoot,
                iListener,
                iContext,
                "");
            iContext.onAfterDocument(iRootRecord, (ODocument) d, fieldName, iUserObject);
          }
        } else {
          iListener.parseLinkedCollectionValue(iRootRecord, d, iUserObject, fieldName, iContext);
        }
      } else if (o instanceof Map<?, ?>) {
        fetchMap(
            iRootRecord,
            iUserObject,
            iFetchPlan,
            o,
            null,
            iCurrentLevel + 1,
            iLevelFromRoot,
            iFieldDepthLevel,
            parsedRecords,
            iFieldPathFromRoot,
            iListener,
            iContext);
      } else if (OMultiValue.isMultiValue(o)) {
        fetchCollection(
            iRootRecord,
            iUserObject,
            iFetchPlan,
            o,
            null,
            iCurrentLevel + 1,
            iLevelFromRoot,
            iFieldDepthLevel,
            parsedRecords,
            iFieldPathFromRoot,
            iListener,
            iContext);
      }
    }

    if (fieldValue instanceof Collection<?>)
      iContext.onAfterCollection(iRootRecord, fieldName, iUserObject);
    else if (fieldValue instanceof Map<?, ?>)
      iContext.onAfterMap(iRootRecord, fieldName, iUserObject);
  }
예제 #4
0
  @SuppressWarnings("unchecked")
  private static void fetchMap(
      final ORecordSchemaAware<?> iRootRecord,
      final Object iUserObject,
      final Map<String, Integer> iFetchPlan,
      Object fieldValue,
      String fieldName,
      final int iCurrentLevel,
      final int iLevelFromRoot,
      final int iFieldDepthLevel,
      final Map<ORID, Integer> parsedRecords,
      final String iFieldPathFromRoot,
      final OFetchListener iListener,
      final OFetchContext iContext)
      throws IOException {
    final Map<String, ODocument> linked = (Map<String, ODocument>) fieldValue;
    iContext.onBeforeMap(iRootRecord, fieldName, iUserObject);

    for (Object key : linked.keySet()) {
      final Object o = linked.get(key);

      if (o instanceof OIdentifiable) {
        final ODocument d = ((OIdentifiable) o).getRecord();
        if (d != null) {
          // GO RECURSIVELY
          final Integer fieldDepthLevel = parsedRecords.get(d.getIdentity());
          if (!d.getIdentity().isValid()
              || (fieldDepthLevel != null && fieldDepthLevel.intValue() == iLevelFromRoot)) {
            removeParsedFromMap(parsedRecords, d);
            iContext.onBeforeDocument(iRootRecord, d, key.toString(), iUserObject);
            final Object userObject =
                iListener.fetchLinkedMapEntry(
                    iRootRecord, iUserObject, fieldName, key.toString(), d, iContext);
            processRecord(
                d,
                userObject,
                iFetchPlan,
                iCurrentLevel,
                iLevelFromRoot,
                iFieldDepthLevel,
                parsedRecords,
                iFieldPathFromRoot,
                iListener,
                iContext,
                "");
            iContext.onAfterDocument(iRootRecord, d, key.toString(), iUserObject);
          } else {
            iListener.parseLinked(iRootRecord, d, iUserObject, key.toString(), iContext);
          }
        }
      } else if (o instanceof Map) {
        fetchMap(
            iRootRecord,
            iUserObject,
            iFetchPlan,
            o,
            key.toString(),
            iCurrentLevel + 1,
            iLevelFromRoot,
            iFieldDepthLevel,
            parsedRecords,
            iFieldPathFromRoot,
            iListener,
            iContext);
      } else if (OMultiValue.isMultiValue(o)) {
        fetchCollection(
            iRootRecord,
            iUserObject,
            iFetchPlan,
            o,
            key.toString(),
            iCurrentLevel + 1,
            iLevelFromRoot,
            iFieldDepthLevel,
            parsedRecords,
            iFieldPathFromRoot,
            iListener,
            iContext);
      } else
        iListener.processStandardField(iRootRecord, o, key.toString(), iContext, iUserObject, "");
    }
    iContext.onAfterMap(iRootRecord, fieldName, iUserObject);
  }