use of org.jaffa.exceptions.DomainObjectChangedException in project jaffa-framework by jaffa-projects.
the class TransformerUtils method domainObjectChangedTest.
/**
* Performs the dirty-read check to ensure that the underlying record in the database hasn't
* been changed by another user, while the current user has been trying to modify it.
*/
private static void domainObjectChangedTest(String path, GraphDataObject source, GraphMapping mapping, IPersistent domainObject) throws InstantiationException, IllegalAccessException, InvocationTargetException, FrameworkException, ApplicationExceptions {
if (source.getPerformDirtyReadCheck() != null && source.getPerformDirtyReadCheck() && mapping.getDirtyReadDataFieldName() != null) {
if (log.isDebugEnabled())
log.debug("Performing dirty-read check for " + domainObject);
Object lastKnownValue = getProperty(mapping.getDataFieldDescriptor(mapping.getDirtyReadDataFieldName()), source);
Object currentValue = getProperty(mapping.getDomainFieldDescriptor(mapping.getDirtyReadDataFieldName()), domainObject);
if (lastKnownValue == null ? currentValue != null : !lastKnownValue.equals(currentValue)) {
if (log.isDebugEnabled())
log.debug("Dirty-read check failed: lastKnownValue='" + lastKnownValue + "', currentValue='" + currentValue + '\'');
if (!domainObject.isDatabaseOccurence()) {
if (log.isDebugEnabled())
log.debug("Dirty-read check failed: " + domainObject + " may have been removed.");
throw new ApplicationExceptions(new ApplicationExceptionWithContext(path, new ApplicationException(DomainObjectChangedException.OBJECT_REMOVED, null, null)));
} else {
String[] errorParamNames = mapping.getDirtyReadErrorParams();
Object[] errorParamValues = new Object[errorParamNames.length];
try {
for (int i = 0; i < errorParamNames.length; i++) errorParamValues[i] = BeanHelper.getField(domainObject, errorParamNames[i]);
} catch (Exception e) {
log.warn("Error in creation of the argument array to pass to the DomainObjectChangedException from the list: " + Arrays.toString(mapping.getDirtyReadErrorParams()), e);
}
throw new ApplicationExceptions(new ApplicationExceptionWithContext(path, new DomainObjectChangedException(mapping.getDirtyReadErrorLabelToken(), errorParamValues, null)));
}
} else {
if (log.isDebugEnabled())
log.debug("Dirty-read check succeeded. Both lastKnownValue and currentValue equal '" + currentValue + '\'');
}
}
}
Aggregations