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); }
public static void processRecordRidMap( final ORecordSchemaAware<?> record, Map<String, Integer> iFetchPlan, final int iCurrentLevel, final int iLevelFromRoot, final int iFieldDepthLevel, final Map<ORID, Integer> parsedRecords, final String iFieldPathFromRoot, final OFetchContext iContext) throws IOException { if (iFetchPlan == null) return; Object fieldValue; for (String fieldName : record.fieldNames()) { int depthLevel; final String fieldPath = !iFieldPathFromRoot.isEmpty() ? iFieldPathFromRoot + "." + fieldName : fieldName; depthLevel = getDepthLevel(iFetchPlan, fieldPath); if (depthLevel == -2) continue; if (iFieldDepthLevel > -1) depthLevel = iFieldDepthLevel; fieldValue = record.field(fieldName); if (fieldValue == null || !(fieldValue instanceof OIdentifiable) && (!(fieldValue instanceof ORecordLazyMultiValue) || !((ORecordLazyMultiValue) fieldValue).rawIterator().hasNext() || !(((ORecordLazyMultiValue) fieldValue).rawIterator().next() instanceof OIdentifiable)) && (!(fieldValue instanceof Collection<?>) || ((Collection<?>) fieldValue).size() == 0 || !(((Collection<?>) fieldValue).iterator().next() instanceof OIdentifiable)) && (!(fieldValue instanceof OMultiCollectionIterator<?>)) && (!(fieldValue instanceof Map<?, ?>) || ((Map<?, ?>) fieldValue).size() == 0 || !(((Map<?, ?>) fieldValue).values().iterator().next() instanceof OIdentifiable))) { continue; } else { try { final boolean isEmbedded = fieldValue instanceof ODocument && (((ODocument) fieldValue).isEmbedded() || !((ODocument) fieldValue).getIdentity().isValid()); if (!(isEmbedded && iContext.fetchEmbeddedDocuments()) && !iFetchPlan.containsKey(fieldPath) && depthLevel > -1 && iCurrentLevel >= depthLevel) // MAX DEPTH REACHED: STOP TO FETCH THIS FIELD continue; final int nextLevel = isEmbedded ? iLevelFromRoot : iLevelFromRoot + 1; fetchRidMap( record, iFetchPlan, fieldValue, fieldName, iCurrentLevel, nextLevel, iFieldDepthLevel, parsedRecords, fieldPath, iContext); } catch (Exception e) { e.printStackTrace(); OLogManager.instance() .error(null, "Fetching error on record %s", e, record.getIdentity()); } } } }