// in an shared editing context
EOEditingContext ec = ERXEC.newEditingContext();
ec.lock();
try {
ec.setSharedEditingContext(null);
EOEnterpriseObject object = EOUtilities.localInstanceOfObject(ec, object());
ec.deleteObject(object);
ec.saveChanges();
} finally {
ec.unlock();
ec.dispose();
}
} else {
editingContext.deleteObject(object());
if (ERXEOControlUtilities.isNewObject(object())) {
// This is necessary to force state synching, e.g., for display groups, etc.
editingContext.processRecentChanges();
} else {
// Only save if the object is NOT new.
editingContext.saveChanges();
}
}
} catch (EOObjectNotAvailableException e) {
exception = ERXValidationFactory.defaultFactory().createCustomException(object(), "EOObjectNotAvailableException");
} catch (EOGeneralAdaptorException e) {
@SuppressWarnings("unchecked") NSDictionary userInfo = e.userInfo();
if(userInfo != null) {
EODatabaseOperation op = (EODatabaseOperation)userInfo.objectForKey(EODatabaseContext.FailedDatabaseOperationKey);
if(op.databaseOperator() == EODatabaseOperation.DatabaseDeleteOperator) {
exception = ERXValidationFactory.defaultFactory().createCustomException(object(), "EOObjectNotAvailableException");
}
}
if(exception == null) {
exception = ERXValidationFactory.defaultFactory().createCustomException(object(), "Database error: " + e.getMessage());
}
} catch (NSValidation.ValidationException e) {
exception = e;
}
if(exception != null) {
if (exception instanceof ERXValidationException) {
ERXValidationException ex = (ERXValidationException) exception;
D2WContext context = d2wContext();
Object o = ex.object();
if (o instanceof EOEnterpriseObject) {
EOEnterpriseObject eo = (EOEnterpriseObject) o;
context.takeValueForKey(eo.entityName(), "entityName");
context.takeValueForKey(ex.propertyKey(), "propertyKey");
}
((ERXValidationException) exception).setContext(context);
log.info("Validation Exception: " + exception + exception.getMessage());