Java Code Examples for com.orientechnologies.orient.core.record.impl.ODocument#rawField()

The following examples show how to use com.orientechnologies.orient.core.record.impl.ODocument#rawField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeconflictComponentMavenAttributes.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ConflictState deconflict(final ODocument storedRecord, final ODocument changeRecord) {
  Object storedMaven = storedRecord.rawField(MAVEN_ATTRIBUTES);
  Object changeMaven = changeRecord.rawField(MAVEN_ATTRIBUTES);
  if (storedMaven != null && changeMaven != null) {
    // packaging is only added when the pom asset is fetched/deployed
    return pickNonNull(storedRecord, changeRecord, PACKAGING_ATTRIBUTE);
  }
  else if (changeMaven != null) {
    storedRecord.field(MAVEN_ATTRIBUTES, changeMaven);
    return ALLOW;
  }
  else if (storedMaven != null) {
    changeRecord.field(MAVEN_ATTRIBUTES, storedMaven);
    return MERGE;
  }
  return IGNORE;
}
 
Example 2
Source File: DeconflictStepSupport.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves differences in the given optional field by picking non-null values over null values.
 */
public static ConflictState pickNonNull(final ODocument storedRecord,
                                        final ODocument changeRecord,
                                        final String fieldName)
{
  Object storedValue = storedRecord.rawField(fieldName);
  Object changeValue = changeRecord.rawField(fieldName);
  if (Objects.equals(storedValue, changeValue)) {
    return IGNORE;
  }
  else if (storedValue == null) {
    storedRecord.field(fieldName, changeValue);
    return ALLOW;
  }
  else if (changeValue == null) {
    changeRecord.field(fieldName, storedValue);
    return MERGE;
  }
  return DENY;
}
 
Example 3
Source File: DeconflictStepSupport.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves differences in the given date field by picking the latest time.
 *
 * If the incoming change has a later time we write that to our copy of the stored record
 * (the actual write to the DB happens after all resolution steps are done) so they match
 * when the final {@link EntityAdapter#compare} check happens. Otherwise if the stored time
 * is later then that value is merged with the incoming change record.
 */
public static ConflictState pickLatest(final ODocument storedRecord,
                                       final ODocument changeRecord,
                                       final String fieldName)
{
  Object storedValue = storedRecord.rawField(fieldName);
  Object changeValue = changeRecord.rawField(fieldName);
  // prefer later non-null times, over earlier/null times
  int comparison = MILLIS_COMPARATOR.compare(asMillis(storedValue), asMillis(changeValue));
  if (comparison < 0) {
    storedRecord.field(fieldName, changeValue);
    return ALLOW;
  }
  else if (comparison > 0) {
    changeRecord.field(fieldName, storedValue);
    return MERGE;
  }
  return IGNORE;
}
 
Example 4
Source File: DeconflictAssetMetadata.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves minor book-keeping differences in cache information.
 */
public static ConflictState resolveCache(final ODocument storedRecord, final ODocument changeRecord) {
  Object storedCache = storedRecord.rawField(CACHE_ATTRIBUTES);
  Object changeCache = changeRecord.rawField(CACHE_ATTRIBUTES);
  if (storedCache != null && changeCache != null) {
    return resolveCacheToken(storedRecord, changeRecord)
        .andThen(() -> pickLatest(storedRecord, changeRecord, LAST_VERIFIED_ATTRIBUTE));
  }
  else if (changeCache != null) {
    storedRecord.field(CACHE_ATTRIBUTES, changeCache);
    return ALLOW;
  }
  else if (storedCache != null) {
    changeRecord.field(CACHE_ATTRIBUTES, storedCache);
    return MERGE;
  }
  return IGNORE;
}
 
Example 5
Source File: DeconflictAssetMetadata.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves differences in cache tokens: "invalidated" always wins, non-null tokens win over null tokens.
 */
private static ConflictState resolveCacheToken(final ODocument storedRecord, final ODocument changeRecord) {
  Object storedToken = storedRecord.rawField(CACHE_TOKEN_ATTRIBUTE);
  Object changeToken = changeRecord.rawField(CACHE_TOKEN_ATTRIBUTE);
  if (Objects.equals(storedToken, changeToken)) {
    return IGNORE;
  }
  else if (storedToken == null || CACHE_TOKEN_INVALIDATED.equals(changeToken)) {
    storedRecord.field(CACHE_TOKEN_ATTRIBUTE, changeToken);
    return ALLOW;
  }
  else if (changeToken == null || CACHE_TOKEN_INVALIDATED.equals(storedToken)) {
    changeRecord.field(CACHE_TOKEN_ATTRIBUTE, storedToken);
    return MERGE;
  }
  return DENY;
}
 
Example 6
Source File: DeconflictAssetMetadata.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Resolves minor book-keeping differences in content information.
 */
public static ConflictState resolveContent(final ODocument storedRecord, final ODocument changeRecord) {
  Object storedContent = storedRecord.rawField(CONTENT_ATTRIBUTES);
  Object changeContent = changeRecord.rawField(CONTENT_ATTRIBUTES);
  if (storedContent != null && changeContent != null) {
    return pickLatest(storedRecord, changeRecord, LAST_MODIFIED_ATTRIBUTE);
  }
  else if (changeContent != null) {
    storedRecord.field(CONTENT_ATTRIBUTES, changeContent);
    return ALLOW;
  }
  else if (storedContent != null) {
    changeRecord.field(CONTENT_ATTRIBUTES, storedContent);
    return MERGE;
  }
  return IGNORE;
}
 
Example 7
Source File: EntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Does one last round of comparison between the (hopefully) deconflicted records.
 *
 * @since 3.14
 */
protected ConflictState compare(final ODocument storedRecord, final ODocument changeRecord) {
  for (Entry<String, Object> property : storedRecord) {
    Object changeValue = changeRecord.rawField(property.getKey());
    if (!Objects.equals(property.getValue(), changeValue)) {
      log.trace("Conflict detected in {}: {} vs {}", property.getKey(), property.getValue(), changeValue);
      return DENY;
    }
  }
  return IGNORE; // identical content, update can be ignored or allowed
}