core/src/main/java/com/orientechnologies/orient/core/storage/impl/local/OMicroTransaction.java
public void updateIdentityAfterRecordCommit(final ORID oldRid, final ORID newRid) {
    if (oldRid.equals(newRid))
      return; // no change, ignore

    // XXX: Identity update may mutate the index keys, so we have to identify and reinsert potentially affected index keys to keep
    // the OTransactionIndexChanges.changesPerKey in a consistent state.

    final List<KeyChangesUpdateRecord> keyRecordsToReinsert = new ArrayList<>();
    final OIndexManager indexManager = getDatabase().getMetadata().getIndexManager();
    for (Map.Entry<String, OTransactionIndexChanges> entry : indexOperations.entrySet()) {
      final OIndex<?> index = indexManager.getIndex(entry.getKey());
      if (index == null)
        throw new OTransactionException("Cannot find index '" + entry.getValue() + "' while committing transaction");

      final Dependency[] fieldRidDependencies = getIndexFieldRidDependencies(index);
      if (!isIndexMayDependOnRids(fieldRidDependencies))
        continue;

      final OTransactionIndexChanges indexChanges = entry.getValue();
      for (final Iterator<OTransactionIndexChangesPerKey> iterator = indexChanges.changesPerKey.values().iterator(); iterator
          .hasNext(); ) {
        final OTransactionIndexChangesPerKey keyChanges = iterator.next();
        if (isIndexKeyMayDependOnRid(keyChanges.key, oldRid, fieldRidDependencies)) {
          keyRecordsToReinsert.add(new KeyChangesUpdateRecord(keyChanges, indexChanges));
          iterator.remove();
        }
      }
    }

    // Update the identity.

    final ORecordOperation rec = resolveRecordOperation(oldRid);
    if (rec != null) {
      updatedRids.put(newRid.copy(), oldRid.copy());

      if (!rec.getRecord().getIdentity().equals(newRid)) {
        ORecordInternal.onBeforeIdentityChanged(rec.getRecord());

        final ORecordId recordId = (ORecordId) rec.getRecord().getIdentity();
        if (recordId == null) {
          ORecordInternal.setIdentity(rec.getRecord(), new ORecordId(newRid));
        } else {
          recordId.setClusterPosition(newRid.getClusterPosition());
          recordId.setClusterId(newRid.getClusterId());
        }

        ORecordInternal.onAfterIdentityChanged(rec.getRecord());
      }
    }

    // Reinsert the potentially affected index keys.

    for (KeyChangesUpdateRecord record : keyRecordsToReinsert)
      record.indexChanges.changesPerKey.put(record.keyChanges.key, record.keyChanges);

    // Update the indexes.

    final List<OTransactionRecordIndexOperation> transactionIndexOperations = recordIndexOperations.get(translateRid(oldRid));
    if (transactionIndexOperations != null) {
      for (final OTransactionRecordIndexOperation indexOperation : transactionIndexOperations) {
        OTransactionIndexChanges indexEntryChanges = indexOperations.get(indexOperation.index);
        if (indexEntryChanges == null)
          continue;
        final OTransactionIndexChangesPerKey keyChanges;
        if (indexOperation.key == null) {
          keyChanges = indexEntryChanges.nullKeyChanges;
        } else {
          keyChanges = indexEntryChanges.changesPerKey.get(indexOperation.key);
        }
        if (keyChanges != null)
          updateChangesIdentity(oldRid, newRid, keyChanges);
      }
    }
  }
public void updateIdentityAfterRecordCommit(final ORID oldRid, final ORID newRid) {
    if (oldRid.equals(newRid))
      return; // no change, ignore

    // XXX: Identity update may mutate the index keys, so we have to identify and reinsert potentially affected index keys to keep
    // the OTransactionIndexChanges.changesPerKey in a consistent state.

    final List<KeyChangesUpdateRecord> keyRecordsToReinsert = new ArrayList<>();
    final OIndexManager indexManager = getDatabase().getMetadata().getIndexManager();
    for (Map.Entry<String, OTransactionIndexChanges> entry : indexOperations.entrySet()) {
      final OIndex<?> index = indexManager.getIndex(entry.getKey());
      if (index == null)
        throw new OTransactionException("Cannot find index '" + entry.getValue() + "' while committing transaction");

      final Dependency[] fieldRidDependencies = getIndexFieldRidDependencies(index);
      if (!isIndexMayDependOnRids(fieldRidDependencies))
        continue;

      final OTransactionIndexChanges indexChanges = entry.getValue();
      for (final Iterator<OTransactionIndexChangesPerKey> iterator = indexChanges.changesPerKey.values().iterator(); iterator
          .hasNext(); ) {
        final OTransactionIndexChangesPerKey keyChanges = iterator.next();
        if (isIndexKeyMayDependOnRid(keyChanges.key, oldRid, fieldRidDependencies)) {
          keyRecordsToReinsert.add(new KeyChangesUpdateRecord(keyChanges, indexChanges));
          iterator.remove();
        }
      }
    }

    // Update the identity.

    final ORecordOperation rec = resolveRecordOperation(oldRid);
    if (rec != null) {
      updatedRids.put(newRid.copy(), oldRid.copy());

      if (!rec.getRecord().getIdentity().equals(newRid)) {
        ORecordInternal.onBeforeIdentityChanged(rec.getRecord());

        final ORecordId recordId = (ORecordId) rec.getRecord().getIdentity();
        if (recordId == null) {
          ORecordInternal.setIdentity(rec.getRecord(), new ORecordId(newRid));
        } else {
          recordId.setClusterPosition(newRid.getClusterPosition());
          recordId.setClusterId(newRid.getClusterId());
        }

        ORecordInternal.onAfterIdentityChanged(rec.getRecord());
      }
    }

    // Reinsert the potentially affected index keys.

    for (KeyChangesUpdateRecord record : keyRecordsToReinsert)
      record.indexChanges.changesPerKey.put(record.keyChanges.key, record.keyChanges);

    // Update the indexes.

    final List<OTransactionRecordIndexOperation> transactionIndexOperations = recordIndexOperations.get(translateRid(oldRid));
    if (transactionIndexOperations != null) {
      for (final OTransactionRecordIndexOperation indexOperation : transactionIndexOperations) {
        OTransactionIndexChanges indexEntryChanges = indexOperations.get(indexOperation.index);
        if (indexEntryChanges == null)
          continue;
        final OTransactionIndexChangesPerKey keyChanges;
        if (indexOperation.key == null) {
          keyChanges = indexEntryChanges.nullKeyChanges;
        } else {
          keyChanges = indexEntryChanges.changesPerKey.get(indexOperation.key);
        }
        if (keyChanges != null)
          updateChangesIdentity(oldRid, newRid, keyChanges);
      }
    }
  }
public void updateIdentityAfterRecordCommit ( final ORID oldRid , final ORID newRid ) { if ( oldRid . equals ( newRid ) ) return ; // no change, ignore // XXX: Identity update may mutate the index keys, so we have to identify and reinsert potentially affected index keys to keep // the OTransactionIndexChanges.changesPerKey in a consistent state. final List < KeyChangesUpdateRecord > keyRecordsToReinsert = new ArrayList <> ( ) ; final OIndexManager indexManager = getDatabase ( ) . getMetadata ( ) . getIndexManager ( ) ; for ( Map . Entry < String , OTransactionIndexChanges > entry : indexOperations . entrySet ( ) ) { final OIndex < ? > index = indexManager . getIndex ( entry . getKey ( ) ) ; if ( index == null ) throw new OTransactionException ( "Cannot find index '" + entry . getValue ( ) + "' while committing transaction" ) ; final Dependency [ ] fieldRidDependencies = getIndexFieldRidDependencies ( index ) ; if ( ! isIndexMayDependOnRids ( fieldRidDependencies ) ) continue ; final OTransactionIndexChanges indexChanges = entry . getValue ( ) ; for ( final Iterator < OTransactionIndexChangesPerKey > iterator = indexChanges . changesPerKey . values ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { final OTransactionIndexChangesPerKey keyChanges = iterator . next ( ) ; if ( isIndexKeyMayDependOnRid ( keyChanges . key , oldRid , fieldRidDependencies ) ) { keyRecordsToReinsert . add ( new KeyChangesUpdateRecord ( keyChanges , indexChanges ) ) ; iterator . remove ( ) ; } } } // Update the identity. final ORecordOperation rec = resolveRecordOperation ( oldRid ) ; if ( rec != null ) { updatedRids . put ( newRid . copy ( ) , oldRid . copy ( ) ) ; if ( ! rec . getRecord ( ) . getIdentity ( ) . equals ( newRid ) ) { ORecordInternal . onBeforeIdentityChanged ( rec . getRecord ( ) ) ; final ORecordId recordId = ( ORecordId ) rec . getRecord ( ) . getIdentity ( ) ; if ( recordId == null ) { ORecordInternal . setIdentity ( rec . getRecord ( ) , new ORecordId ( newRid ) ) ; } else { recordId . setClusterPosition ( newRid . getClusterPosition ( ) ) ; recordId . setClusterId ( newRid . getClusterId ( ) ) ; } ORecordInternal . onAfterIdentityChanged ( rec . getRecord ( ) ) ; } } // Reinsert the potentially affected index keys. for ( KeyChangesUpdateRecord record : keyRecordsToReinsert ) record . indexChanges . changesPerKey . put ( record . keyChanges . key , record . keyChanges ) ; // Update the indexes. final List < OTransactionRecordIndexOperation > transactionIndexOperations = recordIndexOperations . get ( translateRid ( oldRid ) ) ; if ( transactionIndexOperations != null ) { for ( final OTransactionRecordIndexOperation indexOperation : transactionIndexOperations ) { OTransactionIndexChanges indexEntryChanges = indexOperations . get ( indexOperation . index ) ; if ( indexEntryChanges == null ) continue ; final OTransactionIndexChangesPerKey keyChanges ; if ( indexOperation . key == null ) { keyChanges = indexEntryChanges . nullKeyChanges ; } else { keyChanges = indexEntryChanges . changesPerKey . get ( indexOperation . key ) ; } if ( keyChanges != null ) updateChangesIdentity ( oldRid , newRid , keyChanges ) ; } } }
Updates the record identity after its successful commit.
Updates the record identity after its successful commit .