Search in sources :

Example 6 with DomainObjectChangedException

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 + '\'');
        }
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) ApplicationExceptionWithContext(org.jaffa.exceptions.ApplicationExceptionWithContext) GraphDataObject(org.jaffa.soa.graph.GraphDataObject) DomainObjectChangedException(org.jaffa.exceptions.DomainObjectChangedException) DomainObjectChangedException(org.jaffa.exceptions.DomainObjectChangedException) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultipleDomainObjectsFoundException(org.jaffa.exceptions.MultipleDomainObjectsFoundException)

Aggregations

ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)6 DomainObjectChangedException (org.jaffa.exceptions.DomainObjectChangedException)6 IntrospectionException (java.beans.IntrospectionException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 ApplicationExceptionWithContext (org.jaffa.exceptions.ApplicationExceptionWithContext)1 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 MultipleDomainObjectsFoundException (org.jaffa.exceptions.MultipleDomainObjectsFoundException)1 GraphDataObject (org.jaffa.soa.graph.GraphDataObject)1