// First index the current objects by their primary key.
for (int i=0; i < currentList.size(); i++) {
Object currentObject = currentList.get(i);
try {
CacheId primaryKey = (CacheId)getReferenceDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(currentObject, query.getSession());
primaryKey.add(i);
Object[] previousAndCurrent = new Object[]{null, currentObject};
previousAndCurrentByKey.put(primaryKey, previousAndCurrent);
} catch (NullPointerException e) {
// For CR#2646 quietly discard nulls added to a collection mapping.
// This try-catch is essentially a null check on currentObject, for
// ideally the customer should check for these themselves.
if (currentObject != null) {
throw e;
}
}
}
if (shouldRepairOrder) {
DeleteAllQuery deleteAllQuery = (DeleteAllQuery)this.deleteAllQuery;
if (this.isCascadeOnDeleteSetOnDatabase) {
deleteAllQuery = (DeleteAllQuery)deleteAllQuery.clone();
deleteAllQuery.setIsInMemoryOnly(false);
}
deleteAllQuery.executeDeleteAll(query.getSession().getSessionForClass(getReferenceClass()), query.getTranslationRow(), new Vector(previousList));
} else {
// Next index the previous objects (read from db or from backup in uow)
for(int i=0; i < previousList.size(); i++) {
Object previousObject = previousList.get(i);
CacheId primaryKey = (CacheId)getReferenceDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(previousObject, query.getSession());
primaryKey.add(i);
Object[] previousAndCurrent = previousAndCurrentByKey.get(primaryKey);
if (previousAndCurrent == null) {
// there's no current object - that means that previous object should be deleted
DatabaseRecord extraData = new DatabaseRecord(1);
extraData.put(this.listOrderField, i);