oldFieldIndex < oldFields.size();
oldFieldIndex += 1) {
FieldInfo oldField = oldFields.get(oldFieldIndex);
String oldName = oldField.getName();
SecondaryKeyMetadata oldMeta = null;
if (isOldSecKeyField) {
oldMeta = getSecondaryKeyMetadataByFieldName
(clsMeta.getSecondaryKeys(), oldName);
assert oldMeta != null;
}
/* Get field mutations. */
Renamer renamer = mutations.getRenamer
(getClassName(), getVersion(), oldName);
Deleter deleter = mutations.getDeleter
(getClassName(), getVersion(), oldName);
Converter converter = mutations.getConverter
(getClassName(), getVersion(), oldName);
if (deleter != null && (converter != null || renamer != null)) {
evolver.addInvalidMutation
(this, newFormat, deleter,
"Field Deleter is not allowed along with a Renamer or " +
"Converter for the same field: " + oldName);
evolveFailure = true;
continue fieldLoop;
}
/*
* Match old and new field by name, taking into account the Renamer
* mutation. If the @SecondaryKey annotation was added or removed,
* the field will have moved from one of the two field lists to the
* other.
*/
String newName = (renamer != null) ?
renamer.getNewName() : oldName;
boolean nameChanged = false;
if (!oldName.equals(newName)) {
if (newToOldFieldMap == null) {
newToOldFieldMap = new HashMap<String, String>();
}
newToOldFieldMap.put(newName, oldName);
nameChanged = true;
}
int newFieldIndex = FieldInfo.getFieldIndex(newFields, newName);
FieldInfo newField = null;
boolean isNewSecKeyField = isOldSecKeyField;
if (newFieldIndex >= 0) {
newField = newFields.get(newFieldIndex);
/*
* Change the key name in incorrectlyOrderedSecKeys of the new
* format.
*/
if (nameChanged &&
newFormat.incorrectlyOrderedSecKeys != null &&
newFormat.incorrectlyOrderedSecKeys.remove(oldName)) {
newFormat.incorrectlyOrderedSecKeys.add(newName);
}
/*
* [#18961] If the order of the field has been changed, we will
* create a PlainFieldReader for it.
*/
if (newFieldIndex != oldFieldIndex) {
localEvolveNeeded = true;
readerNeeded = true;
}
} else {
newFieldIndex = FieldInfo.getFieldIndex
(otherNewFields, newName);
if (newFieldIndex >= 0) {
newField = otherNewFields.get(newFieldIndex);
isNewSecKeyField = !isOldSecKeyField;
}
localEvolveNeeded = true;
readerNeeded = true;
/*
* Remove the key in incorrectlyOrderedSecKeys of the new
* format.
*/
if (newFormat.incorrectlyOrderedSecKeys != null) {
newFormat.incorrectlyOrderedSecKeys.remove(oldName);
}
}
/* Apply field Deleter and continue. */
if (deleter != null) {
if (newField != null) {
evolver.addInvalidMutation
(this, newFormat, deleter,
"Field Deleter is not allowed when the persistent " +
"field is still present: " + oldName);
evolveFailure = true;
}
/* A SkipFieldReader can read multiple sequential fields. */
if (currentReader instanceof SkipFieldReader &&
currentReader.acceptField
(oldFieldIndex, newFieldIndex, isNewSecKeyField)) {
currentReader.addField(oldField);
} else {
currentReader = new SkipFieldReader
(oldFieldIndex, oldField);
fieldReaders.add(currentReader);
readerNeeded = true;
localEvolveNeeded = true;
}
if (isOldSecKeyField) {
if (oldToNewKeyMap == null) {
oldToNewKeyMap = new HashMap<String, String>();
}
oldToNewKeyMap.put(oldMeta.getKeyName(), null);
}
continue fieldLoop;
} else {
if (newField == null) {
evolver.addMissingMutation
(this, newFormat,
"Field is not present or not persistent: " +
oldName);
evolveFailure = true;
continue fieldLoop;
}
}
/*
* The old field corresponds to a known new field, and no Deleter
* mutation applies.
*/
newFieldsMatched += 1;
/* Get and process secondary key metadata changes. */
SecondaryKeyMetadata newMeta = null;
if (isOldSecKeyField && isNewSecKeyField) {
newMeta = getSecondaryKeyMetadataByFieldName
(newFormat.clsMeta.getSecondaryKeys(), newName);
assert newMeta != null;
/* Validate metadata changes. */
if (!checkSecKeyMetadata
(newFormat, oldMeta, newMeta, evolver)) {
evolveFailure = true;
continue fieldLoop;
}
/*
* Check for a renamed key and save the old-to-new mapping for
* use in renaming the secondary database and for key
* extraction.
*/
String oldKeyName = oldMeta.getKeyName();
String newKeyName = newMeta.getKeyName();
if (!oldKeyName.equals(newKeyName)) {
if (oldToNewKeyMap == null) {
oldToNewKeyMap = new HashMap<String, String>();
}
oldToNewKeyMap.put(oldName, newName);