graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
protected static OrientEdge getEdge(final OrientBaseGraph graph, final ODocument doc, String fieldName,
      final OPair<Direction, String> connection, final Object fieldValue, final OIdentifiable iTargetVertex,
      final String[] iLabels) {
    final OrientEdge toAdd;

    final ODocument fieldRecord = ((OIdentifiable) fieldValue).getRecord();
    if (fieldRecord == null)
      return null;

    OClass klass = ODocumentInternal.getImmutableSchemaClass(fieldRecord);
    if (klass == null && ODatabaseRecordThreadLocal.instance().getIfDefined() != null) {
      ODatabaseRecordThreadLocal.instance().getIfDefined().getMetadata().reload();
      klass = fieldRecord.getSchemaClass();
    }

    if (klass.isVertexType()) {
      if (iTargetVertex != null && !iTargetVertex.equals(fieldValue))
        return null;

      // DIRECT VERTEX, CREATE A DUMMY EDGE BETWEEN VERTICES
      if (connection.getKey() == Direction.OUT)
        toAdd = graph.getEdgeInstance(doc, fieldRecord, connection.getValue());
      else
        toAdd = graph.getEdgeInstance(fieldRecord, doc, connection.getValue());

    } else if (klass.isEdgeType()) {
      // EDGE
      if (iTargetVertex != null) {
        Object targetVertex = OrientEdge.getConnection(fieldRecord, connection.getKey().opposite());

        if (!iTargetVertex.equals(targetVertex))
          return null;
      }

      toAdd = graph.getEdge(fieldRecord);
    } else
      throw new IllegalStateException("Invalid content found in " + fieldName + " field: " + fieldRecord);

    return toAdd;
  }
protected static OrientEdge getEdge(final OrientBaseGraph graph, final ODocument doc, String fieldName,
      final OPair<Direction, String> connection, final Object fieldValue, final OIdentifiable iTargetVertex,
      final String[] iLabels) {
    final OrientEdge toAdd;

    final ODocument fieldRecord = ((OIdentifiable) fieldValue).getRecord();
    if (fieldRecord == null)
      return null;

    OClass klass = ODocumentInternal.getImmutableSchemaClass(fieldRecord);
    if (klass == null && ODatabaseRecordThreadLocal.instance().getIfDefined() != null) {
      ODatabaseRecordThreadLocal.instance().getIfDefined().getMetadata().reload();
      klass = fieldRecord.getSchemaClass();
    }

    if (klass.isVertexType()) {
      if (iTargetVertex != null && !iTargetVertex.equals(fieldValue))
        return null;

      // DIRECT VERTEX, CREATE A DUMMY EDGE BETWEEN VERTICES
      if (connection.getKey() == Direction.OUT)
        toAdd = graph.getEdgeInstance(doc, fieldRecord, connection.getValue());
      else
        toAdd = graph.getEdgeInstance(fieldRecord, doc, connection.getValue());

    } else if (klass.isEdgeType()) {
      // EDGE
      if (iTargetVertex != null) {
        Object targetVertex = OrientEdge.getConnection(fieldRecord, connection.getKey().opposite());

        if (!iTargetVertex.equals(targetVertex))
          return null;
      }

      toAdd = graph.getEdge(fieldRecord);
    } else
      throw new IllegalStateException("Invalid content found in " + fieldName + " field: " + fieldRecord);

    return toAdd;
  }
(Internal only)