} else if (record.getRecordTypeName() == null) {
recordTypeVersion = originalRecord.getRecordTypeVersion();
} else {
recordTypeVersion = record.getRecordTypeVersion();
}
RecordType recordType = typeManager.getRecordTypeByName(recordTypeName, recordTypeVersion);
// Update the mutable record type in the record object
Scope mutableScope = Scope.VERSIONED_MUTABLE;
newRecord.setRecordType(mutableScope, recordType.getName(), recordType.getVersion());
// If the record type changed, update it on the record table
QName originalMutableScopeRecordTypeName = originalRecord.getRecordTypeName(mutableScope);
if (originalMutableScopeRecordTypeName == null) { // There was no initial mutable record type yet
put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(mutableScope), version,
recordType.getId().getBytes());
put.add(RecordCf.DATA.bytes, RECORD_TYPE_VERSION_QUALIFIERS.get(mutableScope), version,
Bytes.toBytes(recordType.getVersion()));
} else {
RecordType originalMutableScopeRecordType = typeManager
.getRecordTypeByName(originalMutableScopeRecordTypeName,
originalRecord.getRecordTypeVersion(mutableScope));
if (!recordType.getId().equals(originalMutableScopeRecordType.getId())) {
// If the next record version had the same record type name, copy the original value to that one
if (originalNextRecord != null && originalMutableScopeRecordType.getName()
.equals(originalNextRecord.getRecordTypeName(mutableScope))) {
put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(mutableScope), version + 1,
originalMutableScopeRecordType.getId().getBytes());
}
put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(mutableScope), version,
recordType.getId().getBytes());
}
if (!recordType.getVersion().equals(originalMutableScopeRecordType.getVersion())) {
// If the next record version had the same record type version, copy the original value to that one
if (originalNextRecord != null && originalMutableScopeRecordType.getVersion()
.equals(originalNextRecord.getRecordTypeVersion(mutableScope))) {
put.add(RecordCf.DATA.bytes, RECORD_TYPE_ID_QUALIFIERS.get(mutableScope), version + 1,
Bytes.toBytes(originalMutableScopeRecordType.getVersion()));
}
put.add(RecordCf.DATA.bytes, RECORD_TYPE_VERSION_QUALIFIERS.get(mutableScope), version,
Bytes.toBytes(recordType.getVersion()));
}
}