graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientVertex.java
public static void replaceLinks(final ODocument iVertex, final String iFieldName, final OIdentifiable iVertexToRemove,
      final OIdentifiable iNewVertex) {
    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)) {
          return;
        }
        iVertex.field(iFieldName, iNewVertex);
      }

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

      boolean found = false;
      final Iterator<OIdentifiable> it = bag.rawIterator();
      while (it.hasNext()) {
        if (it.next().equals(iVertexToRemove)) {
          // REMOVE THE OLD ENTRY
          found = true;
          it.remove();
        }
      }
      if (found)
        // ADD THE NEW ONE
        bag.add(iNewVertex);

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

      if (col.remove(iVertexToRemove))
        col.add(iNewVertex);
    }

    iVertex.save();
  }
public static void replaceLinks(final ODocument iVertex, final String iFieldName, final OIdentifiable iVertexToRemove,
      final OIdentifiable iNewVertex) {
    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)) {
          return;
        }
        iVertex.field(iFieldName, iNewVertex);
      }

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

      boolean found = false;
      final Iterator<OIdentifiable> it = bag.rawIterator();
      while (it.hasNext()) {
        if (it.next().equals(iVertexToRemove)) {
          // REMOVE THE OLD ENTRY
          found = true;
          it.remove();
        }
      }
      if (found)
        // ADD THE NEW ONE
        bag.add(iNewVertex);

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

      if (col.remove(iVertexToRemove))
        col.add(iNewVertex);
    }

    iVertex.save();
  }
public static void replaceLinks ( final ODocument iVertex , final String iFieldName , final OIdentifiable iVertexToRemove , final OIdentifiable iNewVertex ) { 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 ) ) { return ; } iVertex . field ( iFieldName , iNewVertex ) ; } } else if ( fieldValue instanceof ORidBag ) { // COLLECTION OF RECORDS: REMOVE THE ENTRY final ORidBag bag = ( ORidBag ) fieldValue ; boolean found = false ; final Iterator < OIdentifiable > it = bag . rawIterator ( ) ; while ( it . hasNext ( ) ) { if ( it . next ( ) . equals ( iVertexToRemove ) ) { // REMOVE THE OLD ENTRY found = true ; it . remove ( ) ; } } if ( found ) // ADD THE NEW ONE bag . add ( iNewVertex ) ; } else if ( fieldValue instanceof Collection ) { final Collection col = ( Collection ) fieldValue ; if ( col . remove ( iVertexToRemove ) ) col . add ( iNewVertex ) ; } iVertex . save ( ) ; }
(Internal only)
( Internal only )