boolean validateAndCheckNoop() {
if (getChangesByObjectId().isEmpty()) {
return true;
}
ValidationResult result = new ValidationResult();
boolean noop = true;
// build a new collection for validation as validation methods may result in
// ObjectStore modifications
Collection objectsToValidate = null;
Iterator it = getChangesByObjectId().entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
if (!((ObjectDiff) entry.getValue()).isNoop()) {
if (noop) {
noop = false;
objectsToValidate = new ArrayList();
}
// accessing objectMap directly to avoid unneeded synchronization.
objectsToValidate.add(objectStore.getNodeNoSync(entry.getKey()));
}
}
if (objectsToValidate != null) {
Iterator validationIt = objectsToValidate.iterator();
while (validationIt.hasNext()) {
DataObject object = (DataObject) validationIt.next();
switch (object.getPersistenceState()) {
case PersistenceState.NEW:
object.validateForInsert(result);
break;
case PersistenceState.MODIFIED:
object.validateForUpdate(result);
break;
case PersistenceState.DELETED:
object.validateForDelete(result);
break;
}
}
if (result.hasFailures()) {
throw new ValidationException(result);
}
}
return noop;