All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.orientechnologies.orient.core.db.tool.importer.OLinksRewriter Maven / Gradle / Ivy

There is a newer version: 3.2.32
Show newest version
package com.orientechnologies.orient.core.db.tool.importer;

import com.orientechnologies.orient.core.db.document.ODocumentFieldVisitor;
import com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue;
import com.orientechnologies.orient.core.metadata.schema.OType;

/** Created by tglman on 28/07/17. */
public final class OLinksRewriter implements ODocumentFieldVisitor {
  private OConverterData converterData;

  public OLinksRewriter(OConverterData converterData) {
    this.converterData = converterData;
  }

  @Override
  public Object visitField(OType type, OType linkedType, Object value) {
    boolean oldAutoConvertValue = false;
    if (value instanceof ORecordLazyMultiValue) {
      ORecordLazyMultiValue multiValue = (ORecordLazyMultiValue) value;
      oldAutoConvertValue = multiValue.isAutoConvertToRecord();
      multiValue.setAutoConvertToRecord(false);
    }

    final OValuesConverter valuesConverter =
        OImportConvertersFactory.INSTANCE.getConverter(value, converterData);
    if (valuesConverter == null) return value;

    final Object newValue = valuesConverter.convert(value);

    if (value instanceof ORecordLazyMultiValue) {
      ORecordLazyMultiValue multiValue = (ORecordLazyMultiValue) value;
      multiValue.setAutoConvertToRecord(oldAutoConvertValue);
    }

    // this code intentionally uses == instead of equals, in such case we may distinguish rids which
    // already contained in
    // document and RID which is used to indicate broken record
    if (newValue == OImportConvertersFactory.BROKEN_LINK) return null;

    return newValue;
  }

  @Override
  public boolean goFurther(OType type, OType linkedType, Object value, Object newValue) {
    return true;
  }

  @Override
  public boolean goDeeper(OType type, OType linkedType, Object value) {
    return true;
  }

  @Override
  public boolean updateMode() {
    return true;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy