private static RecordMutation merge(RecordMutation recordMutation1, RecordMutation recordMutation2) throws BException {
RecordMutationType recordMutationType1 = recordMutation1.getRecordMutationType();
RecordMutationType recordMutationType2 = recordMutation2.getRecordMutationType();
if (!recordMutationType1.equals(recordMutationType2)) {
throw new BException(
"RecordMutation conflict, cannot perform 2 different operations on the same record in the same row in the same batch. [{0}] [{1}]",
recordMutation1, recordMutation2);
}
if (recordMutationType1.equals(RecordMutationType.DELETE_ENTIRE_RECORD)) {
// Since both are trying to delete the same record, just pick one and move
// on.
return recordMutation1;
} else if (recordMutationType1.equals(RecordMutationType.REPLACE_ENTIRE_RECORD)) {
throw new BException(
"RecordMutation conflict, cannot perform 2 different replace record operations on the same record in the same row in the same batch. [{0}] [{1}]",
recordMutation1, recordMutation2);
} else if (recordMutationType1.equals(RecordMutationType.REPLACE_COLUMNS)) {
throw new BException(
"RecordMutation conflict, cannot perform 2 different replace columns operations on the same record in the same row in the same batch. [{0}] [{1}]",
recordMutation1, recordMutation2);
} else {
Record record1 = recordMutation1.getRecord();
Record record2 = recordMutation2.getRecord();
String family1 = record1.getFamily();
String family2 = record2.getFamily();
if (isSameFamily(family1, family2)) {
record1.getColumns().addAll(record2.getColumns());
return recordMutation1;
} else {
throw new BException("RecordMutation conflict, cannot merge records with different family. [{0}] [{1}]",
recordMutation1, recordMutation2);
}
}
}