graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
protected static void removeEdges(final OrientBaseGraph graph, final ODocument iVertex, final String iFieldName,
      final OIdentifiable iVertexToRemove, final boolean iAlsoInverse, final boolean useVertexFieldsForEdgeLabels,
      final boolean autoScaleEdgeType, final boolean forceReload) {
    if (iVertex == null)
      return;

    final Object fieldValue = iVertexToRemove != null ? iVertex.field(iFieldName) : iVertex.removeField(iFieldName);
    if (fieldValue == null)
      return;

    if (fieldValue instanceof OIdentifiable) {
      // SINGLE RECORD

      if (iVertexToRemove != null) {
        if (!fieldValue.equals(iVertexToRemove))
          // NOT FOUND
          return;

        iVertex.removeField(iFieldName);

        deleteEdgeIfAny(iVertexToRemove, forceReload);
      }

      if (iAlsoInverse)
        removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, (OIdentifiable) fieldValue, useVertexFieldsForEdgeLabels,
            autoScaleEdgeType, forceReload);

    } else if (fieldValue instanceof ORidBag) {
      // COLLECTION OF RECORDS: REMOVE THE ENTRY
      final ORidBag bag = (ORidBag) fieldValue;

      if (iVertexToRemove != null) {
        // SEARCH SEQUENTIALLY (SLOWER)
        for (Iterator<OIdentifiable> it = bag.rawIterator(); it.hasNext(); ) {
          final ODocument curr = getDocument(it.next(), forceReload);

          if (curr == null) {
            // EDGE REMOVED
            it.remove();
            iVertex.save();
            continue;
          }

          if (iVertexToRemove.equals(curr)) {
            // FOUND AS VERTEX
            it.remove();
            if (iAlsoInverse)
              removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, curr, useVertexFieldsForEdgeLabels, autoScaleEdgeType,
                  forceReload);
            break;

          } else if (ODocumentInternal.getImmutableSchemaClass(curr).isEdgeType()) {
            final Direction direction = OrientVertex.getConnectionDirection(iFieldName, useVertexFieldsForEdgeLabels);

            // EDGE, REMOVE THE EDGE
            if (iVertexToRemove.equals(OrientEdge.getConnection(curr, direction.opposite()))) {
              it.remove();
              if (iAlsoInverse)
                removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, curr, useVertexFieldsForEdgeLabels,
                    autoScaleEdgeType, forceReload);
              break;
            }
          }
        }

        deleteEdgeIfAny(iVertexToRemove, forceReload);

      } else {

        // DELETE ALL THE EDGES
        for (Iterator<OIdentifiable> it = bag.rawIterator(); it.hasNext(); ) {
          OIdentifiable edge = it.next();
          if (iAlsoInverse)
            removeInverseEdge(graph, iVertex, iFieldName, null, edge, useVertexFieldsForEdgeLabels, autoScaleEdgeType, forceReload);

          deleteEdgeIfAny(edge, forceReload);
        }
      }

      if (autoScaleEdgeType && bag.isEmpty())
        // FORCE REMOVAL OF ENTIRE FIELD
        iVertex.removeField(iFieldName);

    } else if (fieldValue instanceof Collection) {
      final Collection col = (Collection) fieldValue;

      if (iVertexToRemove != null) {
        // SEARCH SEQUENTIALLY (SLOWER)
        for (Iterator<OIdentifiable> it = col.iterator(); it.hasNext(); ) {
          final ODocument curr = getDocument(it.next(), forceReload);

          if (curr == null)
            // EDGE REMOVED
            continue;

          if (iVertexToRemove.equals(curr)) {
            // FOUND AS VERTEX
            it.remove();
            if (iAlsoInverse)
              removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, curr, useVertexFieldsForEdgeLabels, autoScaleEdgeType,
                  forceReload);
            break;

          } else if (ODocumentInternal.getImmutableSchemaClass(curr).isVertexType()) {
            final Direction direction = OrientVertex.getConnectionDirection(iFieldName, useVertexFieldsForEdgeLabels);

            // EDGE, REMOVE THE EDGE
            if (iVertexToRemove.equals(OrientEdge.getConnection(curr, direction.opposite()))) {
              it.remove();
              if (iAlsoInverse)
                removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, curr, useVertexFieldsForEdgeLabels,
                    autoScaleEdgeType, forceReload);
              break;
            }
          }
        }

        deleteEdgeIfAny(iVertexToRemove, forceReload);

      } else {

        // DELETE ALL THE EDGES
        for (OIdentifiable edge : (Iterable<OIdentifiable>) col) {

          if (iAlsoInverse)
            removeInverseEdge(graph, iVertex, iFieldName, null, edge, useVertexFieldsForEdgeLabels, autoScaleEdgeType, forceReload);

          deleteEdgeIfAny(edge, forceReload);
        }
      }

      if (autoScaleEdgeType && col.isEmpty())
        // FORCE REMOVAL OF ENTIRE FIELD
        iVertex.removeField(iFieldName);
    }
  }
protected static void removeEdges(final OrientBaseGraph graph, final ODocument iVertex, final String iFieldName,
      final OIdentifiable iVertexToRemove, final boolean iAlsoInverse, final boolean useVertexFieldsForEdgeLabels,
      final boolean autoScaleEdgeType, final boolean forceReload) {
    if (iVertex == null)
      return;

    final Object fieldValue = iVertexToRemove != null ? iVertex.field(iFieldName) : iVertex.removeField(iFieldName);
    if (fieldValue == null)
      return;

    if (fieldValue instanceof OIdentifiable) {
      // SINGLE RECORD

      if (iVertexToRemove != null) {
        if (!fieldValue.equals(iVertexToRemove))
          // NOT FOUND
          return;

        iVertex.removeField(iFieldName);

        deleteEdgeIfAny(iVertexToRemove, forceReload);
      }

      if (iAlsoInverse)
        removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, (OIdentifiable) fieldValue, useVertexFieldsForEdgeLabels,
            autoScaleEdgeType, forceReload);

    } else if (fieldValue instanceof ORidBag) {
      // COLLECTION OF RECORDS: REMOVE THE ENTRY
      final ORidBag bag = (ORidBag) fieldValue;

      if (iVertexToRemove != null) {
        // SEARCH SEQUENTIALLY (SLOWER)
        for (Iterator<OIdentifiable> it = bag.rawIterator(); it.hasNext(); ) {
          final ODocument curr = getDocument(it.next(), forceReload);

          if (curr == null) {
            // EDGE REMOVED
            it.remove();
            iVertex.save();
            continue;
          }

          if (iVertexToRemove.equals(curr)) {
            // FOUND AS VERTEX
            it.remove();
            if (iAlsoInverse)
              removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, curr, useVertexFieldsForEdgeLabels, autoScaleEdgeType,
                  forceReload);
            break;

          } else if (ODocumentInternal.getImmutableSchemaClass(curr).isEdgeType()) {
            final Direction direction = OrientVertex.getConnectionDirection(iFieldName, useVertexFieldsForEdgeLabels);

            // EDGE, REMOVE THE EDGE
            if (iVertexToRemove.equals(OrientEdge.getConnection(curr, direction.opposite()))) {
              it.remove();
              if (iAlsoInverse)
                removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, curr, useVertexFieldsForEdgeLabels,
                    autoScaleEdgeType, forceReload);
              break;
            }
          }
        }

        deleteEdgeIfAny(iVertexToRemove, forceReload);

      } else {

        // DELETE ALL THE EDGES
        for (Iterator<OIdentifiable> it = bag.rawIterator(); it.hasNext(); ) {
          OIdentifiable edge = it.next();
          if (iAlsoInverse)
            removeInverseEdge(graph, iVertex, iFieldName, null, edge, useVertexFieldsForEdgeLabels, autoScaleEdgeType, forceReload);

          deleteEdgeIfAny(edge, forceReload);
        }
      }

      if (autoScaleEdgeType && bag.isEmpty())
        // FORCE REMOVAL OF ENTIRE FIELD
        iVertex.removeField(iFieldName);

    } else if (fieldValue instanceof Collection) {
      final Collection col = (Collection) fieldValue;

      if (iVertexToRemove != null) {
        // SEARCH SEQUENTIALLY (SLOWER)
        for (Iterator<OIdentifiable> it = col.iterator(); it.hasNext(); ) {
          final ODocument curr = getDocument(it.next(), forceReload);

          if (curr == null)
            // EDGE REMOVED
            continue;

          if (iVertexToRemove.equals(curr)) {
            // FOUND AS VERTEX
            it.remove();
            if (iAlsoInverse)
              removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, curr, useVertexFieldsForEdgeLabels, autoScaleEdgeType,
                  forceReload);
            break;

          } else if (ODocumentInternal.getImmutableSchemaClass(curr).isVertexType()) {
            final Direction direction = OrientVertex.getConnectionDirection(iFieldName, useVertexFieldsForEdgeLabels);

            // EDGE, REMOVE THE EDGE
            if (iVertexToRemove.equals(OrientEdge.getConnection(curr, direction.opposite()))) {
              it.remove();
              if (iAlsoInverse)
                removeInverseEdge(graph, iVertex, iFieldName, iVertexToRemove, curr, useVertexFieldsForEdgeLabels,
                    autoScaleEdgeType, forceReload);
              break;
            }
          }
        }

        deleteEdgeIfAny(iVertexToRemove, forceReload);

      } else {

        // DELETE ALL THE EDGES
        for (OIdentifiable edge : (Iterable<OIdentifiable>) col) {

          if (iAlsoInverse)
            removeInverseEdge(graph, iVertex, iFieldName, null, edge, useVertexFieldsForEdgeLabels, autoScaleEdgeType, forceReload);

          deleteEdgeIfAny(edge, forceReload);
        }
      }

      if (autoScaleEdgeType && col.isEmpty())
        // FORCE REMOVAL OF ENTIRE FIELD
        iVertex.removeField(iFieldName);
    }
  }
(Internal only)